mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-27 02:01:42 +00:00
[glass] Use .controllable to set widgets' read-only state (#3035)
This modifies the mecanum drive, differential drive, speed controller, and PID controller widgets to only be writeable when .controllable is set to true.
This commit is contained in:
committed by
GitHub
parent
d8652cfd4f
commit
278e0f126e
@@ -5,6 +5,7 @@
|
||||
#include "glass/hardware/SpeedController.h"
|
||||
|
||||
#include <imgui.h>
|
||||
#include <imgui_internal.h>
|
||||
|
||||
#include "glass/Context.h"
|
||||
#include "glass/DataSource.h"
|
||||
@@ -22,6 +23,12 @@ void glass::DisplaySpeedController(SpeedControllerModel* m) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Set the buttons and sliders to read-only if the model is read-only.
|
||||
if (m->IsReadOnly()) {
|
||||
ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true);
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, IM_COL32(210, 210, 210, 255));
|
||||
}
|
||||
|
||||
// Add button to zero output.
|
||||
if (ImGui::Button("Zero")) {
|
||||
m->SetPercent(0.0);
|
||||
@@ -31,7 +38,13 @@ void glass::DisplaySpeedController(SpeedControllerModel* m) {
|
||||
// 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 (m->IsReadOnly()) {
|
||||
ImGui::PopStyleColor();
|
||||
ImGui::PopItemFlag();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,6 +106,12 @@ void glass::DisplayDrive(DriveModel* m) {
|
||||
drawArrow(arrowPos, a2 + adder);
|
||||
}
|
||||
|
||||
// Set the buttons and sliders to read-only if the model is read-only.
|
||||
if (m->IsReadOnly()) {
|
||||
ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true);
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, IM_COL32(210, 210, 210, 255));
|
||||
}
|
||||
|
||||
// Add sliders for the wheel percentages.
|
||||
ImGui::SetCursorPosY(y2 - pos.y + ImGui::GetFontSize() * 0.5);
|
||||
for (auto&& wheel : wheels) {
|
||||
@@ -124,4 +130,9 @@ void glass::DisplayDrive(DriveModel* m) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (m->IsReadOnly()) {
|
||||
ImGui::PopStyleColor();
|
||||
ImGui::PopItemFlag();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,10 +20,12 @@ void glass::DisplayPIDController(PIDControllerModel* m) {
|
||||
}
|
||||
|
||||
if (m->Exists()) {
|
||||
auto createTuningParameter = [](const char* name, double* v,
|
||||
std::function<void(double)> callback) {
|
||||
auto flag = m->IsReadOnly() ? ImGuiInputTextFlags_ReadOnly
|
||||
: ImGuiInputTextFlags_None;
|
||||
auto createTuningParameter = [flag](const char* name, double* v,
|
||||
std::function<void(double)> callback) {
|
||||
ImGui::SetNextItemWidth(ImGui::GetFontSize() * 4);
|
||||
if (ImGui::InputDouble(name, v, 0.0, 0.0, "%.3f")) {
|
||||
if (ImGui::InputDouble(name, v, 0.0, 0.0, "%.3f", flag)) {
|
||||
callback(*v);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user