From b1b10ab7350c13448417fc7085aa8b5e54bf2d7c Mon Sep 17 00:00:00 2001 From: aiongg Date: Fri, 20 Nov 2026 21:59:25 +0000 Subject: [PATCH] Brush Preset picker: a rename request runs the view that takes it, the picker opens in its search field, a memoized view keeps its body's column - Collection requests are a tracked input: request_rename moves it and the item step that takes the request reads it, so a pending request runs the memoized view that takes it. - A preset picker opens with the focus in its search field (the browser's search field is the popover's default stop), so its head and list replay while it is open and idle; without a search field, on its first stop. - A memoized view's layout room keeps whether its body is a content-sized or a given column, as it keeps the content axes: a rule that fills the width in a view in a content-sized popover took the open room, not the popover's width. - Trials: a request runs the taking view once; a view in a popover fills its width as without the view. The escape revert trial edits roundness by dragging a dot (a press on the tip widget takes no focus). --- crates/draw/src/ui/brush_presets/picker.rs | 3 +- crates/draw/tests/it/brush_presets.rs | 8 +- .../ui-contract/src/contract/items/request.rs | 6 +- crates/ui-contract/src/contract/memo_view.rs | 21 ++--- crates/ui-contract/src/runtime/env.rs | 15 +++- crates/ui-contract/src/runtime/inputs.rs | 13 ++- .../src/patterns/presets/browser.rs | 12 +++ .../src/patterns/presets/picker.rs | 9 +- crates/ui-patterns/tests/it/presets/picker.rs | 4 +- crates/ui-widgets/tests/it/body/memo_view.rs | 83 ++++++++++++++++++- 10 files changed, 144 insertions(+), 30 deletions(-) diff --git a/crates/draw/src/ui/brush_presets/picker.rs b/crates/draw/src/ui/brush_presets/picker.rs index c530ef168..4cc0ec45c 100644 --- a/crates/draw/src/ui/brush_presets/picker.rs +++ b/crates/draw/src/ui/brush_presets/picker.rs @@ -226,7 +226,8 @@ impl Opened { /// brush live and report [`BrushPresetPickerOutput::tip`], [`diameter`](BrushPresetPickerOutput::diameter) and /// [`hardness`](BrushPresetPickerOutput::hardness). /// - **Search row.** The browser's search field (any letter case, groups open while filtering) unless Show Search -/// Bar is off, then at its reading end the Brush Settings and New Brush Preset buttons and the gear. +/// Bar is off, then at its reading end the Brush Settings and New Brush Preset buttons and the gear. The popover +/// opens with the focus in the search field, so typing filters the presets. /// - **Gear menu.** New Brush Preset…; Rename Brush… (opens the name field on the current preset) and Delete Brush… /// (enabled with a current preset); the Brush Name, Brush Stroke and Brush Tip boxes (at least one stays on); Show /// Search Bar; Import Brushes… with [`import`](Self::import). The app adds its own rows to each section with diff --git a/crates/draw/tests/it/brush_presets.rs b/crates/draw/tests/it/brush_presets.rs index 348d7bfc4..ee29f907e 100644 --- a/crates/draw/tests/it/brush_presets.rs +++ b/crates/draw/tests/it/brush_presets.rs @@ -3,7 +3,7 @@ //! roundness; Escape reverts the head's edits. use craft_draw::ui::brush_presets::{BrushCardParts, BrushPick, BrushPickerState, BrushPickerValues, BrushPresetPicker, BrushRowPaint, brush_row}; -use craft_draw::ui::brush_settings::TipAngle; +use craft_draw::ui::brush_settings::{TipAngle, ellipse_handles}; use craft_ui::contract::{Bind, Role, SaveKey}; use craft_ui::patterns::presets::{PresetEvent, PresetFns, PresetRow, PresetSource}; use craft_ui::runtime::env::Env; @@ -208,7 +208,11 @@ fn escape_reverts_size_hardness_angle_and_roundness() { let (mut fixture, host) = opened_rig(true, false); let tip = fixture.by_label("Tip angle and roundness").expect("the angle widget shows"); fixture.click_at(tip.rect.center() + Vec2::new(tip.rect.width() / 4.0, -tip.rect.height() / 4.0)); - fixture.key(Key::ArrowDown, Modifiers::ALT); + fixture.idle(2); + // A roundness dot dragged halfway to the centre squashes the ellipse. The ellipse spans most of the disc. + let turned = host.borrow().values.tip.expect("the tip shows"); + let dot = ellipse_handles(turned, tip.rect.width().min(tip.rect.height()) / 2.0 * 0.85)[0]; + fixture.drag_at(tip.rect.center() + dot, -dot / 2.0); for label in ["Size", "Hardness"] { let slider = fixture.by_role(Role::SLIDER).into_iter().find(|target| fixture.tree().name_of(target.node) == Some(label)); let slider = slider.unwrap_or_else(|| panic!("the {label} slider shows")); diff --git a/crates/ui-contract/src/contract/items/request.rs b/crates/ui-contract/src/contract/items/request.rs index 17db231b1..112d60240 100644 --- a/crates/ui-contract/src/contract/items/request.rs +++ b/crates/ui-contract/src/contract/items/request.rs @@ -1,6 +1,8 @@ -//! Requests to a collection's item step from outside it, taken at the collection's next pass. +//! Requests to a collection's item step from outside it, taken at the collection's next pass. Each request moves the +//! `Requests` input and each take reads it, so a pending request runs the memoized view that takes it. use crate::runtime::egui::memory as store; +use crate::runtime::inputs::{self, Input}; use egui::{Context, Id}; /// The rename requests not yet taken: the collection and the key to rename. @@ -24,11 +26,13 @@ pub fn request_rename(ctx: &Context, collectio requests.0.retain(|(id, _)| *id != collection); requests.0.push((collection, key.clone())); }); + inputs::bump(ctx, Input::Requests); crate::runtime::egui::repaint::request_of(ctx, crate::runtime::egui::pass::current_viewport(ctx)); } /// The rename request addressed to `collection`, once. pub(super) fn take_rename(ctx: &Context, collection: Id) -> Option { + crate::runtime::replay::note_input(ctx, Input::Requests); store::Service::>::run(ctx, |requests| { let at = requests.0.iter().position(|(id, _)| *id == collection)?; Some(requests.0.remove(at).1) diff --git a/crates/ui-contract/src/contract/memo_view.rs b/crates/ui-contract/src/contract/memo_view.rs index 04fb2ce87..fffb18b1d 100644 --- a/crates/ui-contract/src/contract/memo_view.rs +++ b/crates/ui-contract/src/contract/memo_view.rs @@ -3,7 +3,7 @@ use super::lazy::{Lazy, Shown}; use super::memo::{MemoKey, MemoProps}; -use crate::runtime::env::Env; +use crate::runtime::env::{Env, Scoped}; use crate::runtime::shift::Shift; use egui::Ui; use std::fmt; @@ -44,8 +44,8 @@ use std::sync::Arc; /// - what the scope around it hands down beyond those (enabled, read-only, size, ink, the command chain, motion, every /// app value, and the rest of `Scoped::scope_key`), in the key; /// - the framework inputs it reads outside its props (`runtime::inputs`: the modifiers, the pointer, the keys held, the -/// window facts, the keyboard layout, the keymap, a drag, the focus, the open layers, the scroll view of a nested -/// `Lazy`): a change of one runs only the views that read it; +/// window facts, the keyboard layout, the keymap, a drag, the focus, the open layers, the requests to collections, +/// the scroll view of a nested `Lazy`): a change of one runs only the views that read it; /// - the clock, read through `frame::stepped_clock`: the view runs at the next step; /// - commands sent to a command scope instance inside it: it runs while one waits. /// @@ -103,17 +103,10 @@ impl MemoVie let env = Env::of(ui); let key = Self::key(&ctx, &env, &props, show); let shown = lazy.run_keyed(ui, std::any::type_name::

