fix text shifting in status bar from font scale changes

This commit is contained in:
dan_s
2026-03-05 01:29:03 -06:00
parent 68c2a59d09
commit c51d3dafff

View File

@@ -1223,8 +1223,6 @@ void App::renderStatusBar()
const float sbIconTextGap = S.drawElement("components.status-bar", "icon-text-gap").size;
const float sbSectionGap = S.drawElement("components.status-bar", "section-gap").size;
const float sbSeparatorGap = S.drawElement("components.status-bar", "separator-gap").size;
const float sbRightContentOff = S.label("components.status-bar", "right-content").position;
const float sbVersionRightOff = S.label("components.status-bar", "version-label").position;
ImGuiWindowFlags childFlags = ImGuiWindowFlags_NoScrollbar |
ImGuiWindowFlags_NoScrollWithMouse;
@@ -1364,19 +1362,36 @@ void App::renderStatusBar()
ImGui::TextColored(ImVec4(0.6f, 0.8f, 1.0f, 1.0f), "Importing keys%s", dotStr);
}
// Right side: connection status message (if any) + version always at far right
float rightStart = ImGui::GetWindowWidth() - sbRightContentOff;
if (!connection_status_.empty() && connection_status_ != "Connected") {
ImGui::SameLine(rightStart);
ImGui::TextDisabled("%s", connection_status_.c_str());
} else if (!daemon_status_.empty() && daemon_status_.find("Error") != std::string::npos) {
ImGui::SameLine(rightStart);
ImGui::TextColored(ImVec4(1.0f, 0.5f, 0.5f, 1.0f), "Daemon not found");
}
// Right side: version always at far right, connection status to its left.
// Compute positions dynamically from actual text widths so they
// never overlap and always stay within the window at any font scale.
{
char versionBuf[32];
snprintf(versionBuf, sizeof(versionBuf), "v%s", DRAGONX_VERSION);
float versionW = ImGui::CalcTextSize(versionBuf).x;
float rightPad = sbPadX; // match the left window padding
float versionX = ImGui::GetWindowWidth() - versionW - rightPad;
// Version always at far right
ImGui::SameLine(ImGui::GetWindowWidth() - sbVersionRightOff);
ImGui::Text("v%s", DRAGONX_VERSION);
// Connection / daemon status sits to the left of the version string
// with a small gap.
float gap = sbSectionGap;
if (!connection_status_.empty() && connection_status_ != "Connected") {
float statusW = ImGui::CalcTextSize(connection_status_.c_str()).x;
float statusX = versionX - statusW - gap;
ImGui::SameLine(statusX);
ImGui::TextDisabled("%s", connection_status_.c_str());
} else if (!daemon_status_.empty() && daemon_status_.find("Error") != std::string::npos) {
const char* errText = "Daemon not found";
float statusW = ImGui::CalcTextSize(errText).x;
float statusX = versionX - statusW - gap;
ImGui::SameLine(statusX);
ImGui::TextColored(ImVec4(1.0f, 0.5f, 0.5f, 1.0f), "%s", errText);
}
// Version always at far right
ImGui::SameLine(versionX);
ImGui::Text("%s", versionBuf);
}
ImGui::PopStyleColor(1); // Text opacity
ImGui::PopFont(); // status bar font