Add braces to C++ single-line loops and conditionals (NFC) (#2973)

This makes code easier to read and more consistent between C++ and Java.
Also update clang-format settings to always add a line break (even if no braces are used).
This commit is contained in:
Peter Johnson
2020-12-28 12:58:06 -08:00
committed by GitHub
parent 0291a3ff56
commit 2aed432b4b
634 changed files with 10716 additions and 3938 deletions

View File

@@ -182,7 +182,9 @@ void FieldInfo::LoadImage() {
m_fileOpener.reset();
}
if (!m_texture && !m_pFilename->empty()) {
if (!LoadImageImpl(m_pFilename->c_str())) m_pFilename->clear();
if (!LoadImageImpl(m_pFilename->c_str())) {
m_pFilename->clear();
}
}
}
@@ -264,7 +266,9 @@ void FieldInfo::LoadJson(const wpi::Twine& jsonfile) {
wpi::sys::path::append(pathname, image);
// load field image
if (!LoadImageImpl(pathname.c_str())) return;
if (!LoadImageImpl(pathname.c_str())) {
return;
}
// save to field info
*m_pFilename = pathname.str();
@@ -292,8 +296,9 @@ bool FieldInfo::LoadImageImpl(const char* fn) {
FieldFrameData FieldInfo::GetFrameData(ImVec2 min, ImVec2 max) const {
// fit the image into the window
if (m_texture && m_imageHeight != 0 && m_imageWidth != 0)
if (m_texture && m_imageHeight != 0 && m_imageWidth != 0) {
gui::MaxFit(&min, &max, m_imageWidth, m_imageHeight);
}
FieldFrameData ffd;
ffd.imageMin = min;
@@ -340,11 +345,15 @@ void ObjectGroupInfo::Reset() {
void ObjectGroupInfo::LoadImage() {
if (m_fileOpener && m_fileOpener->ready(0)) {
auto result = m_fileOpener->result();
if (!result.empty()) LoadImageImpl(result[0].c_str());
if (!result.empty()) {
LoadImageImpl(result[0].c_str());
}
m_fileOpener.reset();
}
if (!m_texture && !m_pFilename->empty()) {
if (!LoadImageImpl(m_pFilename->c_str())) m_pFilename->clear();
if (!LoadImageImpl(m_pFilename->c_str())) {
m_pFilename->clear();
}
}
}
@@ -368,10 +377,15 @@ ObjectFrameData::ObjectFrameData(FieldObjectModel& model,
m_width2(ffd.scale * width / 2),
m_length2(ffd.scale * length / 2),
m_hitRadius((std::min)(m_width2, m_length2) / 2) {
if (auto xData = model.GetXData()) m_x = xData->GetValue();
if (auto yData = model.GetYData()) m_y = yData->GetValue();
if (auto rotationData = model.GetRotationData())
if (auto xData = model.GetXData()) {
m_x = xData->GetValue();
}
if (auto yData = model.GetYData()) {
m_y = yData->GetValue();
}
if (auto rotationData = model.GetRotationData()) {
m_rot = rotationData->GetValue();
}
UpdateFrameData();
}
@@ -418,22 +432,25 @@ int ObjectFrameData::IsHovered(const ImVec2& cursor) const {
// only allow initiation of dragging when invisible button is hovered;
// this prevents the window resize handles from simultaneously activating
// the drag functionality
if (!ImGui::IsItemHovered()) return 0;
if (!ImGui::IsItemHovered()) {
return 0;
}
float hitRadiusSquared = m_hitRadius * m_hitRadius;
// it's within the hit radius of the center?
if (gui::GetDistSquared(cursor, m_center) < hitRadiusSquared)
if (gui::GetDistSquared(cursor, m_center) < hitRadiusSquared) {
return 1;
else if (gui::GetDistSquared(cursor, m_corners[0]) < hitRadiusSquared)
} else if (gui::GetDistSquared(cursor, m_corners[0]) < hitRadiusSquared) {
return 2;
else if (gui::GetDistSquared(cursor, m_corners[1]) < hitRadiusSquared)
} else if (gui::GetDistSquared(cursor, m_corners[1]) < hitRadiusSquared) {
return 3;
else if (gui::GetDistSquared(cursor, m_corners[2]) < hitRadiusSquared)
} else if (gui::GetDistSquared(cursor, m_corners[2]) < hitRadiusSquared) {
return 4;
else if (gui::GetDistSquared(cursor, m_corners[3]) < hitRadiusSquared)
} else if (gui::GetDistSquared(cursor, m_corners[3]) < hitRadiusSquared) {
return 5;
else
} else {
return 0;
}
}
bool ObjectFrameData::HandleDrag(const ImVec2& cursor, int hitCorner,
@@ -525,10 +542,14 @@ void glass::DisplayField2DSettings(Field2DModel* model) {
}
model->ForEachFieldObjectGroup([&](auto& groupModel, auto name) {
if (!groupModel.Exists()) return;
if (!groupModel.Exists()) {
return;
}
PushID(name);
auto& objGroupRef = field->m_objectGroups[name];
if (!objGroupRef) objGroupRef = std::make_unique<ObjectGroupInfo>();
if (!objGroupRef) {
objGroupRef = std::make_unique<ObjectGroupInfo>();
}
auto objGroup = objGroupRef.get();
wpi::SmallString<64> nameBuf = name;
@@ -565,7 +586,9 @@ void glass::DisplayField2D(Field2DModel* model, const ImVec2& contentSize) {
// for dragging to work, there needs to be a button (otherwise the window is
// dragged)
if (contentSize.x <= 0 || contentSize.y <= 0) return;
if (contentSize.x <= 0 || contentSize.y <= 0) {
return;
}
ImVec2 cursorPos = windowPos + ImGui::GetCursorPos(); // screen coords
ImGui::InvisibleButton("field", contentSize);
@@ -576,10 +599,14 @@ void glass::DisplayField2D(Field2DModel* model, const ImVec2& contentSize) {
field->Draw(drawList, ffd);
model->ForEachFieldObjectGroup([&](auto& groupModel, auto name) {
if (!groupModel.Exists()) return;
if (!groupModel.Exists()) {
return;
}
PushID(name);
auto& objGroupRef = field->m_objectGroups[name];
if (!objGroupRef) objGroupRef = std::make_unique<ObjectGroupInfo>();
if (!objGroupRef) {
objGroupRef = std::make_unique<ObjectGroupInfo>();
}
auto objGroup = objGroupRef.get();
objGroup->LoadImage();
@@ -593,8 +620,9 @@ void glass::DisplayField2D(Field2DModel* model, const ImVec2& contentSize) {
if (objGroup->m_dragState.object == 0 ||
objGroup->m_dragState.object == i) {
hitCorner = ofd.IsHovered(mousePos);
if (ofd.HandleDrag(mousePos, hitCorner, &objGroup->m_dragState))
if (ofd.HandleDrag(mousePos, hitCorner, &objGroup->m_dragState)) {
objGroup->m_dragState.object = i;
}
}
// draw