mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-29 17:55:45 +01:00
Merge pull request #3484 from dotCooCoo/fix/menu-bar-title-focus-ring
ui-widgets: a focused menu bar title shows the focus ring
This commit is contained in:
2 files changed
+40
-3
No files matched your search
@@ -191,12 +191,15 @@ impl Component for TitleFace {
|
||||
}
|
||||
}
|
||||
|
||||
/// The style of a menu bar: the titles wear row faces, which underline their mnemonics.
|
||||
/// The style of a menu bar: the titles wear row faces, which underline their mnemonics, and the title the keyboard is
|
||||
/// on is ringed with the focus look.
|
||||
#[derive(Clone, Debug, PartialEq, ComponentStyle)]
|
||||
#[non_exhaustive]
|
||||
pub struct MenuBarStyle {
|
||||
#[style(metrics)]
|
||||
metrics: Metrics,
|
||||
#[style(focus)]
|
||||
focus: FocusLook,
|
||||
}
|
||||
|
||||
/// A title's text without its marker, and its mnemonic: the letter and its character index in the text, none for a
|
||||
@@ -503,8 +506,8 @@ impl Component for MenuBar<'_> {
|
||||
type Style = MenuBarStyle;
|
||||
type Output = MenuBarOutput;
|
||||
|
||||
fn style(_: &StyleCx<'_>, _: MenuBarStyleKey) -> MenuBarStyle {
|
||||
MenuBarStyle { metrics: Metrics::new() }
|
||||
fn style(cx: &StyleCx<'_>, _: MenuBarStyleKey) -> MenuBarStyle {
|
||||
MenuBarStyle { metrics: Metrics::new(), focus: cx.focus_look() }
|
||||
}
|
||||
|
||||
/// Every title's width; at its least (`Proposal::Min`) the width of the "…" title alone. A row that has less room
|
||||
|
||||
@@ -635,3 +635,37 @@ fn a_fields_selection_holds_while_the_menu_bar_has_the_keyboard() {
|
||||
let copy = fixture.by_label("Copy").expect("the Edit menu is open");
|
||||
assert!(!fixture.tree().is_disabled_key(copy.node), "Copy applies to the field's selection");
|
||||
}
|
||||
|
||||
/// Whether the latest frame paints a focus ring (a stroke at least two points wide) close around `target`, not around
|
||||
/// the whole bar.
|
||||
fn ringed(fixture: &mut Fixture, target: egui::Rect) -> bool {
|
||||
let around = |ring: egui::Rect| ring.expand(1.0).contains_rect(target) && target.expand(4.0).contains_rect(ring);
|
||||
fixture.frame_shapes().iter().any(|shape| match shape {
|
||||
egui::Shape::Rect(rect) if rect.stroke.width >= 2.0 => around(rect.rect),
|
||||
egui::Shape::Path(path) if path.stroke.width >= 2.0 => around(egui::Rect::from_points(&path.points)),
|
||||
_ => false,
|
||||
})
|
||||
}
|
||||
|
||||
/// The title that Tab, F10 or an arrow key moves the keyboard to is ringed, as a focused button is, and the title the
|
||||
/// keyboard left is not.
|
||||
#[trial]
|
||||
fn the_focused_title_shows_the_focus_ring() {
|
||||
let mut rig = rig(Direction::Ltr);
|
||||
let fixture = &mut rig.fixture;
|
||||
fixture.key(Key::Tab, Modifiers::NONE).settle();
|
||||
let (bar, file) = fixture.focused_stop().and_then(|(bar, part)| Some((bar, part?))).expect("Tab focuses a title");
|
||||
let file_rect = fixture.part_rect(bar, file).expect("the focused title's rect");
|
||||
assert!(ringed(fixture, file_rect), "Tab rings the title it focuses");
|
||||
fixture.key(Key::ArrowRight, Modifiers::NONE).settle();
|
||||
let edit = fixture.focused_stop().and_then(|(_, part)| part).expect("Right focuses the next title");
|
||||
assert_ne!(edit, file, "Right moves to another title");
|
||||
let edit_rect = fixture.part_rect(bar, edit).expect("the next title's rect");
|
||||
assert!(ringed(fixture, edit_rect), "Right rings the title it moves to");
|
||||
assert!(!ringed(fixture, file_rect), "the title the keyboard left loses its ring");
|
||||
fixture.key(Key::Escape, Modifiers::NONE).settle();
|
||||
fixture.key(Key::F10, Modifiers::NONE).settle();
|
||||
let first = fixture.focused_stop().and_then(|(_, part)| part).expect("F10 focuses the first title");
|
||||
let first_rect = fixture.part_rect(bar, first).expect("the first title's rect");
|
||||
assert!(ringed(fixture, first_rect), "F10 rings the title it focuses");
|
||||
}
|
||||
Reference in new issue
Block a user