craft-ui: bind_tracked! binds a whole Tracked value; Selection, OpenSet and Level are plain data

This commit is contained in:
aiongg
2026-11-19 15:38:39 +00:00
parent 765c2ca9f7
commit d125e4e094
6 changed files with 21 additions and 6 deletions
Generated
+2
View File
@@ -2077,6 +2077,8 @@ dependencies = [
"craft-host",
"craft-keymap",
"craft-theme",
"craft-tracked",
"craft-ui-macros",
"emath",
"kurbo",
"serde",
+3
View File
@@ -21,6 +21,9 @@ bitflags = "2"
craft-host = { workspace = true }
craft-keymap = { workspace = true }
craft-theme = { workspace = true }
# Value types readers hold in `Tracked` derive its `PlainData` marker.
craft-tracked = { workspace = true }
craft-ui-macros = { workspace = true }
# The dock layout is a persisted shape.
serde = { workspace = true }
+1 -1
View File
@@ -193,7 +193,7 @@ pub trait SelectionModel<K>: Value + Default {
}
/// A set of keys with a lead and an anchor.
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq, craft_ui_macros::PlainData)]
#[non_exhaustive]
pub struct Selection<K> {
/// The selected keys.
+1 -1
View File
@@ -17,7 +17,7 @@ use super::{Probe, ShapeKind};
use std::collections::BTreeMap;
/// Where a type sits in the design system, in the order a viewer lists them.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, craft_ui_macros::PlainData)]
#[non_exhaustive]
pub enum Level {
/// Colours, the edit lifecycle, stock egui.
+13 -3
View File
@@ -743,9 +743,9 @@ pub(crate) enum Checked {
/// Write-through bindings to fields of a [`Tracked`](crate::contract::Tracked) value: `bind_tracked!(doc => size)`
/// gives one [`Bind`], `bind_tracked!(doc => title, style.size)` a tuple with one per field path (field names and
/// tuple indices only). Making and reading the bindings leaves the revision; an edit that changes a field moves it at
/// the write, so bindings made every pass don't invalidate the value's readers. Each binding borrows its own field,
/// so the paths must not overlap.
/// tuple indices only), and `bind_tracked!(name)` one binding to the whole value. Making and reading the bindings
/// leaves the revision; an edit that changes the bound value moves it at the write, so bindings made every pass don't
/// invalidate the value's readers. Each binding borrows its own field, so the paths must not overlap.
///
/// ```
/// # extern crate craft_ui_contract as craft_ui;
@@ -760,6 +760,12 @@ pub(crate) enum Checked {
/// let mut doc = Tracked::new(Doc { title: "a".into(), style: (12.0, false) });
/// let (title, size) = bind_tracked!(doc => title, style.0);
/// # let _ = (title, size);
///
/// let mut name = Tracked::new(String::from("a"));
/// let before = name.revision();
/// let whole = bind_tracked!(name);
/// # let _ = whole;
/// assert_eq!(name.revision(), before, "binding leaves the revision");
/// ```
///
/// Overlapping paths don't compile:
@@ -791,4 +797,8 @@ macro_rules! bind_tracked {
let (model, count) = $tracked.__split_for_bind();
($($crate::contract::Bind::__tracked(&mut model.$first $(.$rest)*, count),)+)
}};
($tracked:expr) => {{
let (model, count) = $tracked.__split_for_bind();
$crate::contract::Bind::__tracked(model, count)
}};
}
+1 -1
View File
@@ -5,7 +5,7 @@ use std::hash::Hash;
/// The groups of a tree that are open, for an app whose source reports `ItemSource::open` from it. Every group is
/// closed to begin with.
#[derive(Clone, Debug, PartialEq, Eq)]
#[derive(Clone, Debug, PartialEq, Eq, crate::contract::PlainData)]
pub struct OpenSet<K: Hash + Eq> {
open: HashSet<K>,
}