Merge remote-tracking branch 'origin/next' into fix/vc-buttons-fields

This commit is contained in:
bflatastic
2026-11-24 13:51:33 +07:00
13 changed files with 245 additions and 30 deletions
@@ -152,6 +152,42 @@ fn cmd_or_ctrl_with_page_down_scrolls_a_focused_canvas_sideways_on_every_os() {
}
}
const NEXT_ARTBOARD: &str = "canvasTrial.nextArtboard";
/// A page key the app binds to a command runs it ahead of the canvas's page scroll, with nothing focused and with the
/// canvas focused (Page Down goes to the next artboard); an unbound page key still scrolls the view.
#[trial]
fn a_bound_page_key_runs_its_command_and_an_unbound_one_pages_the_canvas() {
let view = Rc::new(Cell::new(CanvasView::new(egui::Rect::ZERO, Point::new(2000.0, 2000.0), 1.0)));
let shown = Rc::clone(&view);
let mut fixture = Fixture::new(move |ui| {
let mut given = shown.get();
given.rect = ui.available_rect_before_wrap();
let canvas = Canvas::new("Document").document(Size::new(4000.0, 4000.0)).view(given).show(ui, |_, _| {});
shown.set(canvas.output.view.unwrap_or(given));
});
let binding = Binding::parse("PageDown").expect("the trial's chord parses");
let catalog =
AppCatalog::new(vec![CommandDef::new(NEXT_ARTBOARD, "Next Artboard", Scope::app()).with_default(binding)], 1).expect("the catalog is valid");
fixture.commands(CommandInput::new().catalog(catalog));
fixture.settle();
let page = |fixture: &mut Fixture, key: Key| {
frame::take_output(fixture.ctx());
let before = view.get().center;
fixture.key(key, Modifiers::NONE).settle();
let fired: Vec<String> = frame::take_output(fixture.ctx()).fired.into_iter().map(|fired| fired.command.id).collect();
(fired, view.get().center != before)
};
assert_eq!(fixture.focused(), None, "nothing is focused");
assert_eq!(page(&mut fixture, Key::PageDown), (vec![NEXT_ARTBOARD.to_owned()], false), "unfocused: the bound Page Down runs its command");
assert_eq!(page(&mut fixture, Key::PageUp), (Vec::new(), true), "unfocused: the unbound Page Up scrolls");
let canvas = fixture.by_role(Role::CANVAS)[0];
fixture.click(&canvas);
assert!(fixture.focused().is_some(), "the click focuses the canvas");
assert_eq!(page(&mut fixture, Key::PageDown), (vec![NEXT_ARTBOARD.to_owned()], false), "focused: the bound Page Down runs its command");
assert_eq!(page(&mut fixture, Key::PageUp), (Vec::new(), true), "focused: the unbound Page Up scrolls");
}
#[trial]
fn cmd_or_ctrl_with_page_down_on_a_focused_canvas_control_scrolls_the_canvas_sideways() {
let view = Rc::new(Cell::new(CanvasView::new(egui::Rect::ZERO, Point::new(2000.0, 2000.0), 1.0)));
+16 -1
View File
@@ -20,7 +20,7 @@ use craft_ui::dialog::Dialog;
use craft_ui::display::Text;
use craft_ui::popover::Popover;
use craft_ui::primitives::Draw;
use craft_ui::runtime::commands::{self, EditCommands, FireSource};
use craft_ui::runtime::commands::{self, CommandSet as _, EditCommands, FireSource};
use craft_ui::runtime::frame::take_output;
use craft_ui::testing::access::Declared;
use craft_ui::testing::focus::{AccessActionKind, key_release};
@@ -169,6 +169,21 @@ fn a_fired_command_whose_key_the_tool_claims_reaches_it_with_nothing_focused() {
assert!(take_output(canvas.fixture().ctx()).fired.is_empty(), "no app command ran");
}
/// A command a button fires runs as the button's command, though the tool claims its key: only a menu's or the
/// palette's stands for the key (a toolbar's tool button finishes a gesture the tool holds the keyboard for).
#[trial]
fn a_pointer_fired_command_whose_key_the_tool_claims_runs_as_a_command() {
let mut canvas = ToolFixture::new("Document", Outline::new(true));
canvas.fixture().settle();
assert_eq!(canvas.fixture().focused(), None, "nothing is focused");
take_output(canvas.fixture().ctx());
assert!(commands::fire(canvas.fixture().ctx(), EditCommands::Delete, FireSource::Pointer), "Delete runs");
canvas.fixture().settle();
assert_eq!(canvas.tool().seen, [], "the tool got no Delete");
let fired = take_output(canvas.fixture().ctx()).fired;
assert!(fired.iter().any(|fired| fired.command.id == EditCommands::Delete.id()), "the app's Delete ran: {fired:?}");
}
/// A tool that takes every key the host offers it, and the lone Alt tap while `taps`.
#[derive(Default)]
struct Taker {
@@ -253,6 +253,7 @@ pub(crate) fn host(ctx: &Context, layer: &Layer<'_>, body: &mut dyn FnMut(&mut U
entry.region = layer.region;
entry.scoped = scope.is_some();
entry.absorbs = overlay.dismiss.outside == Outside::Absorb;
entry.closes_on_commands = overlay.dismiss.commands;
overlay::record(ctx, entry);
let dismissed = if layer.exiting { None } else { dismissal(ctx, layer, shown.rect, anchor, scope, &mut memory) };
// The layer closes after its body ran: the run shows it open, so a record of the run is not replayed.
@@ -330,6 +331,7 @@ fn host_in_popup(ctx: &Context, layer: &Layer<'_>, popup: PopupRoom, body: &mut
entry.exiting = layer.exiting;
entry.scoped = scope.is_some();
entry.absorbs = overlay.dismiss.outside == Outside::Absorb;
entry.closes_on_commands = overlay.dismiss.commands;
entry.window = true;
entry.popup = true;
overlay::record(ctx, entry);
@@ -41,14 +41,16 @@ pub struct Dismiss {
pub on_activate: bool,
/// The anchor is no longer shown.
pub anchor_gone: bool,
/// A command a key, a native menu pick or the palette ran, from outside the layer and the layers opened from it.
pub commands: bool,
/// Seconds after opening.
pub timeout: Option<f32>,
}
impl Dismiss {
/// An outside press closes; nothing else does.
/// An outside press or a command closes; nothing else does.
pub const fn new() -> Self {
Dismiss { outside: Outside::Close, enter: false, focus_left: false, on_activate: false, anchor_gone: true, timeout: None }
Dismiss { outside: Outside::Close, enter: false, focus_left: false, on_activate: false, anchor_gone: true, commands: true, timeout: None }
}
/// Sets what an outside press does.
@@ -75,6 +77,13 @@ impl Dismiss {
self
}
/// Closes when a key, a native menu pick or the palette runs a command from outside it; off for a layer its host
/// opens and closes, as a dock panel's flyout.
pub const fn commands(mut self, on: bool) -> Self {
self.commands = on;
self
}
/// Closes after `seconds`.
pub const fn timeout(mut self, seconds: Option<f32>) -> Self {
self.timeout = seconds;
@@ -1731,10 +1731,11 @@ fn queue(ctx: &Context, fired: Fired) {
observed.push(fired.command.clone());
}
});
// A command whose key the focused component claims reaches it as that key, as the key's press does; an edit command
// goes to the focused component that lists it; otherwise it goes to the instance that declared it or, with none,
// stays an app command.
if fired.phase != FirePhase::Release {
// A command run from a menu or the palette whose key the focused component claims reaches it as that key, as the
// key's press does (a button's is the button's command, even while a canvas gesture claims every key); an edit
// command goes to the focused component that lists it; otherwise it goes to the instance that declared it or, with
// none, stays an app command.
if fired.phase != FirePhase::Release && matches!(fired.source, FireSource::Menu | FireSource::Palette) {
let chords: Vec<Chord> =
bindings(ctx, &fired.command).into_iter().filter(|binding| !binding.trigger.is_double()).map(|binding| binding.trigger.chord).collect();
if keys::fire_claimed(ctx, &chords) {
+20 -4
View File
@@ -140,7 +140,8 @@ pub(crate) fn begin(ctx: &Context, press_captured: bool) -> EscapeRouting {
// session control on a canvas), unless a modal layer is open. The window's document canvas is its key target
// (`focus::host_canvas`): Page Up and Down, Home and End page it as they do while it has the focus. What the
// canvas takes is its alone, as while it has the focus: the app's shortcuts do not run with it too. It takes the
// arrows with the modifiers it acts on (`KeyUse::nudge_mods`); the others are the app's.
// arrows with the modifiers it acts on (`KeyUse::nudge_mods`); the others are the app's, as is a page key bound to
// a command that runs now (`page_key_runs`).
let declared = |mods: Mods| canvas.as_ref().is_none_or(|canvas| canvas.stop.keys.nudge_mods.contains(mods));
for (press, taken) in batch.presses.iter().zip(&mut consumed).filter(|(press, _)| !press.canvas) {
if let Some(id) = hover_delete
@@ -161,6 +162,7 @@ pub(crate) fn begin(ctx: &Context, press_captured: bool) -> EscapeRouting {
} else if let Some(canvas) = &canvas
&& let Some(Intent::Move(mv @ (NavMove::PageUp | NavMove::PageDown | NavMove::Start | NavMove::End), mods)) =
keys::intent(os, press.key, press.mods, canvas.stop.role)
&& !page_key_runs(ctx, canvas, press)
{
push(&mut routed, Some(canvas.stop.id), Intent::Move(mv, mods), false);
*taken = Taken::Canvas;
@@ -185,7 +187,9 @@ pub(crate) fn begin(ctx: &Context, press_captured: bool) -> EscapeRouting {
}
let over: Vec<bool> = batch.presses.iter().map(held_press).collect();
let (shortcuts, held) = owned_shortcuts(ctx, target.as_ref(), &batch, &consumed, &taken_texts, &over);
withdraw_taken(ctx, target.is_some(), &batch, &held, &withdrawn_texts);
// The app's own widget, focused or the window's canvas, reads its keys from egui.
let host = target.as_ref().or(canvas.as_ref()).is_some_and(|rec| rec.stop.host);
withdraw_taken(ctx, host, &batch, &held, &withdrawn_texts);
let pasted = batch.paste.clone().zip(focused).map(|(content, id)| (id, content));
// PLAN: a repeat Tab of a held-over key is not gated; `take_nav` reads `batch.tabs` before this hook runs (owner: focus).
// One Escape press cancels once: its repeats cancel nothing more, in the layer it closed or in what that uncovered.
@@ -277,6 +281,18 @@ fn remap_mods(mods: &[(usize, Mods)], kept: &[bool]) -> Vec<(usize, Mods)> {
mods.iter().map(|(at, held)| (kept.get(..*at).unwrap_or(kept).iter().filter(|stays| **stays).count(), *held)).collect()
}
/// Whether `press`, a page key (Page Up or Down, Home, End) of the window's document canvas `canvas`, focused or the
/// unfocused window's key target, runs the command the window's keymap binds it to (`commands::runs_now`): that app
/// shortcut goes ahead of the canvas's page scroll (Q370), as the keymap ran it before the canvas paged. A canvas's
/// editor part keeps its page keys as its input.
fn page_key_runs(ctx: &Context, canvas: &StopRec, press: &Press) -> bool {
let keys = &canvas.stop.keys;
keys.chrome_key
&& !keys.is_document_editor()
&& matches!(press.key, Key::PageUp | Key::PageDown | Key::Home | Key::End)
&& commands::runs_now(ctx, crate::runtime::egui::pass::current_viewport(ctx), &Chord { mods: press.mods, key: press.key })
}
pub(super) fn push(routed: &mut HashMap<Option<Id>, Routed>, target: Option<Id>, intent: Intent, horizontal: bool) {
routed.entry(target).or_default().items.push(Item { intent, horizontal, source: None });
}
@@ -687,8 +703,8 @@ fn press_route(ctx: &Context, os: Os, rec: &StopRec, press: &Press, driven: Opti
let leaves_row = !caret && is_vertical(mv) && focus::is_row_child(ctx, stop);
let kept = caret || (stop.part.is_none() && stop.keys.keep.keeps_arrow(mv));
// A stop that does not act on its moves leaves a move key a scoped command around it binds to that
// command, ahead of its roving group and the scroll owner.
if !leaves_row && !kept && !stop.role.moves && commands::binds_scoped(ctx, &chord) {
// command, ahead of its roving group and the scroll owner; the document canvas leaves a bound page key.
if (!leaves_row && !kept && !stop.role.moves && commands::binds_scoped(ctx, &chord)) || page_key_runs(ctx, rec, press) {
PressRoute::Free
} else {
PressRoute::Move(mv, mods)
+10 -2
View File
@@ -168,6 +168,8 @@ pub struct OpenEntry {
pub(crate) scoped: bool,
/// A press outside its family closes it and goes no further.
pub(crate) absorbs: bool,
/// A command run from outside it closes it (`Dismiss::commands`).
pub(crate) closes_on_commands: bool,
/// The entry is an OS window of the integration: it takes its place in the stack's order and facts, and no egui
/// layer is shown for it.
pub(crate) window: bool,
@@ -225,6 +227,7 @@ impl OpenEntry {
cover: None,
scoped: false,
absorbs: false,
closes_on_commands: true,
window: false,
popup: false,
region: None,
@@ -365,7 +368,8 @@ pub fn request_close(ctx: &Context, id: Id, why: CloseReason) {
push_close(ctx, id, why, false);
}
/// Queues a close of every popup layer of the running viewport shown last frame: its menus, dropdowns and lists. The
/// Queues a close of every popup layer of the running viewport shown last frame that a command closes
/// (`Dismiss::commands`): its menus, dropdowns and lists, not a dock panel's flyout. The
/// runtime's command dispatcher calls it when a key runs a command; an app whose own dispatcher runs a shortcut from the
/// keys the runtime leaves in egui's input calls it when the shortcut runs. Either way the command closes the open
/// popups as a menu pick does; modal layers, windows and toasts stay.
@@ -387,7 +391,11 @@ pub(crate) fn close_popups_outside(ctx: &Context, inside: &[Id]) {
at = pass.last.iter().find(|entry| entry.id == id).and_then(|entry| entry.parent);
}
}
pass.last.iter().filter(|entry| entry.rank == Rank::Popup && !entry.exiting && !kept.contains(&entry.id)).map(|entry| entry.id).collect()
pass.last
.iter()
.filter(|entry| entry.rank == Rank::Popup && entry.closes_on_commands && !entry.exiting && !kept.contains(&entry.id))
.map(|entry| entry.id)
.collect()
});
for id in popups {
push_close(ctx, id, CloseReason::Requested, false);
+16 -9
View File
@@ -231,9 +231,10 @@ fn a_recorder_reads_a_press_as_one_chord_and_no_command_runs() {
assert_eq!(press_k("button").0, Vec::new(), "no other role reads chords");
}
/// With nothing focused, the window's document canvas takes Page Down and the arrows' nudge, as while it has the focus;
/// the press is its alone, so no app shortcut runs with it as well (a page view would turn twice). Without a canvas the
/// press is the app's.
/// With nothing focused, the window's document canvas takes the arrows' nudge and an unbound Page Up, as while it has
/// the focus; the press is its alone, so no app shortcut runs with it as well (a page view would turn twice). A page key
/// the app binds to a command that runs is the app's (Page Down to the next artboard). Without a canvas every press is
/// the app's.
#[trial]
fn an_unfocused_press_the_window_canvas_takes_reaches_no_app_shortcut() {
let paged = Rc::new(Cell::new(0));
@@ -245,8 +246,10 @@ fn an_unfocused_press_the_window_canvas_takes_reaches_no_app_shortcut() {
stop(ui, "canvas", KeyUse::CANVAS);
}
let mut intents = intents_of(ui.ctx(), Some(id("canvas")), false);
if intents.take(Intent::Move(craft_behavior::NavMove::PageDown, craft_behavior::MoveMods::PLAIN)) {
sink.set(sink.get() + 1);
for page in [craft_behavior::NavMove::PageDown, craft_behavior::NavMove::PageUp] {
if intents.take(Intent::Move(page, craft_behavior::MoveMods::PLAIN)) {
sink.set(sink.get() + 1);
}
}
};
let mut bound = Overrides::default();
@@ -256,17 +259,21 @@ fn an_unfocused_press_the_window_canvas_takes_reaches_no_app_shortcut() {
frames.commands(CommandInput::new().overrides(Arc::new(bound)));
frames.frame(Vec::new(), &mut show);
take_output(&frames.ctx);
let fired = |frames: &mut Frames, show: &mut dyn FnMut(&mut Ui)| {
frames.frame(vec![key_press(Key::PageDown, Modifiers::NONE), key_press(Key::ArrowRight, Modifiers::NONE)], &mut *show);
let fired = |frames: &mut Frames, show: &mut dyn FnMut(&mut Ui), key: Key| {
frames.frame(vec![key_press(key, Modifiers::NONE), key_release(key, Modifiers::NONE)], &mut *show);
frames.frame(Vec::new(), &mut *show);
take_output(&frames.ctx).fired.len()
};
assert_eq!(fired(&mut frames, &mut show), 0, "neither press reaches the app's commands");
assert_eq!(fired(&mut frames, &mut show, Key::ArrowRight), 0, "the arrow is the canvas's nudge");
assert_eq!(fired(&mut frames, &mut show, Key::PageUp), 0, "the unbound Page Up is the canvas's");
assert_eq!(paged.get(), 1, "the canvas pages");
assert_eq!(fired(&mut frames, &mut show, Key::PageDown), 1, "the bound Page Down is the app's");
assert_eq!(paged.get(), 1, "the canvas does not page with it");
canvas.set(false);
frames.idle(2, &mut show);
take_output(&frames.ctx);
assert_eq!(fired(&mut frames, &mut show), 2, "without a canvas both presses are the app's");
let presses = [Key::PageDown, Key::ArrowRight].map(|key| fired(&mut frames, &mut show, key));
assert_eq!(presses, [1, 1], "without a canvas both presses are the app's");
}
/// A recorder holds every press: the app reads none from egui's input, and `focus_holds` answers so before the press.
+7 -2
View File
@@ -90,13 +90,18 @@ impl Flyout {
let bounded = self.within.is_finite();
let least = if bounded { self.least.min(self.within.size().max(Vec2::ZERO)) } else { self.least };
// A float place as well as the caller's position: the placement pins no edge, so the edge set alone decides
// the grips.
// the grips. The host's binding opens and closes the flyout, so a command leaves it open.
let overlay = Overlay::popover()
.place(Place::Float(FloatPlace::at(top_left)))
.placed_at(top_left)
.size_limits(SizeLimits::at_least(least))
.resize_edges(free.union(ResizeEdges::TOP).union(ResizeEdges::BOTTOM))
.dismiss(Dismiss::new().outside(if self.auto_collapse { Outside::Close } else { Outside::Keep }).focus_left(self.auto_collapse))
.dismiss(
Dismiss::new()
.outside(if self.auto_collapse { Outside::Close } else { Outside::Keep })
.focus_left(self.auto_collapse)
.commands(false),
)
.body_scroll(false);
if bounded { overlay.bounds(self.within) } else { overlay }
}
+54 -2
View File
@@ -1,15 +1,20 @@
//! Trials of `IconicColumn`: the letter of a panel without an icon, the names a wide column shows, the grips of its
//! groups, and the resizes of its flyouts.
//! groups, the resizes of its flyouts, and a flyout that a command leaves open.
#![allow(clippy::panic, clippy::expect_used, reason = "trials assert by panicking")]
use super::GRIP;
use crate::buttons::Button;
use crate::contract::overlay::{self, OpenFilter};
use crate::contract::{Bind, Show as _, ShowContainer as _};
use crate::docking::group::GRIP_ABOVE;
use crate::docking::{
DockHeights, DockSizes, DockSpot, DockTargets, DragUnit, FlyoutResize, GroupAt, GroupDrag, GroupGrip, IconicColumn, PanelKey, PanelSpec,
};
use crate::runtime::commands::{AppCatalog, Binding, CommandDef, CommandInput, Scope};
use crate::runtime::drag;
use crate::runtime::env::Direction;
use crate::runtime::focus::{FocusTarget, request};
use crate::runtime::frame::take_output;
use crate::sections::Panel;
use crate::style::StyleCx;
use crate::testing::memory::global;
@@ -18,7 +23,7 @@ use crate::testing::{Fixture, trial};
use craft_behavior::DockSide;
use craft_behavior::dock::{Action, Column, DockEdge, Group, Layout, Node};
use craft_behavior::overlay::Side;
use egui::{Pos2, Rect, Vec2};
use egui::{Key, Modifiers, Pos2, Rect, UiBuilder, Vec2};
use std::cell::{Cell, RefCell};
use std::rc::Rc;
@@ -238,6 +243,53 @@ fn a_press_outside_closes_the_flyout_only_with_auto_collapse() {
}
}
/// The app command the trials bind to a key.
const NUDGE: &str = "flyoutTrial.nudge";
/// A key that runs an app command, with a stop in the open flyout focused, leaves the flyout open and live in every
/// pass and the stop focused, with Auto-Collapse Iconic Panels off or on: the host's binding opens and closes a flyout,
/// and a command closes only the transient popups (menus, dropdowns, lists).
#[trial]
fn a_key_command_leaves_the_open_flyout_and_the_focus_in_it() {
for auto_collapse in [false, true] {
let (open, stop, faded) = (Rc::new(Cell::new(None)), Rc::new(Cell::new(None)), Rc::new(Cell::new(false)));
let (seen, shown, fade) = (Rc::clone(&open), Rc::clone(&stop), Rc::clone(&faded));
let place = Rect::from_min_size(Pos2::ZERO, Vec2::new(RAIL, SCREEN.y));
let mut fixture = Fixture::new(move |ui| {
let column = Column::new(vec![Group::new(vec![0, 1], 0)]);
let mut now = seen.get();
IconicColumn::new("Panels", global("iconic column", "commands"), &column, Bind::bound(&mut now), &spec)
.within(screen())
.auto_collapse(auto_collapse)
.show_flyouts_at(ui, place, |_, at, ui, _| {
let GroupAt::Show(rect) = at else { return None };
shown.set(Some(ui.scope_builder(UiBuilder::new().max_rect(rect), |ui| Button::new("Snap").show(ui).id).inner));
None
});
// Last pass the open flyout was not among the live layers that take keys: it played its exit.
fade.set(fade.get() || (now.is_some() && !overlay::any_open(ui.ctx(), OpenFilter::Keys)));
seen.set(now);
});
let binding = Binding::parse("F9").expect("the trial's chord parses");
let catalog = AppCatalog::new(vec![CommandDef::new(NUDGE, NUDGE, Scope::app()).with_default(binding)], 1).expect("the catalog is taken");
fixture.commands(CommandInput::new().catalog(catalog)).room(SCREEN).settle();
let icon = fixture.by_label("Swatches").expect("the Swatches icon").rect.center();
fixture.click_at(icon).settle();
let button = stop.get().expect("the flyout shows its stop");
request(fixture.ctx(), FocusTarget::Id(button));
fixture.settle();
assert_eq!(fixture.focused_stop().map(|(id, _)| id), Some(button), "auto-collapse {auto_collapse}: the flyout's stop has the focus");
faded.set(false);
take_output(fixture.ctx());
fixture.key(Key::F9, Modifiers::NONE).settle();
let fired = take_output(fixture.ctx()).fired;
assert!(fired.iter().any(|fired| fired.command.id == NUDGE), "auto-collapse {auto_collapse}: the key runs its command");
assert_eq!(open.get(), Some(1), "auto-collapse {auto_collapse}: the flyout stays open");
assert!(!faded.get(), "auto-collapse {auto_collapse}: and never plays its exit");
assert_eq!(fixture.focused_stop().map(|(id, _)| id), Some(button), "auto-collapse {auto_collapse}: and its stop keeps the focus");
}
}
/// The top edge and the free top corner grow the flyout upward on either window edge: the bottom and the column-side
/// edge stay, the column-side edge has no grip, and the new top is kept as an offset from the icons, so it survives
/// another group's flyout and reopening.
@@ -130,3 +130,70 @@ fn a_picker_dialog_settles_after_opening() {
assert!(passes[2..].iter().all(|&n| n == 1), "{name}: every frame from the third runs one pass: {passes:?}; {warned:?}");
}
}
/// A form dialog with two panes side by side, as Export for Screens lays them out: a heading, a grid of boards and a
/// row of a button and a text field that takes the focus as the dialog opens, and options beside. Counts the button's
/// clicks and the grid's selection events.
fn panes_with_a_field(clicks: &Rc<Cell<u32>>, picks: &Rc<Cell<usize>>) -> Fixture {
use craft_ui::buttons::Button;
use craft_ui::contract::{CollectionEvent, Props as _};
use craft_ui::list::ToggleState;
use craft_ui::runtime::focus::FocusRequest;
use craft_ui::text::TextField;
let opening = Rc::new(Cell::new(true));
let (clicks, picks, opens) = (clicks.clone(), picks.clone(), opening.clone());
let mut fixture = Fixture::new(move |ui| {
let mut value = String::new();
FormDialog::new("Export", Bind::bound(&mut value)).show(ui, |ui, _, _| {
let keys: Vec<u64> = (0..3).collect();
let source = keyed(&keys, |key: &u64| *key);
Row::new().show(ui, |ui, _| {
Stack::new().show(ui, |ui, _| {
Text::new("Artboards").show(ui);
let out = TileGrid::new("Boards").checks(true).max_rows(3).show_items(ui, &source, &mut |key, _| {
Tile::new(format!("Board {key}")).check(ToggleState::Off).thumb(ThumbAspect::SQUARE, |_, _| {})
});
picks.set(picks.get() + out.response.events.iter().filter(|event| matches!(event, CollectionEvent::Selection { .. })).count());
Row::new().show(ui, |ui, _| {
clicks.set(clicks.get() + Button::new("Clear Selection").show(ui).clicks);
let field = TextField::new("Prefix", Bind::given(String::new()));
if opens.get() { field.request_focus(FocusRequest::Take) } else { field }.show(ui);
});
});
Stack::new().show(ui, |ui, _| {
Text::new("Options").show(ui);
});
});
true
});
});
fixture.room(egui::vec2(1024.0, 768.0));
fixture.settle();
opening.set(false);
assert!(fixture.focused_stop().is_some(), "the field takes the focus");
fixture
}
/// A press on a button in a row beside a focused text field, under a grid, is the button's: the pane's room holds the
/// grid's rows and what follows them. (The field keeps the focus, as a dialog's field does when one of its buttons is
/// pressed.)
#[trial]
fn a_press_on_a_button_beside_a_field_is_the_buttons() {
let (clicks, picks) = (Rc::new(Cell::new(0)), Rc::new(Cell::new(0)));
let mut fixture = panes_with_a_field(&clicks, &picks);
let button = fixture.by_label("Clear Selection").expect("the button shows");
fixture.click(&button).settle();
assert_eq!(clicks.get(), 1, "the press on the button clicks it");
}
/// A click on a tile of a grid over a focused text field picks the tile, and takes the focus off the field.
#[trial]
fn a_tile_click_beside_a_focused_field_is_reported() {
let (clicks, picks) = (Rc::new(Cell::new(0)), Rc::new(Cell::new(0)));
let mut fixture = panes_with_a_field(&clicks, &picks);
let field = fixture.focused_stop();
let tile = fixture.by_label("Board 2").expect("the tile shows");
fixture.click(&tile).settle();
assert!(picks.get() > 0, "the grid reports the click on its tile as a selection");
assert_ne!(fixture.focused_stop(), field, "and the field loses the focus");
}
-3
View File
@@ -1042,9 +1042,6 @@ impl<K: Clone + Eq + Hash + Send + Sync + 'static> Collection for TileGrid<'_, K
/// The last layout again while the width, the rows stamp and everything the arrangement reads are the same.
fn ideal_width(&self, item: Option<Vec2>, _rows: usize, cx: &StyleCx<'_>) -> f32 {
if self.card_columns == 0 {
return 0.0;
}
let style = GridSizes::of(cx, self.card, self.card_text, self.items.row_height, self.regular_card_padding, self.action_place);
let aspect = if self.aspect.is_finite() && self.aspect > 0.0 { self.aspect } else { 1.0 };
let around = style.around.get(self.caption, self.detail_line);
@@ -153,7 +153,7 @@ fn metadata_value_copies_without_selecting_the_row() {
fn tab_toggles_the_panels_from_read_only_text_a_press_or_drag_focused() {
let text = Rc::new(Cell::new(Id::NULL));
let seen = text.clone();
let canvas = Id::new("document canvas");
let canvas = Id::unique("document canvas");
let mut fixture = Fixture::new(move |ui| {
Button::new("Save").show(ui);
seen.set(SelectableText::new("Path", "/projects/poster.indd").show(ui).id);