diff --git a/crates/draw/src/ui/brush_settings/ellipse.rs b/crates/draw/src/ui/brush_settings/ellipse.rs index 94397da55..2bb555257 100644 --- a/crates/draw/src/ui/brush_settings/ellipse.rs +++ b/crates/draw/src/ui/brush_settings/ellipse.rs @@ -153,7 +153,7 @@ pub struct TipEllipse<'a> { common: Common, value: Bind<'a, TipAngle>, /// The least roundness a dot drag, an Alt+arrow step and the drawn ellipse reach; 0 draws the flat tip as a line. - #[prop] + #[prop(quantity = "minor axis over major")] least_roundness: f64, } diff --git a/crates/draw/src/ui/slice/stories.rs b/crates/draw/src/ui/slice/stories.rs index 5a81885e7..f0ae2d27a 100644 --- a/crates/draw/src/ui/slice/stories.rs +++ b/crates/draw/src/ui/slice/stories.rs @@ -112,7 +112,7 @@ fn slice_bar_locked(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { /// fields keep what was typed while it shows. fn dialog_story(ui: &mut Ui, data: &mut StoryData, opener: &'static str, make: impl FnOnce() -> D) -> StoryOutput { let open = data.note::>("dialog", None); - if Button::new(opener).show(ui).response.clicked() { + if craft_ui::contract::clicked(&Button::new(opener).show(ui)) { *open = Some(make()); } if let Some(dialog) = open.as_mut() { diff --git a/crates/font-manager/src/picker/rows.rs b/crates/font-manager/src/picker/rows.rs index 5b44fd8a6..1cb4ad448 100644 --- a/crates/font-manager/src/picker/rows.rs +++ b/crates/font-manager/src/picker/rows.rs @@ -8,6 +8,7 @@ use std::sync::Arc; use craft_behavior::{DisplayOrder, IconId, ItemSource, Preview, Selection}; use craft_font_catalog::Catalog; +use craft_theme::Srgba; use craft_ui::buttons::{Button, IconButton, ToggleButton}; use craft_ui::choice::{Radio, RadioGroup}; use craft_ui::contract::overlay::Dismiss; @@ -374,8 +375,8 @@ fn face_thumb<'a>( return; } let ink = if on_white { - cx.painter.rect_filled(rect, 0.0, Color32::WHITE); - DataColor::new(Color32::BLACK) + cx.painter.rect_filled(rect, 0.0, Color32::from(Srgba::WHITE)); + DataColor::new(Color32::from(Srgba::BLACK)) } else { DataColor::new(cx.ink()) }; diff --git a/crates/layers/src/ui/filter/mod.rs b/crates/layers/src/ui/filter/mod.rs index 128f9e4ee..70a7973ea 100644 --- a/crates/layers/src/ui/filter/mod.rs +++ b/crates/layers/src/ui/filter/mod.rs @@ -961,11 +961,11 @@ impl<'a> LayerFilterBar<'a> { .popup(PopupKind::Menu) .show(ui); let mut open = cx.memory::().open; - if button.clicked() { + if craft_ui::contract::clicked(&button) { open = !open; } Popover::new(words.filter.clone(), Bind::bound(&mut open)).opened_by(&button).show(ui, |ui, _| { - if Button::new(words.clear_all.clone()).enabled(ticked).show(ui).clicked() { + if craft_ui::contract::clicked(&Button::new(words.clear_all.clone()).enabled(ticked).show(ui)) { next.objects.clear(); next.states.clear(); } diff --git a/crates/ui-canvas/src/canvas/pasteboard/mod.rs b/crates/ui-canvas/src/canvas/pasteboard/mod.rs index cc0869ca8..0625da39d 100644 --- a/crates/ui-canvas/src/canvas/pasteboard/mod.rs +++ b/crates/ui-canvas/src/canvas/pasteboard/mod.rs @@ -10,7 +10,7 @@ use super::space::canvas_space; use crate::contract::overlay::{Dismiss, LayerRole, Outside}; use crate::contract::{ Access, Bind, Common, Component, Cx, MeasureCx, Name, NoValue, Outcome, Overlay, OverlayUi, Overlays as _, PaintUi, PartsCx, Pointer as _, - Props as _, Rename, Role, + Props as _, Rename, Role, Show as _, }; use crate::primitives::{Checker, CheckerArea, PaintShape, PaintSlot, Rule, StrokeWidth, TextRun, paint_surround}; use crate::runtime::env::Label; @@ -208,7 +208,7 @@ impl Outcome for PasteboardOutput { /// page edges and names paint in place, over the pictures. The canvas must be given a view; without one nothing is /// shown. #[derive(crate::contract::Component, crate::contract::Props)] -#[component(canvas_control, content_painter)] +#[component(canvas_control, content_painter, overlay)] pub struct Pasteboard<'a> { #[common] common: Common, @@ -569,7 +569,7 @@ impl Component for Pasteboard<'_> { let (open, field) = (state.open.as_ref()?, field?); let size = field.size(); let at = Rect::from_min_size(ui.max_rect().min, size); - Some(crate::text::rename_field(ui, Bind::bound(&mut draft), at, &open.name)) + Some(crate::text::rename_field(Bind::bound(&mut draft), &open.name).show_at(ui, at)) }); let Some(open) = state.open else { return }; // `None`: the popup is not shown yet (it opens at the end of the pass that began the rename). diff --git a/crates/ui-canvas/src/canvas/pasteboard/stories.rs b/crates/ui-canvas/src/canvas/pasteboard/stories.rs index 3740fc583..8a1e4ed55 100644 --- a/crates/ui-canvas/src/canvas/pasteboard/stories.rs +++ b/crates/ui-canvas/src/canvas/pasteboard/stories.rs @@ -132,7 +132,7 @@ fn long_page_names(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { } /// A double press on a page's name opens its rename field. -#[story(Pasteboard<'static>, covers = [Default], drive = Drive::Custom(rename_first_name))] +#[story(Pasteboard<'static>, covers = [Open], drive = Drive::Custom(rename_first_name))] fn renaming_a_page_name(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { let view = view_values(data, 0.0); let border = border_of(data, PageBorder::DropShadow); diff --git a/crates/ui-canvas/src/canvas/tool_host.rs b/crates/ui-canvas/src/canvas/tool_host.rs index 7973da87e..740feef7a 100644 --- a/crates/ui-canvas/src/canvas/tool_host.rs +++ b/crates/ui-canvas/src/canvas/tool_host.rs @@ -953,10 +953,10 @@ fn cancel_reason(reason: PressCancel) -> CancelReason { match reason { PressCancel::Escape => CancelReason::Escape, PressCancel::FocusLost => CancelReason::Blur, - PressCancel::Disabled => CancelReason::Dismissed, PressCancel::Host => CancelReason::HostChanged, - PressCancel::Gesture => CancelReason::Dismissed, - _ => CancelReason::Removed, + PressCancel::Removed => CancelReason::Removed, + // A part turned disabled, or a second finger landing on the canvas, dismisses the gesture. + _ => CancelReason::Dismissed, } } diff --git a/crates/ui-contract/src/runtime/commands/mod.rs b/crates/ui-contract/src/runtime/commands/mod.rs index 6b2e32f9e..7faed256b 100644 --- a/crates/ui-contract/src/runtime/commands/mod.rs +++ b/crates/ui-contract/src/runtime/commands/mod.rs @@ -39,7 +39,8 @@ pub(crate) use board::{fire_bound, fire_resolved, resolve_bound, resolve_scoped} pub(crate) use board::{keymap_built, queued_for}; use crate::contract::{MemoKey, MemoProps, PlainData, Revision, Tracked}; -use crate::runtime::egui::{areas, pass}; +use crate::runtime::egui::areas::{self, LayerKey}; +use crate::runtime::egui::pass; use crate::runtime::env::Label; use crate::runtime::memory::Facts; use crate::runtime::overlay; @@ -633,7 +634,7 @@ pub fn holder(ctx: &Context, chord: &Chord) -> Option { #[derive(Clone, Debug, PartialEq)] struct ShownFact { command: CommandRef, - layer: egui::LayerId, + layer: LayerKey, rect: egui::Rect, label: Label, holder: bool, @@ -651,13 +652,13 @@ impl Shift for ShownFact { } /// Registers `command` as shown for the next pass of the running viewport. -fn register_shown(ctx: &Context, layer: egui::LayerId, rect: egui::Rect, label: Label, command: &CommandRef, holder: bool) { +fn register_shown(ctx: &Context, layer: LayerKey, rect: egui::Rect, label: Label, command: &CommandRef, holder: bool) { Facts::register(ctx, ShownFact { command: command.clone(), layer, rect, label, holder }); } /// Records that a container at `rect` holds `commands`, for this pass and viewport. Not [`CommandInput::holds`], which /// turns hold bindings on. -pub fn holds(ctx: &Context, layer: egui::LayerId, rect: egui::Rect, commands: &[CommandRef], label: Label) { +pub fn holds(ctx: &Context, layer: LayerKey, rect: egui::Rect, commands: &[CommandRef], label: Label) { for command in commands { register_shown(ctx, layer, rect, label.clone(), command, true); } @@ -666,7 +667,7 @@ pub fn holds(ctx: &Context, layer: egui::LayerId, rect: egui::Rect, commands: &[ /// Records that the bound component of `command` was shown at `rect` in `layer`, with `label`, for this pass and /// viewport: the report step calls it for a component wholly inside its clip. // PLAN: the caller is the report step (menus-w3); until it lands nothing in this crate calls it. -pub(crate) fn note_shown(ctx: &Context, layer: egui::LayerId, rect: egui::Rect, label: Label, command: &CommandRef) { +pub(crate) fn note_shown(ctx: &Context, layer: LayerKey, rect: egui::Rect, label: Label, command: &CommandRef) { register_shown(ctx, layer, rect, label, command, false); } diff --git a/crates/ui-contract/src/testing/host_key_trials.rs b/crates/ui-contract/src/testing/host_key_trials.rs index a20139eb7..1655e11a2 100644 --- a/crates/ui-contract/src/testing/host_key_trials.rs +++ b/crates/ui-contract/src/testing/host_key_trials.rs @@ -481,7 +481,7 @@ fn a_host_canvas_reads_the_clipboard_of_its_edit_set_with_nothing_focused() { /// `textless_paste` reads it in that pass only. #[trial] fn a_paste_with_no_text_is_the_paste_chord_and_reads_as_textless() { - let picture = Event::PasteImage(Arc::new(egui::ColorImage::filled([1, 1], egui::Color32::WHITE))); + let picture = Event::PasteImage(Arc::new(crate::testing::pictures::sample_picture(1, [1, 1]))); assert!(!clipboard_with_canvas(KeyUse::CANVAS, picture.clone()).1.is_empty(), "the picture's paste fires the app's Paste"); let read = Rc::new(Cell::new(false)); let seen = Rc::clone(&read); diff --git a/crates/ui-patterns/src/patterns/form_dialogs/dialog/stories.rs b/crates/ui-patterns/src/patterns/form_dialogs/dialog/stories.rs index 166c1b940..8267f59e4 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/dialog/stories.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/dialog/stories.rs @@ -1,7 +1,8 @@ //! Stories of `ParamDialog`. use super::{HostedParamDialog, ParamDialog, ParamLayout, ParamPresets}; -use crate::contract::Bind; +use crate::buttons::Button; +use crate::contract::{Bind, Show as _}; use crate::dialog::StackDialog as _; use crate::dialog::stories::hosted_with; use crate::patterns::form_dialogs::{DialogFields, Param, ParamKind}; @@ -117,7 +118,7 @@ fn hosted_param_dialog_with_a_refused_ok(ui: &mut Ui, data: &mut StoryData) -> S /// The open state of a story's dialog, which starts closed: a button opens it. fn opener<'d>(ui: &mut Ui, data: &'d mut StoryData) -> &'d mut bool { let open = data.value("open", false); - if ui.button("Open").clicked() { + if crate::contract::clicked(&Button::new("Open").show(ui)) { *open = true; } open diff --git a/crates/ui-widgets/src/list/view.rs b/crates/ui-widgets/src/list/view.rs index 74ba94f56..99a472a36 100644 --- a/crates/ui-widgets/src/list/view.rs +++ b/crates/ui-widgets/src/list/view.rs @@ -7,7 +7,7 @@ use super::predicate::{DropTest, RowTest, RowText}; use super::{ListRow, RowEvent}; use crate::contract::{ Access, ActivateOn, Bind, BindMut, Collection, CollectionProps, CollectionResponse, ColumnLayout, Common, Component, ContainerProps, Cx, - DropKind, EdgePress, EditResponse, HoverLead, LeadOnOpen, ListDrag, Props as _, Role, RowState, SelectMode, Sizing, + DropKind, EdgePress, EditResponse, HoverLead, LeadOnOpen, ListDrag, Props as _, Role, RowState, SelectMode, Show as _, Sizing, }; use crate::runtime::env::{Env, Label}; use crate::style::{ComponentStyle, StyleCx}; @@ -279,7 +279,7 @@ impl Collection for List<'_, K> { } fn rename_editor(&mut self, ui: &mut Ui, draft: Bind<'_, String>, label: Rect, name: &str) -> Option> { - Some(crate::text::rename_field(ui, draft, label, name)) + Some(crate::text::rename_field(draft, name).show_at(ui, label)) } } diff --git a/crates/ui-widgets/src/list/view_stories.rs b/crates/ui-widgets/src/list/view_stories.rs index e076ec620..162b3a30e 100644 --- a/crates/ui-widgets/src/list/view_stories.rs +++ b/crates/ui-widgets/src/list/view_stories.rs @@ -7,8 +7,8 @@ use super::{ }; use crate::buttons::Button; use crate::contract::{ - Bind, CollectionEvent, ColumnSpec, Entry, Outcome as _, ScrollAnchor, Show as _, ShowCollection as _, ShowContainer as _, ToggleColumn, - ToggleEdit, WordSetCx as _, request_rename, + Bind, CollectionEvent, ColumnSpec, Entry, ScrollAnchor, Show as _, ShowCollection as _, ShowContainer as _, ToggleColumn, ToggleEdit, + WordSetCx as _, request_rename, }; use crate::layout_components::Stack; use crate::menu::Menu; @@ -629,7 +629,7 @@ fn list_follows_end(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { let count = data.value("count", 12_usize); let mut shown = StoryOutput::default(); Stack::new().show(ui, |ui, _| { - if Button::new("Add a row").show(ui).response().clicked() { + if crate::contract::clicked(&Button::new("Add a row").show(ui)) { *count += 1; } let names = names(*count); diff --git a/crates/ui-widgets/src/table/view.rs b/crates/ui-widgets/src/table/view.rs index b5ea1e546..f7423c423 100644 --- a/crates/ui-widgets/src/table/view.rs +++ b/crates/ui-widgets/src/table/view.rs @@ -247,7 +247,7 @@ impl Collection for Table<'_, K> { } fn rename_editor(&mut self, ui: &mut Ui, draft: Bind<'_, String>, label: Rect, name: &str) -> Option> { - Some(crate::text::rename_field(ui, draft, label, name)) + Some(crate::text::rename_field(draft, name).show_at(ui, label)) } fn hosts_header(&self, column: &ColumnKey) -> bool { diff --git a/crates/ui-widgets/src/text/mod.rs b/crates/ui-widgets/src/text/mod.rs index 1f17e7d52..7d548e6b1 100644 --- a/crates/ui-widgets/src/text/mod.rs +++ b/crates/ui-widgets/src/text/mod.rs @@ -25,7 +25,7 @@ pub use text_field::TextField; pub use words::TextWords; pub use zoom_field::{InvalidZoom, ZoomField, ZoomFieldOutput}; -use crate::contract::{Bind, EditResponse}; +use crate::contract::Bind; use crate::primitives::TextKey; use crate::style::{ComponentStyle, IconLook, Ink, StyleCx, SurfaceLook}; use craft_behavior::{Insets, Metrics, PartKey}; @@ -122,7 +122,6 @@ fn text_part() -> TextKey { /// The text field every collection's `rename_editor` and the canvas `Pasteboard`'s page-name rename show over a label: /// it selects the name on focus, so typing replaces it. -pub fn rename_field(ui: &mut egui::Ui, draft: Bind<'_, String>, label: egui::Rect, name: &str) -> EditResponse { - use crate::contract::Show as _; - TextField::new(name.to_owned(), draft).select_on_focus().show_at(ui, label) +pub fn rename_field<'a>(draft: Bind<'a, String>, name: &str) -> TextField<'a> { + TextField::new(name.to_owned(), draft).select_on_focus() } diff --git a/crates/ui-widgets/src/text/number.rs b/crates/ui-widgets/src/text/number.rs index b09a2d65d..042fd065e 100644 --- a/crates/ui-widgets/src/text/number.rs +++ b/crates/ui-widgets/src/text/number.rs @@ -175,7 +175,7 @@ pub struct NumberField<'a, V: NumberValue + 'static = Option> { fixed_decimals: Option, /// The number the held name stands for: while the value is a name, the field shows this number in parentheses in /// place of the name's label; the presets row keeps the label. - #[prop] + #[prop(quantity = "field value")] #[allow(dead_code)] // PLAN: `Ruled::format`'s named arm (rule.rs, appearance-w3) must show this number; the field passes it on once `Ruled` carries it name_number: Option, diff --git a/crates/ui-widgets/src/tile_grid/grid.rs b/crates/ui-widgets/src/tile_grid/grid.rs index 1cf15fa15..373e1741c 100644 --- a/crates/ui-widgets/src/tile_grid/grid.rs +++ b/crates/ui-widgets/src/tile_grid/grid.rs @@ -15,7 +15,7 @@ use super::{CaptionPlace, CardText, Tile, TilePartEvent, ZoomStep}; use crate::contract::{ Access, Bind, BindMut, Collection, CollectionEvent, CollectionProps, CollectionResponse, ColumnKind, ColumnSpec, Common, Component, ContainerProps, Cx, DropKind, EditResponse, Focus as _, ListDrag, Meta as _, NoValue, Notch, Outcome, PaintUi, PartsCx, Pointer as _, Props as _, - Role, RowHeight, RowState, SelectMode, Sizing, SpaceAction, SweepApply, SweepStep, ToggleColumn, section_part, + Role, RowHeight, RowState, SelectMode, Show as _, Sizing, SpaceAction, SweepApply, SweepStep, ToggleColumn, section_part, }; use crate::controls::disclosure::Disclosure; use crate::list::{DropTest, ListRow, ListRowStyle, RowTest, ThumbSize}; @@ -906,6 +906,6 @@ impl Collection for TileGrid<'_, K } fn rename_editor(&mut self, ui: &mut Ui, draft: Bind<'_, String>, label: Rect, name: &str) -> Option> { - Some(crate::text::rename_field(ui, draft, label, name)) + Some(crate::text::rename_field(draft, name).show_at(ui, label)) } }