(), crate::runtime::lazy::Key::Memo(key), |ui, run| { - // The content is a layout room of its own: the flow of the body around it does not reach in. It keeps the - // axes that body sizes from its content, so the view takes what its content used there, as the same - // content shown without the view would: a child that fills takes its measured size, never the open room. - let installed = Env::install_for( - ui, - env.derive_local(|scoped| { - let content = scoped.content; - scoped.start_room(); - scoped.content = content; - }), - ); + // The content is a layout room of its own: the flow of the body around it does not reach in. It keeps how + // that body sizes from its content, so the view takes what its content used there, as the same content + // shown without the view would. + let installed = Env::install_for(ui, env.derive_local(Scoped::start_view_room)); let out = show(&mut props, ui); Env::restore(&ctx, installed); run.output = Some(Arc::new(out.clone())); diff --git a/crates/ui-contract/src/runtime/env.rs b/crates/ui-contract/src/runtime/env.rs index 8963b05df..00c95d128 100644 --- a/crates/ui-contract/src/runtime/env.rs +++ b/crates/ui-contract/src/runtime/env.rs @@ -394,12 +394,22 @@ impl Scoped { self.offered = None; } + /// Starts a memoized view's layout room (`start_room`), keeping whether the enclosing body is a content-sized or a + /// given column, as `start_room` keeps the content axes. The view's content then measures and fills as it would + /// shown without the view: a child that fills takes its measured size where the body sizes from content, never the + /// open room. + pub(crate) fn start_view_room(&mut self) { + let (content_column, given_column) = (self.content_column, self.given_column); + self.start_room(); + (self.content_column, self.given_column) = (content_column, given_column); + } + /// The key of everything a memoized view shown in this scope inherits beyond `key` (the style inputs, which its /// place compares): the scope's state (enabled, read-only, size, glyphs, ink, surface, wheel, directions), the /// containers around it (arena, roving group, transform, collection item and row, inside label, footer slot, line /// length, scroll owner and axes), the command chain, motion, the host's formats and date, and every app value. Of - /// the flow fields of the enclosing body only the axes it sizes from its content are in it: a memoized view's - /// content starts a layout room of its own (`start_room`) that keeps those axes. Computed once per scope, on the + /// the flow fields of the enclosing body only how it sizes from its content is in it: a memoized view's content + /// starts a layout room of its own (`start_view_room`) that keeps those facts. Computed once per scope, on the /// first view that asks; the bytes it fed are counted then. pub(crate) fn scope_key(&self) -> u128 { *self.scope_key.get_or_init(|| { @@ -407,6 +417,7 @@ impl Scoped { let mut key = MemoKey::of_view(&self.ctx); key.feed_hash(&(self.enabled, self.read_only, self.size, self.glyphs, self.ink, self.surface, self.wheel)); key.feed_hash(&(self.direction, self.text_direction, self.ids_stable, self.cell_fills, self.least, self.unbounded, self.content)); + key.feed_hash(&(self.content_column, self.given_column)); key.feed_hash(&(self.arena, self.roving, self.item, self.row, self.scroll_owner.map(|owner| (owner.id, owner.view)))); self.transform.map(|transform| (transform.scale, transform.offset)).key(&mut key); self.footer_slot.map(|slot| (slot.owner, slot.size)).key(&mut key); diff --git a/crates/ui-contract/src/runtime/inputs.rs b/crates/ui-contract/src/runtime/inputs.rs index 4c3d8d51c..27f75e78a 100644 --- a/crates/ui-contract/src/runtime/inputs.rs +++ b/crates/ui-contract/src/runtime/inputs.rs @@ -1,5 +1,6 @@ //! Tracked inputs: the framework inputs a view can read outside its props (the modifiers, the pointer, the window's -//! facts, the keyboard layout, the keymap, a drag, the focus, the open layers, the keys held), each with a generation +//! facts, the keyboard layout, the keymap, a drag, the focus, the open layers, the keys held, the requests to +//! collections), each with a generation //! that moves when its value changes. The accessor that reads one notes it into the records open around the running //! code (`replay::note_input`); a memoized view's replay is refused when an input its run read has another generation //! now (`runtime::lazy::settled`), so a change runs only the views that read it, and a view absent while it changed @@ -34,12 +35,15 @@ pub(crate) enum Input { Focus, /// The layers shown last frame (`overlay::is_open`, `any_open`, `top`, `family`, `entry`). Overlays, + /// The requests to collections from outside them (`items::request_rename`), read by the item step that takes + /// them, so a pending request runs the view that takes it. + Requests, /// The view of the scroll area a nested `Lazy` child decides by. No generation: compared by value. Scroll, } impl Input { - pub(crate) const ALL: [Input; 10] = [ + pub(crate) const ALL: [Input; 11] = [ Input::Modifiers, Input::Pointer, Input::Keys, @@ -49,6 +53,7 @@ impl Input { Input::Drag, Input::Focus, Input::Overlays, + Input::Requests, Input::Scroll, ]; @@ -117,7 +122,7 @@ pub(crate) fn observe(ctx: &Context, input /// The generation `input` has now. The inputs a pass can change while views run (keys, drag, focus, open layers) are /// observed here; the pointer and the modifiers by the pointer's begin hook, the window facts and the layout where -/// the frame's root env is built, the keymap by the command board. +/// the frame's root env is built, the keymap by the command board, the requests by each request. pub(crate) fn generation(ctx: &Context, input: Input) -> u64 { match input { Input::Keys => observe(ctx, input, crate::runtime::keys::keys_state(ctx)), @@ -125,7 +130,7 @@ pub(crate) fn generation(ctx: &Context, input: Input) -> u64 { Input::Focus => observe(ctx, input, crate::runtime::focus::focus_state(ctx)), Input::Overlays => observe(ctx, input, crate::runtime::overlay::open_state(ctx)), Input::Keymap => return crate::runtime::commands::keymap_built(ctx), - Input::Modifiers | Input::Pointer | Input::Shell | Input::Keyboard | Input::Scroll => {} + Input::Modifiers | Input::Pointer | Input::Shell | Input::Keyboard | Input::Requests | Input::Scroll => {} } with(ctx, |generations| generations.gens[input as usize]) } diff --git a/crates/ui-patterns/src/patterns/presets/browser.rs b/crates/ui-patterns/src/patterns/presets/browser.rs index 1ca9ff484..d343f32d3 100644 --- a/crates/ui-patterns/src/patterns/presets/browser.rs +++ b/crates/ui-patterns/src/patterns/presets/browser.rs @@ -217,6 +217,9 @@ pub struct PresetBrowser<'a, K: Clone + Eq + Hash + Send + Sync + MemoProps + 's drop_zone: Option, extra_items: Vec>, actions: Vec