From 17a03514bad6de195639634b3d57d5ac411d601e Mon Sep 17 00:00:00 2001 From: Wispy <101812473+WispySparks@users.noreply.github.com> Date: Wed, 1 Jan 2025 17:20:35 -0600 Subject: [PATCH] [glass, simgui] Fix minimum widths of windows (#7604) --- glass/src/lib/native/cpp/Window.cpp | 18 ++++++++++++++---- .../src/lib/native/cpp/hardware/LEDDisplay.cpp | 2 +- .../src/main/native/cpp/DriverStationGui.cpp | 10 +++++++++- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/glass/src/lib/native/cpp/Window.cpp b/glass/src/lib/native/cpp/Window.cpp index 64b043ffb1e..8a69ed8b6ed 100644 --- a/glass/src/lib/native/cpp/Window.cpp +++ b/glass/src/lib/native/cpp/Window.cpp @@ -57,12 +57,22 @@ void Window::Display() { ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, m_padding); } - std::string label; + std::string* name = &m_name; if (m_name.empty()) { - label = fmt::format("{}###{}", m_defaultName, m_id); - } else { - label = fmt::format("{}###{}", m_name, m_id); + name = &m_defaultName; + } + std::string label = fmt::format("{}###{}", *name, m_id); + + // Accounts for size of title, collapse button, and close button + float minWidth = + ImGui::CalcTextSize(name->c_str()).x + ImGui::GetFontSize() * 2 + + ImGui::GetStyle().ItemInnerSpacing.x * 3 + + ImGui::GetStyle().FramePadding.x * 2 + ImGui::GetStyle().WindowBorderSize; + // Accounts for size of hamburger button + if (m_renamePopupEnabled || m_view->HasSettings()) { + minWidth += ImGui::GetFontSize() + ImGui::GetStyle().FramePadding.x; } + ImGui::SetNextWindowSizeConstraints({minWidth, 0}, ImVec2{FLT_MAX, FLT_MAX}); if (Begin(label.c_str(), &m_visible, m_flags)) { if (m_renamePopupEnabled || m_view->HasSettings()) { diff --git a/glass/src/lib/native/cpp/hardware/LEDDisplay.cpp b/glass/src/lib/native/cpp/hardware/LEDDisplay.cpp index 6ad7fc54a74..8e02be30a4c 100644 --- a/glass/src/lib/native/cpp/hardware/LEDDisplay.cpp +++ b/glass/src/lib/native/cpp/hardware/LEDDisplay.cpp @@ -33,7 +33,7 @@ void glass::DisplayLEDDisplay(LEDDisplayModel* model, int index) { int& order = storage.GetInt("order", LEDConfig::RowMajor); int& start = storage.GetInt("start", LEDConfig::UpperLeft); - ImGui::PushItemWidth(ImGui::GetFontSize() * 6); + ImGui::PushItemWidth(ImGui::GetFontSize() * 7); ImGui::LabelText("Length", "%d", length); ImGui::LabelText("Running", "%s", running ? "Yes" : "No"); ImGui::InputInt("Columns", &numColumns); diff --git a/simulation/halsim_gui/src/main/native/cpp/DriverStationGui.cpp b/simulation/halsim_gui/src/main/native/cpp/DriverStationGui.cpp index 3ed8fa71127..541437a95d3 100644 --- a/simulation/halsim_gui/src/main/native/cpp/DriverStationGui.cpp +++ b/simulation/halsim_gui/src/main/native/cpp/DriverStationGui.cpp @@ -1104,7 +1104,15 @@ static void DriverStationExecute() { } ImGui::SetNextWindowPos(ImVec2{5, 20}, ImGuiCond_FirstUseEver); - ImGui::Begin("Robot State", nullptr, ImGuiWindowFlags_AlwaysAutoResize); + const char* title = "Robot State"; + // Accounts for size of title and collapse button + float minWidth = ImGui::CalcTextSize(title).x + ImGui::GetFontSize() + + ImGui::GetStyle().ItemInnerSpacing.x * 2 + + ImGui::GetStyle().FramePadding.x * 2 + + ImGui::GetStyle().WindowBorderSize; + ImGui::SetNextWindowSizeConstraints(ImVec2{minWidth, 0}, + ImVec2{FLT_MAX, FLT_MAX}); + ImGui::Begin(title, nullptr, ImGuiWindowFlags_AlwaysAutoResize); if (ImGui::Selectable("Disconnected", !isAttached)) { HALSIM_SetDriverStationEnabled(false); HALSIM_SetDriverStationDsAttached(false);