diff --git a/crates/text/src/ui/character/rows.rs b/crates/text/src/ui/character/rows.rs index 3c9626069..ad4923142 100644 --- a/crates/text/src/ui/character/rows.rs +++ b/crates/text/src/ui/character/rows.rs @@ -391,10 +391,10 @@ const STROKE_SHARE: f32 = 0.2; #[derive(craft_ui::contract::MemoProps)] struct FontHeightGlyph(FontHeightReference); -static EM_BOX: FontHeightGlyph = FontHeightGlyph(FontHeightReference::EmBox); -static CAP_HEIGHT: FontHeightGlyph = FontHeightGlyph(FontHeightReference::CapHeight); -static X_HEIGHT: FontHeightGlyph = FontHeightGlyph(FontHeightReference::XHeight); -static ICF_BOX: FontHeightGlyph = FontHeightGlyph(FontHeightReference::IcfBox); +const EM_BOX: FontHeightGlyph = FontHeightGlyph(FontHeightReference::EmBox); +const CAP_HEIGHT: FontHeightGlyph = FontHeightGlyph(FontHeightReference::CapHeight); +const X_HEIGHT: FontHeightGlyph = FontHeightGlyph(FontHeightReference::XHeight); +const ICF_BOX: FontHeightGlyph = FontHeightGlyph(FontHeightReference::IcfBox); impl Glyph for FontHeightGlyph { fn paint(&self, painter: &Painter, tokens: &UiTokens, rect: Rect, color: Color32, _mirrored: bool) { @@ -408,11 +408,11 @@ impl Glyph for FontHeightGlyph { let boxed = |left: f32, top: f32, right: f32, bottom: f32| { Shape::closed_line([(left, top), (right, top), (right, bottom), (left, bottom)].map(at).to_vec(), stroke) }; - let line = |from: (f32, f32), to: (f32, f32)| Shape::line_segment([at(from), at(to)], stroke); + let segment = |from: (f32, f32), to: (f32, f32)| Shape::line_segment([at(from), at(to)], stroke); // A letter between a top guide and the baseline: the guide's height is what the value measures. - let guided = |top: f32| vec![line((0.1, top), (0.9, top)), line((0.1, 0.8), (0.9, 0.8)), line((0.5, top), (0.5, 0.8))]; + let guided = |top: f32| vec![segment((0.1, top), (0.9, top)), segment((0.1, 0.8), (0.9, 0.8)), segment((0.5, top), (0.5, 0.8))]; let shapes = match self.0 { - FontHeightReference::EmBox => vec![boxed(0.1, 0.1, 0.9, 0.9), line((0.1, 0.75), (0.9, 0.75))], + FontHeightReference::EmBox => vec![boxed(0.1, 0.1, 0.9, 0.9), segment((0.1, 0.75), (0.9, 0.75))], FontHeightReference::CapHeight => guided(0.2), FontHeightReference::XHeight => guided(0.45), FontHeightReference::IcfBox => vec![boxed(0.2, 0.2, 0.8, 0.8)], diff --git a/crates/ui-contract/src/primitives/face.rs b/crates/ui-contract/src/primitives/face.rs index 70567fc9d..8dbd08097 100644 --- a/crates/ui-contract/src/primitives/face.rs +++ b/crates/ui-contract/src/primitives/face.rs @@ -7,9 +7,11 @@ use std::hash::{Hash, Hasher}; use std::sync::Arc; /// The one host painter a value carries: two faces with one key are the same value. -#[derive(Clone)] +#[derive(Clone, crate::contract::MemoProps, craft_ui_macros::PlainData)] pub struct FacePaint { key: u64, + #[memo_props(covered_by = "key", reason = "the key names what the painter paints")] + #[plain_data(assume = "a face is replaced, never written: its painter is shared")] paint: Arc, Rect) + Send + Sync>, } @@ -44,16 +46,6 @@ impl Hash for FacePaint { } } -/// By its key: two faces with one key are the same value. -impl crate::contract::MemoProps for FacePaint { - fn key(&self, key: &mut crate::contract::MemoKey) { - crate::contract::MemoProps::key(&self.key, key); - } -} - -/// A face is replaced, never written: its painter is shared and its key names what it paints. -impl crate::contract::PlainData for FacePaint {} - impl fmt::Debug for FacePaint { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_tuple("FacePaint").field(&self.key).finish() diff --git a/crates/ui-patterns/src/patterns/presets/browser.rs b/crates/ui-patterns/src/patterns/presets/browser.rs index cefee84bb..8334c8d97 100644 --- a/crates/ui-patterns/src/patterns/presets/browser.rs +++ b/crates/ui-patterns/src/patterns/presets/browser.rs @@ -21,9 +21,9 @@ use super::words::PresetWords; use crate::bars::{Bar, BarKind}; use crate::choice::Segmented; use crate::contract::{ - Bind, BodyCx, CollectionEvent, DropAt, DropKind, DropMark, DropPayload, DropPlace, DropTarget, DropZone, Entry, ListDrag, MemoKey, MemoProps, - MemoView, OpenChange, Outbox, Pattern, Props, Rename, ReorderMove, ReorderRule, RowHeight, SelectMode, Show as _, ShowCollection as _, - ShowContainer as _, TooltipSpec, request_rename, + Bind, BodyCx, CollectionEvent, DropAt, DropKind, DropMark, DropPayload, DropPlace, DropTarget, DropZone, Entry, ListDrag, MemoProps, MemoView, + OpenChange, Outbox, Pattern, Props, Rename, ReorderMove, ReorderRule, RowHeight, SelectMode, Show as _, ShowCollection as _, ShowContainer as _, + TooltipSpec, request_rename, }; use crate::display::Divider; use crate::layout_components::Stack; @@ -800,7 +800,11 @@ impl PresetBrowser<'_, row_menu, drags, group_heads, - host: HostFns { tip: tip_painter.as_ref(), row_items: row_items.as_ref(), drops: &drops }, + host: (tip_painter.is_some() || row_items.is_some() || !drops.is_empty()).then(|| HostFns { + tip: tip_painter.as_ref(), + row_items: row_items.as_ref(), + drops: &drops, + }), empty: empty_text.clone(), sent: Outbox::new(&mut sent), }; @@ -861,24 +865,14 @@ impl PresetBrowser<'_, } /// The host's closures a run of the presets view calls: the tip painter, the row menu's rows and the drop targets. +#[derive(crate::contract::MemoProps)] +#[memo_props(every_pass = "a closure reads what it captured, which no key can feed")] struct HostFns<'p, 'a, K> { tip: Option<&'p TipFn<'a, K>>, row_items: Option<&'p RowItems<'a, K>>, drops: &'p [PresetDrop<'a, K>], } -/// A closure reads what it captured, which no key can feed: a view given one runs in every pass. Without them the view -/// keys on its plain props alone. -impl MemoProps for HostFns<'_, '_, K> { - fn key(&self, key: &mut MemoKey) { - let any = self.tip.is_some() || self.row_items.is_some() || !self.drops.is_empty(); - key.write(&[u8::from(any)]); - if any { - key.changes_every_pass(); - } - } -} - /// Every input of the browser's presets view: the source, the state the toolbar left (the open groups, the search, /// the view and the zoom), the host's selection, the row menu's target, the browser's plain settings and the host's /// closures, and an outbox for what a run reports. @@ -906,7 +900,8 @@ struct ListProps<'p, 'a, K: 'static> { row_menu: PresetRowMenu, drags: bool, group_heads: GroupHeads, - host: HostFns<'p, 'a, K>, + /// The host's closures; `None` without any, so the view keys on its plain props alone. + host: Option>, empty: Option