Quick Analysis: use a focus ring colour that meets 3:1 on the popup in both themes

The sheet's green focus colour is only 2.5:1 on the dark popup (1.9:1 on a hovered tile).
Tiles now ring with the theme accent (3.9:1 or more on the popup, hover and pressed fills in
light and dark); the launcher sits on the sheet and keeps the sheet's focus colour. The
contrast test covers the popup pairs.
This commit is contained in:
vangel76
2026-11-25 20:52:50 +01:00
parent 8bbc760f5d
commit 731c90dcc1
3 changed files with 18 additions and 8 deletions
+6 -5
View File
@@ -228,7 +228,8 @@ pub fn show(app: &mut SheetApp, ui: &mut Ui, geo: &Geo, sh: &Sheet) {
ui.painter().rect_filled(r, 4.0, fill);
ui.painter().rect_stroke(r, 4.0, Stroke::new(1.0, t.separator), StrokeKind::Inside);
icons::paint(ui.painter(), Rect::from_center_size(r.center(), vec2(16.0, 16.0)), Icon::QuickAnalysis, t.accent);
paint_focus_ring(ui, &t, r, &resp);
// The launcher sits on the sheet, so its ring is the sheet's focus colour
paint_focus_ring(ui, t.sheet_focus, r, &resp);
let name = lang.tr("Quick Analysis (Ctrl+Q)");
resp.widget_info(|| egui::WidgetInfo::selected(egui::Role::Button, true, open, name));
focused = resp.has_focus();
@@ -307,10 +308,10 @@ fn toggle_key_pressed(ctx: &egui::Context) -> bool {
})
}
/// A visible ring around a control that has the keyboard focus.
fn paint_focus_ring(ui: &Ui, t: &Tokens, rect: Rect, resp: &egui::Response) {
/// A visible ring in `color` around a control that has the keyboard focus.
fn paint_focus_ring(ui: &Ui, color: Color32, rect: Rect, resp: &egui::Response) {
if resp.has_focus() {
ui.painter().rect_stroke(rect.expand(1.0), 5.0, Stroke::new(2.0, t.sheet_focus), StrokeKind::Outside);
ui.painter().rect_stroke(rect.expand(1.0), 5.0, Stroke::new(2.0, color), StrokeKind::Outside);
}
}
@@ -332,7 +333,7 @@ fn paint_tile(ui: &mut Ui, t: &Tokens, item: &Tile, label: &str, take_focus: boo
let galley = ui.painter().layout(label.to_string(), theme::ui_font(11.0), t.text, TILE.x - 4.0);
let at = pos2(rect.center().x - galley.size().x / 2.0, rect.top() + 34.0);
ui.painter().with_clip_rect(rect.intersect(ui.clip_rect())).galley(at, galley, t.text);
paint_focus_ring(ui, t, rect, &resp);
paint_focus_ring(ui, t.popup_focus_ring(), rect, &resp);
*has_keyboard |= resp.has_focus();
resp.clicked()
}
+9
View File
@@ -300,6 +300,12 @@ impl Tokens {
if ctx.global_style().visuals.dark_mode { Tokens::dark() } else { Tokens::light() }
}
/// The ring around a focused control on a popup or menu surface. The sheet's own focus colour
/// is too dim on the dark popup (2.5:1), so this follows the theme's accent instead.
pub fn popup_focus_ring(&self) -> Color32 {
self.accent
}
/// One colour of the category palette.
pub fn cat(&self, c: Cat) -> Color32 {
self.cat.get(c as usize).copied().unwrap_or(self.text)
@@ -440,6 +446,9 @@ mod contrast_tests {
add("slider fill on sheet", t.sheet_fill, t.grid_bg, GLYPH);
add("slider fill on track", t.sheet_fill, t.sheet_track, GLYPH);
add("control focus ring on sheet", t.sheet_focus, t.grid_bg, GLYPH);
for (name, bg) in [("menu", t.menu_bg), ("hover", t.hover), ("pressed", t.pressed)] {
add(&format!("popup control focus ring on {name}"), t.popup_focus_ring(), bg, GLYPH);
}
add("recording dot on ribbon", t.recording, t.ribbon, GLYPH);
add("recording dot on status bar", t.recording, t.status_bar, GLYPH);
for (name, c) in [
@@ -162,18 +162,18 @@ fn launcher_and_tiles_are_named_buttons_that_work_by_keyboard() {
assert_eq!(sheet.cond_formats.len(), 1, "and its color scale is applied");
}
/// Whether a frame of the launcher and popup draws the focus ring colour as a stroke.
/// Whether a frame of the launcher and popup draws the popup focus ring (a 2 px stroke).
fn draws_focus_ring(app: &mut SheetApp, frames: usize) -> bool {
let sh = app.session.active().unwrap().wb.active().unwrap().clone();
let g = Geo::new(&sh, Rect::from_min_max(pos2(0.0, 0.0), pos2(1200.0, 800.0)), Vec2::ZERO);
let ctx = egui::Context::default();
// No fade-in, so the colours are the theme's own.
ctx.global_style_mut(|style| style.animation_time = 0.0);
let ring = gridcraft_ui_egui::theme::Tokens::get(&ctx).sheet_focus;
let ring = gridcraft_ui_egui::theme::Tokens::get(&ctx).popup_focus_ring();
let mut seen = false;
for _ in 0..frames {
let out = ctx.run_ui(egui::RawInput::default(), |ui| gridcraft_ui_egui::quick_analysis::show(app, ui, &g, &sh));
seen = out.shapes.iter().any(|s| matches!(&s.shape, egui::Shape::Rect(r) if r.stroke.color == ring));
seen = out.shapes.iter().any(|s| matches!(&s.shape, egui::Shape::Rect(r) if r.stroke.color == ring && r.stroke.width == 2.0));
out.drop_without_applying_deltas();
}
seen