UX improvements

This commit is contained in:
2026-02-28 00:57:11 -06:00
parent 6607bae2b5
commit f5378a55ed
6 changed files with 132 additions and 97 deletions

View File

@@ -70,14 +70,23 @@ inline const char* GetNavIconMD(NavPage page)
}
}
// Compute the effective draw-list font size for a given font.
// During smooth font-scale drag, FontScaleMain compensates for the atlas
// not yet being rebuilt. drawList->AddText bypasses that, so we apply
// the factor manually to keep sidebar text in sync with the rest of the UI.
inline float ScaledFontSize(ImFont* f) {
return f->LegacySize * ImGui::GetStyle().FontScaleMain;
}
// Draw a Material Design icon centered at (cx, cy) with the given color.
// Uses the medium (18px) icon font from Typography.
inline void DrawNavIcon(ImDrawList* dl, NavPage page, float cx, float cy, float /*s*/, ImU32 col)
{
ImFont* iconFont = material::Type().iconMed();
const char* icon = GetNavIconMD(page);
ImVec2 sz = iconFont->CalcTextSizeA(iconFont->LegacySize, 1000.0f, 0.0f, icon);
dl->AddText(iconFont, iconFont->LegacySize,
float fsz = ScaledFontSize(iconFont);
ImVec2 sz = iconFont->CalcTextSizeA(fsz, 1000.0f, 0.0f, icon);
dl->AddText(iconFont, fsz,
ImVec2(cx - sz.x * 0.5f, cy - sz.y * 0.5f), col, icon);
}
@@ -506,8 +515,9 @@ inline bool RenderSidebar(NavPage& current, float sidebarWidth, float contentHei
{
ImFont* iconFont = Type().iconSmall();
const char* chevIcon = collapsed ? ICON_MD_CHEVRON_RIGHT : ICON_MD_CHEVRON_LEFT;
ImVec2 chevSz = iconFont->CalcTextSizeA(iconFont->LegacySize, 1000.0f, 0.0f, chevIcon);
dl->AddText(iconFont, iconFont->LegacySize,
float chevFsz = ScaledFontSize(iconFont);
ImVec2 chevSz = iconFont->CalcTextSizeA(chevFsz, 1000.0f, 0.0f, chevIcon);
dl->AddText(iconFont, chevFsz,
ImVec2(cx - chevSz.x * 0.5f, cy - chevSz.y * 0.5f), iconCol, chevIcon);
}
@@ -528,10 +538,11 @@ inline bool RenderSidebar(NavPage& current, float sidebarWidth, float contentHei
float labelY = ImGui::GetCursorScreenPos().y;
ImVec4 olCol = ImGui::ColorConvertU32ToFloat4(OnSurfaceMedium());
olCol.w *= expandFrac;
dl->AddText(olFont, olFont->LegacySize,
float olFsz = ScaledFontSize(olFont);
dl->AddText(olFont, olFsz,
ImVec2(wp.x + sbSectionLabelPadLeft, labelY),
ImGui::ColorConvertFloat4ToU32(olCol), item.section_label);
ImGui::Dummy(ImVec2(0, olFont->LegacySize + 2.0f));
ImGui::Dummy(ImVec2(0, olFsz + 2.0f));
} else if (item.section_label && !showLabels) {
// Collapsed: thin separator instead of label
ImGui::Dummy(ImVec2(0, sbSectionGap * 0.4f));
@@ -601,7 +612,8 @@ inline bool RenderSidebar(NavPage& current, float sidebarWidth, float contentHei
// Measure total width of icon + gap + label, then center
ImFont* font = selected ? Type().subtitle2() : Type().body2();
float gap = iconLabelGap;
ImVec2 labelSz = font->CalcTextSizeA(font->LegacySize, 1000.0f, 0.0f, item.label);
float lblFsz = ScaledFontSize(font);
ImVec2 labelSz = font->CalcTextSizeA(lblFsz, 1000.0f, 0.0f, item.label);
float totalW = iconS * 2.0f + gap + labelSz.x;
float btnCX = (indMin.x + indMax.x) * 0.5f;
float startX = btnCX - totalW * 0.5f;
@@ -612,7 +624,7 @@ inline bool RenderSidebar(NavPage& current, float sidebarWidth, float contentHei
float labelX = startX + iconS * 2.0f + gap;
ImVec4 lc = ImGui::ColorConvertU32ToFloat4(textCol);
lc.w *= expandFrac;
dl->AddText(font, font->LegacySize, ImVec2(labelX, textY),
dl->AddText(font, lblFsz, ImVec2(labelX, textY),
ImGui::ColorConvertFloat4ToU32(lc), item.label);
} else {
float iconCX = (indMin.x + indMax.x) * 0.5f;
@@ -656,8 +668,9 @@ inline bool RenderSidebar(NavPage& current, float sidebarWidth, float contentHei
char buf[16];
snprintf(buf, sizeof(buf), "%d", badgeCount > 99 ? 99 : badgeCount);
ImFont* capFont = Type().caption();
ImVec2 ts = capFont->CalcTextSizeA(capFont->LegacySize, 1000.0f, 0.0f, buf);
dl->AddText(capFont, capFont->LegacySize,
float capFsz = ScaledFontSize(capFont);
ImVec2 ts = capFont->CalcTextSizeA(capFsz, 1000.0f, 0.0f, buf);
dl->AddText(capFont, capFsz,
ImVec2(badgeX - ts.x * 0.5f, badgeY - ts.y * 0.5f),
badgeTextCol, buf);
}
@@ -777,25 +790,28 @@ inline bool RenderSidebar(NavPage& current, float sidebarWidth, float contentHei
ImFont* iconFont = Type().iconSmall();
ImFont* font = Type().caption();
const char* exitIcon = ICON_MD_EXIT_TO_APP;
ImVec2 iconSz = iconFont->CalcTextSizeA(iconFont->LegacySize, 1000.0f, 0.0f, exitIcon);
ImVec2 labelSz = font->CalcTextSizeA(font->LegacySize, 1000.0f, 0.0f, "Exit");
float eIconFsz = ScaledFontSize(iconFont);
float eLblFsz = ScaledFontSize(font);
ImVec2 iconSz = iconFont->CalcTextSizeA(eIconFsz, 1000.0f, 0.0f, exitIcon);
ImVec2 labelSz = font->CalcTextSizeA(eLblFsz, 1000.0f, 0.0f, "Exit");
float gap = exitIconGap;
float totalW = iconSz.x + gap + labelSz.x;
float startX = cx - totalW * 0.5f;
dl->AddText(iconFont, iconFont->LegacySize,
dl->AddText(iconFont, eIconFsz,
ImVec2(startX, cy - iconSz.y * 0.5f), exitCol, exitIcon);
ImVec4 lc = ImGui::ColorConvertU32ToFloat4(exitCol);
lc.w *= expandFrac;
dl->AddText(font, font->LegacySize,
dl->AddText(font, eLblFsz,
ImVec2(startX + iconSz.x + gap, cy - labelSz.y * 0.5f),
ImGui::ColorConvertFloat4ToU32(lc), "Exit");
} else {
ImFont* iconFont = Type().iconSmall();
const char* exitIcon = ICON_MD_EXIT_TO_APP;
ImVec2 iconSz = iconFont->CalcTextSizeA(iconFont->LegacySize, 1000.0f, 0.0f, exitIcon);
dl->AddText(iconFont, iconFont->LegacySize,
float eIconFsz = ScaledFontSize(iconFont);
ImVec2 iconSz = iconFont->CalcTextSizeA(eIconFsz, 1000.0f, 0.0f, exitIcon);
dl->AddText(iconFont, eIconFsz,
ImVec2(cx - iconSz.x * 0.5f, cy - iconSz.y * 0.5f),
exitCol, exitIcon);
}