mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-28 17:30:12 +01:00
Merge pull request #3746 from davidmann4/fix/17102-flyout-no-empty-ring
Tool flyouts mark only the shown tool (photocraft#17102)
This commit is contained in:
2 files changed
+36
-7
No files matched your search
@@ -111,9 +111,9 @@ struct Laid {
|
||||
/// One rail button that may stand for a group of tools. The face shows the tool `shown` with a mark at the corner
|
||||
/// when there is a flyout. A click, Enter or Space selects the shown tool and runs its command; holding the press,
|
||||
/// dragging it away from the button, a right click or the Menu key opens the flyout; a press on the corner mark opens it
|
||||
/// at once; after a press that opened it, releasing over a row picks it. Rows are the tools' commands, the shown tool with the radio mark. A hold selects the shown tool
|
||||
/// unless `hold_selects` is off, as for a command button. An Alt-click selects the next enabled tool of the slot,
|
||||
/// wrapping, and opens no flyout. With a `click` command, a click fires that command and selects nothing, and the
|
||||
/// at once; after a press that opened it, releasing over a row picks it. Rows are the tools' commands, the shown tool
|
||||
/// with a check mark and the others with none. A hold selects the shown tool unless `hold_selects` is off, as for a
|
||||
/// command button. An Alt-click selects the next enabled tool of the slot, wrapping, and opens no flyout. With a `click` command, a click fires that command and selects nothing, and the
|
||||
/// release that ends a hold fires nothing. A modified press is never a double click.
|
||||
///
|
||||
/// With `tear_off` a bar runs down the flyout's end edge, named by `RailWords::tear_off`: a press on it dragged past
|
||||
@@ -372,9 +372,9 @@ impl<T: Value + 'static> Component for FlyoutButton<'_, T> {
|
||||
}
|
||||
}
|
||||
|
||||
/// The flyout: one row per tool, each the tool's command, the shown tool with the radio mark, and with `tear_off`
|
||||
/// the bar beside the rows. Running a row reports its tool and closes the flyout; tearing it off by the bar
|
||||
/// reports the pointer and closes it.
|
||||
/// The flyout: one row per tool, each the tool's command, the shown tool with a check mark and the others with
|
||||
/// none, and with `tear_off` the bar beside the rows. Running a row reports its tool and closes the flyout; tearing
|
||||
/// it off by the bar reports the pointer and closes it.
|
||||
fn overlay(&mut self, ui: &mut OverlayUi<'_>, cx: &mut Cx<'_, Self>) {
|
||||
if !self.has_flyout() {
|
||||
return;
|
||||
@@ -394,7 +394,9 @@ impl<T: Value + 'static> Component for FlyoutButton<'_, T> {
|
||||
let rows = Menu::inline(name.clone()).show(ui, |ui, _| {
|
||||
let mut ran = None;
|
||||
for (at, tool) in tools.iter().enumerate() {
|
||||
let mut item = MenuItem::command(tool.command.clone()).radio_mark(tool.id == *shown);
|
||||
// A check before the shown tool and nothing before the others, as the reference application's
|
||||
// flyouts do: an unchosen radio row would draw an empty ring before every other tool.
|
||||
let mut item = MenuItem::command(tool.command.clone()).check(tool.id == *shown);
|
||||
if let Some(icon) = &tool.icon {
|
||||
item = item.icon(icon.clone());
|
||||
}
|
||||
|
||||
@@ -111,6 +111,33 @@ fn dragging_a_press_away_opens_the_flyout_and_releasing_over_a_row_picks_it() {
|
||||
assert_eq!(*dragged.selected.borrow(), [REDO], "releasing over Redo picks it and nothing else");
|
||||
}
|
||||
|
||||
/// The flyout marks only the shown tool, with a check, as the reference application's tool flyouts do: the other
|
||||
/// rows draw no mark, not the empty ring of an unchosen radio row (photocraft#17102).
|
||||
#[trial]
|
||||
fn the_flyout_checks_the_shown_tool_and_marks_no_other_row() {
|
||||
let mut held = rig(true);
|
||||
let target = button(&held);
|
||||
held.fixture.press(&target);
|
||||
held.fixture.advance(HELD);
|
||||
held.fixture.idle(3);
|
||||
assert!(!held.fixture.by_role(Role::MENU).is_empty(), "a held press opens the flyout");
|
||||
// The rows, not the rail button that also bears the shown tool's name.
|
||||
let checked = |fixture: &Fixture, label: &str| {
|
||||
let rows = fixture.by_role(Role::MENU_ITEM_CHECK_BOX);
|
||||
let row = rows.iter().find(|row| fixture.tree().name_of(row.node) == Some(label));
|
||||
fixture.tree().toggled_of(row.unwrap_or_else(|| panic!("the flyout lists {label}")).node)
|
||||
};
|
||||
assert_eq!(checked(&held.fixture, "Undo"), Some(Mixed::Same(true)), "the shown tool's row is checked");
|
||||
assert_eq!(checked(&held.fixture, "Redo"), Some(Mixed::Same(false)), "another tool's row is not");
|
||||
let rings = held
|
||||
.fixture
|
||||
.frame_shapes()
|
||||
.iter()
|
||||
.filter(|shape| matches!(shape, egui::Shape::Circle(circle) if circle.stroke.width > 0.0 && circle.fill == egui::Color32::TRANSPARENT))
|
||||
.count();
|
||||
assert_eq!(rings, 0, "no row of the flyout draws an empty ring");
|
||||
}
|
||||
|
||||
/// A flyout of a tool low on the rail, too tall for the room under the tool's top, slides up to stay in the window
|
||||
/// as PhotoCraft's tool flyouts do, rather than opening upward from the tool as a submenu does.
|
||||
#[trial]
|
||||
|
||||
Reference in new issue
Block a user