Skip to content

Commit 17a0351

Browse files
authored
[glass, simgui] Fix minimum widths of windows (#7604)
1 parent 9ebc4b3 commit 17a0351

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

glass/src/lib/native/cpp/Window.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,22 @@ void Window::Display() {
5757
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, m_padding);
5858
}
5959

60-
std::string label;
60+
std::string* name = &m_name;
6161
if (m_name.empty()) {
62-
label = fmt::format("{}###{}", m_defaultName, m_id);
63-
} else {
64-
label = fmt::format("{}###{}", m_name, m_id);
62+
name = &m_defaultName;
63+
}
64+
std::string label = fmt::format("{}###{}", *name, m_id);
65+
66+
// Accounts for size of title, collapse button, and close button
67+
float minWidth =
68+
ImGui::CalcTextSize(name->c_str()).x + ImGui::GetFontSize() * 2 +
69+
ImGui::GetStyle().ItemInnerSpacing.x * 3 +
70+
ImGui::GetStyle().FramePadding.x * 2 + ImGui::GetStyle().WindowBorderSize;
71+
// Accounts for size of hamburger button
72+
if (m_renamePopupEnabled || m_view->HasSettings()) {
73+
minWidth += ImGui::GetFontSize() + ImGui::GetStyle().FramePadding.x;
6574
}
75+
ImGui::SetNextWindowSizeConstraints({minWidth, 0}, ImVec2{FLT_MAX, FLT_MAX});
6676

6777
if (Begin(label.c_str(), &m_visible, m_flags)) {
6878
if (m_renamePopupEnabled || m_view->HasSettings()) {

glass/src/lib/native/cpp/hardware/LEDDisplay.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ void glass::DisplayLEDDisplay(LEDDisplayModel* model, int index) {
3333
int& order = storage.GetInt("order", LEDConfig::RowMajor);
3434
int& start = storage.GetInt("start", LEDConfig::UpperLeft);
3535

36-
ImGui::PushItemWidth(ImGui::GetFontSize() * 6);
36+
ImGui::PushItemWidth(ImGui::GetFontSize() * 7);
3737
ImGui::LabelText("Length", "%d", length);
3838
ImGui::LabelText("Running", "%s", running ? "Yes" : "No");
3939
ImGui::InputInt("Columns", &numColumns);

simulation/halsim_gui/src/main/native/cpp/DriverStationGui.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1104,7 +1104,15 @@ static void DriverStationExecute() {
11041104
}
11051105

11061106
ImGui::SetNextWindowPos(ImVec2{5, 20}, ImGuiCond_FirstUseEver);
1107-
ImGui::Begin("Robot State", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
1107+
const char* title = "Robot State";
1108+
// Accounts for size of title and collapse button
1109+
float minWidth = ImGui::CalcTextSize(title).x + ImGui::GetFontSize() +
1110+
ImGui::GetStyle().ItemInnerSpacing.x * 2 +
1111+
ImGui::GetStyle().FramePadding.x * 2 +
1112+
ImGui::GetStyle().WindowBorderSize;
1113+
ImGui::SetNextWindowSizeConstraints(ImVec2{minWidth, 0},
1114+
ImVec2{FLT_MAX, FLT_MAX});
1115+
ImGui::Begin(title, nullptr, ImGuiWindowFlags_AlwaysAutoResize);
11081116
if (ImGui::Selectable("Disconnected", !isAttached)) {
11091117
HALSIM_SetDriverStationEnabled(false);
11101118
HALSIM_SetDriverStationDsAttached(false);

0 commit comments

Comments
 (0)