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

@@ -10,7 +10,9 @@
using namespace glass;
void glass::DisplayAccelerometerDevice(AccelerometerModel* model) {
if (!model->Exists()) return;
if (!model->Exists()) {
return;
}
if (BeginDevice("BuiltInAccel")) {
// Range
{

View File

@@ -13,7 +13,9 @@ using namespace glass;
void glass::DisplayAnalogInput(AnalogInputModel* model, int index) {
auto voltageData = model->GetVoltageData();
if (!voltageData) return;
if (!voltageData) {
return;
}
// build label
std::string* name = GetStorage().GetStringRef("name");
@@ -34,11 +36,15 @@ void glass::DisplayAnalogInput(AnalogInputModel* model, int index) {
ImGui::PopStyleColor();
} else {
float val = voltageData->GetValue();
if (voltageData->SliderFloat(label, &val, 0.0, 5.0)) model->SetVoltage(val);
if (voltageData->SliderFloat(label, &val, 0.0, 5.0)) {
model->SetVoltage(val);
}
}
// context menu to change name
if (PopupEditName("name", name)) voltageData->SetName(name->c_str());
if (PopupEditName("name", name)) {
voltageData->SetName(name->c_str());
}
}
void glass::DisplayAnalogInputs(AnalogInputsModel* model,
@@ -58,6 +64,7 @@ void glass::DisplayAnalogInputs(AnalogInputsModel* model,
PopID();
hasAny = true;
});
if (!hasAny && !noneMsg.empty())
if (!hasAny && !noneMsg.empty()) {
ImGui::TextUnformatted(noneMsg.begin(), noneMsg.end());
}
}

View File

@@ -13,12 +13,16 @@ using namespace glass;
void glass::DisplayAnalogOutputsDevice(AnalogOutputsModel* model) {
int count = 0;
model->ForEachAnalogOutput([&](auto&, int) { ++count; });
if (count == 0) return;
if (count == 0) {
return;
}
if (BeginDevice("Analog Outputs")) {
model->ForEachAnalogOutput([&](auto& analogOut, int i) {
auto analogOutData = analogOut.GetVoltageData();
if (!analogOutData) return;
if (!analogOutData) {
return;
}
PushID(i);
// build label
@@ -34,7 +38,9 @@ void glass::DisplayAnalogOutputsDevice(AnalogOutputsModel* model) {
DeviceDouble(label, true, &value, analogOutData);
if (PopupEditName("name", name)) {
if (analogOutData) analogOutData->SetName(name->c_str());
if (analogOutData) {
analogOutData->SetName(name->c_str());
}
}
PopID();
});

View File

@@ -59,11 +59,12 @@ void DisplayDIOImpl(DIOModel* model, int index, bool outputsEnabled) {
}
} else {
const char* name = model->GetName();
if (name[0] != '\0')
if (name[0] != '\0') {
info.GetLabel(label, sizeof(label), name);
else
} else {
info.GetLabel(label, sizeof(label), model->IsInput() ? " In" : "Out",
index);
}
if (auto simDevice = model->GetSimDevice()) {
LabelSimDevice(label, simDevice);
} else {
@@ -87,8 +88,12 @@ void DisplayDIOImpl(DIOModel* model, int index, bool outputsEnabled) {
}
}
if (info.PopupEditName(index)) {
if (dpwmData) dpwmData->SetName(info.GetName());
if (dutyCycleData) dutyCycleData->SetName(info.GetName());
if (dpwmData) {
dpwmData->SetName(info.GetName());
}
if (dutyCycleData) {
dutyCycleData->SetName(info.GetName());
}
}
}
@@ -110,6 +115,7 @@ void glass::DisplayDIOs(DIOsModel* model, bool outputsEnabled,
ImGui::PopID();
});
ImGui::PopItemWidth();
if (!hasAny && !noneMsg.empty())
if (!hasAny && !noneMsg.empty()) {
ImGui::TextUnformatted(noneMsg.begin(), noneMsg.end());
}
}

View File

@@ -82,7 +82,9 @@ void glass::DisplayEncoder(EncoderModel* model) {
model->SetName(name->c_str());
}
if (!open) return;
if (!open) {
return;
}
ImGui::PushItemWidth(ImGui::GetFontSize() * 8);
// distance per pulse
@@ -94,7 +96,9 @@ void glass::DisplayEncoder(EncoderModel* model) {
// count
if (auto countData = model->GetCountData()) {
int value = countData->GetValue();
if (ImGui::InputInt("##input", &value)) model->SetCount(value);
if (ImGui::InputInt("##input", &value)) {
model->SetCount(value);
}
ImGui::SameLine();
if (ImGui::Button("Reset")) {
model->SetCount(0);
@@ -157,6 +161,7 @@ void glass::DisplayEncoders(EncodersModel* model, wpi::StringRef noneMsg) {
DisplayEncoder(&encoder);
PopID();
});
if (!hasAny && !noneMsg.empty())
if (!hasAny && !noneMsg.empty()) {
ImGui::TextUnformatted(noneMsg.begin(), noneMsg.end());
}
}

View File

@@ -36,8 +36,9 @@ void glass::DisplayGyro(GyroModel* m) {
m->IsReadOnly() ? ImGuiInputTextFlags_ReadOnly : ImGuiInputTextFlags_None;
auto value = angle->GetValue();
ImGui::SetNextItemWidth(ImGui::GetFontSize() * 8);
if (ImGui::InputDouble("Gyro Angle (Deg)", &value, 0.0, 0.0, "%.4f", flags))
if (ImGui::InputDouble("Gyro Angle (Deg)", &value, 0.0, 0.0, "%.4f", flags)) {
m->SetAngle(value);
}
// Draw the gyro indicator.
ImDrawList* draw = ImGui::GetWindowDrawList();

View File

@@ -42,7 +42,9 @@ void glass::DisplayLEDDisplay(LEDDisplayModel* model, int index) {
ImGui::Combo("Start", start, options, 4);
}
ImGui::Checkbox("Serpentine", serpentine);
if (*numColumns < 1) *numColumns = 1;
if (*numColumns < 1) {
*numColumns = 1;
}
ImGui::PopItemWidth();
// show as LED indicators
@@ -51,13 +53,17 @@ void glass::DisplayLEDDisplay(LEDDisplayModel* model, int index) {
storage.SetData(std::make_shared<IndicatorData>());
iData = storage.GetData<IndicatorData>();
}
if (length > static_cast<int>(iData->values.size()))
if (length > static_cast<int>(iData->values.size())) {
iData->values.resize(length);
if (length > static_cast<int>(iData->colors.size()))
}
if (length > static_cast<int>(iData->colors.size())) {
iData->colors.resize(length);
}
if (!running) {
iData->colors[0] = IM_COL32(128, 128, 128, 255);
for (int j = 0; j < length; ++j) iData->values[j] = -1;
for (int j = 0; j < length; ++j) {
iData->values[j] = -1;
}
} else {
for (int j = 0; j < length; ++j) {
iData->values[j] = j + 1;
@@ -79,10 +85,14 @@ void glass::DisplayLEDDisplays(LEDDisplaysModel* model) {
model->ForEachLEDDisplay([&](LEDDisplayModel& display, int i) {
hasAny = true;
if (model->GetNumLEDDisplays() > 1) ImGui::Text("LEDs[%d]", i);
if (model->GetNumLEDDisplays() > 1) {
ImGui::Text("LEDs[%d]", i);
}
PushID(i);
DisplayLEDDisplay(&display, i);
PopID();
});
if (!hasAny) ImGui::Text("No addressable LEDs");
if (!hasAny) {
ImGui::Text("No addressable LEDs");
}
}

View File

@@ -23,16 +23,22 @@ bool glass::DisplayPCMSolenoids(PCMModel* model, int index,
wpi::SmallVector<int, 16> channels;
model->ForEachSolenoid([&](SolenoidModel& solenoid, int j) {
if (auto data = solenoid.GetOutputData()) {
if (j >= static_cast<int>(channels.size())) channels.resize(j + 1);
if (j >= static_cast<int>(channels.size())) {
channels.resize(j + 1);
}
channels[j] = (outputsEnabled && data->GetValue()) ? 1 : -1;
}
});
if (channels.empty()) return false;
if (channels.empty()) {
return false;
}
// show nonexistent channels as empty
for (auto&& ch : channels) {
if (ch == 0) ch = -2;
if (ch == 0) {
ch = -2;
}
}
// build header label
@@ -81,17 +87,22 @@ void glass::DisplayPCMsSolenoids(PCMsModel* model, bool outputsEnabled,
bool hasAny = false;
model->ForEachPCM([&](PCMModel& pcm, int i) {
PushID(i);
if (DisplayPCMSolenoids(&pcm, i, outputsEnabled)) hasAny = true;
if (DisplayPCMSolenoids(&pcm, i, outputsEnabled)) {
hasAny = true;
}
PopID();
});
if (!hasAny && !noneMsg.empty())
if (!hasAny && !noneMsg.empty()) {
ImGui::TextUnformatted(noneMsg.begin(), noneMsg.end());
}
}
void glass::DisplayCompressorDevice(PCMModel* model, int index,
bool outputsEnabled) {
auto compressor = model->GetCompressor();
if (!compressor || !compressor->Exists()) return;
if (!compressor || !compressor->Exists()) {
return;
}
DisplayCompressorDevice(compressor, index, outputsEnabled);
}

View File

@@ -24,8 +24,9 @@ static float DisplayChannel(PDPModel& pdp, int channel) {
leftInfo.GetLabel(name, sizeof(name), "", channel);
double val = currentData->GetValue();
ImGui::SetNextItemWidth(ImGui::GetFontSize() * 4);
if (currentData->InputDouble(name, &val, 0, 0, "%.3f"))
if (currentData->InputDouble(name, &val, 0, 0, "%.3f")) {
pdp.SetCurrent(channel, val);
}
width = ImGui::GetItemRectSize().x;
leftInfo.PopupEditName(channel);
ImGui::PopID();
@@ -69,7 +70,9 @@ void glass::DisplayPDP(PDPModel* model, int index) {
float width =
(std::max)(leftWidth, rightWidth) * 2 + ImGui::GetFontSize() * 4;
if (width > maxWidth) maxWidth = width;
if (width > maxWidth) {
maxWidth = width;
}
}
ImGui::Columns(1);
ImGui::Dummy(ImVec2(maxWidth, 0));
@@ -84,6 +87,7 @@ void glass::DisplayPDPs(PDPsModel* model, wpi::StringRef noneMsg) {
DisplayPDP(&pdp, i);
PopID();
});
if (!hasAny && !noneMsg.empty())
if (!hasAny && !noneMsg.empty()) {
ImGui::TextUnformatted(noneMsg.begin(), noneMsg.end());
}
}

View File

@@ -13,7 +13,9 @@ using namespace glass;
void glass::DisplayPWM(PWMModel* model, int index, bool outputsEnabled) {
auto data = model->GetSpeedData();
if (!data) return;
if (!data) {
return;
}
// build label
std::string* name = GetStorage().GetStringRef("name");
@@ -46,14 +48,16 @@ void glass::DisplayPWMs(PWMsModel* model, bool outputsEnabled,
hasAny = true;
PushID(i);
if (!first)
if (!first) {
ImGui::Separator();
else
} else {
first = false;
}
DisplayPWM(&pwm, i, outputsEnabled);
PopID();
});
if (!hasAny && !noneMsg.empty())
if (!hasAny && !noneMsg.empty()) {
ImGui::TextUnformatted(noneMsg.begin(), noneMsg.end());
}
}

View File

@@ -23,20 +23,29 @@ void glass::DisplayRelay(RelayModel* model, int index, bool outputsEnabled) {
bool forward = false;
bool reverse = false;
if (outputsEnabled) {
if (forwardData) forward = forwardData->GetValue();
if (reverseData) reverse = reverseData->GetValue();
if (forwardData) {
forward = forwardData->GetValue();
}
if (reverseData) {
reverse = reverseData->GetValue();
}
}
std::string* name = GetStorage().GetStringRef("name");
ImGui::PushID("name");
if (!name->empty())
if (!name->empty()) {
ImGui::Text("%s [%d]", name->c_str(), index);
else
} else {
ImGui::Text("Relay[%d]", index);
}
ImGui::PopID();
if (PopupEditName("name", name)) {
if (forwardData) forwardData->SetName(name->c_str());
if (reverseData) reverseData->SetName(name->c_str());
if (forwardData) {
forwardData->SetName(name->c_str());
}
if (reverseData) {
reverseData->SetName(name->c_str());
}
}
ImGui::SameLine();
@@ -57,15 +66,17 @@ void glass::DisplayRelays(RelaysModel* model, bool outputsEnabled,
model->ForEachRelay([&](RelayModel& relay, int i) {
hasAny = true;
if (!first)
if (!first) {
ImGui::Separator();
else
} else {
first = false;
}
PushID(i);
DisplayRelay(&relay, i, outputsEnabled);
PopID();
});
if (!hasAny && !noneMsg.empty())
if (!hasAny && !noneMsg.empty()) {
ImGui::TextUnformatted(noneMsg.begin(), noneMsg.end());
}
}

View File

@@ -23,11 +23,15 @@ void glass::DisplaySpeedController(SpeedControllerModel* m) {
}
// Add button to zero output.
if (ImGui::Button("Zero")) m->SetPercent(0.0);
if (ImGui::Button("Zero")) {
m->SetPercent(0.0);
}
ImGui::SameLine();
// Display a slider for the data.
float value = dc->GetValue();
ImGui::SetNextItemWidth(ImGui::GetFontSize() * 8);
if (dc->SliderFloat("% Output", &value, -1.0f, 1.0f)) m->SetPercent(value);
if (dc->SliderFloat("% Output", &value, -1.0f, 1.0f)) {
m->SetPercent(value);
}
}