Skip to content

Commit

Permalink
[glass, simgui] Fix minimum widths of windows (wpilibsuite#7604)
Browse files Browse the repository at this point in the history
  • Loading branch information
WispySparks authored Jan 1, 2025
1 parent 9ebc4b3 commit 17a0351
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
18 changes: 14 additions & 4 deletions glass/src/lib/native/cpp/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
2 changes: 1 addition & 1 deletion glass/src/lib/native/cpp/hardware/LEDDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 9 additions & 1 deletion simulation/halsim_gui/src/main/native/cpp/DriverStationGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 17a0351

Please sign in to comment.