fix(ui): clip & left-align overflowing SegmentedControl labels

material::SegmentedControl drew each label centred with no clip, so long non-English labels (Russian/German, etc.) overflowed their cell and overlapped neighbours. Left-align on overflow and clip per cell (mirroring the chat modal's segmented helper); the fits-case is visually unchanged. Benefits every caller (contacts, receive, wallets, market).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-07-17 22:35:02 -05:00
parent 996e10ed02
commit 0fd3d214a4

View File

@@ -1347,10 +1347,17 @@ inline int SegmentedControl(ImDrawList* dl, ImVec2 origin, float totalW, float h
ImVec2(cMax.x - 2.0f * dp, cMax.y - 2.0f * dp), ImVec2(cMax.x - 2.0f * dp, cMax.y - 2.0f * dp),
WithAlpha(Primary(), 210), (height - 4.0f * dp) * 0.5f); WithAlpha(Primary(), 210), (height - 4.0f * dp) * 0.5f);
ImVec2 ts = font->CalcTextSizeA(font->LegacySize, FLT_MAX, 0, labels[i]); ImVec2 ts = font->CalcTextSizeA(font->LegacySize, FLT_MAX, 0, labels[i]);
// Center when the label fits; otherwise left-align with a small pad (so a long translation clips
// on the right, not on BOTH sides). Clip to the cell so no label can bleed into a neighbouring
// segment or past the rounded track — English fits, but de/es/fr/pt/ru labels can overrun.
const float lpad = 4.0f * dp;
const float tx = (ts.x <= cellW - 2.0f * lpad) ? (cellW - ts.x) * 0.5f : lpad;
dl->PushClipRect(cMin, cMax, true);
dl->AddText(font, font->LegacySize, dl->AddText(font, font->LegacySize,
ImVec2(cMin.x + (cellW - ts.x) * 0.5f, cMin.y + (height - ts.y) * 0.5f), ImVec2(cMin.x + tx, cMin.y + (height - ts.y) * 0.5f),
active ? IM_COL32(255, 255, 255, 255) : (hov ? OnSurface() : OnSurfaceMedium()), active ? IM_COL32(255, 255, 255, 255) : (hov ? OnSurface() : OnSurfaceMedium()),
labels[i]); labels[i]);
dl->PopClipRect();
ImGui::PushID(i); ImGui::PushID(i);
ImGui::SetCursorScreenPos(cMin); ImGui::SetCursorScreenPos(cMin);
if (ImGui::InvisibleButton(idBase, ImVec2(cellW, height))) clicked = i; if (ImGui::InvisibleButton(idBase, ImVec2(cellW, height))) clicked = i;