craft-ui: journal entries are data, comparable by call and arguments

`runtime::journal(ctx, args, again)` notes a registration as its arguments and a capture-free `again` (a function or
a closure without captures; a capture fails to compile). Two entries are equal when they come from the same `again`
with equal arguments, and `Debug` names the call and its arguments, so a replay can be compared with a real run.

The focus `Transcript` and the records it holds (`StopRec`, `ScopeRec`, `RowGroups`, `Stop`, `Group`, `KeyUse`,
`KeyRole`) derive `PartialEq`. The journal's argument types gain `PartialEq` or `Debug` where they lacked them;
`UiTokens` compares by its content key. The docking generics that journal drop spots require `PartialEq + Debug` of
the panel type.
This commit is contained in:
aiongg
2026-11-19 09:44:06 +00:00
parent 1e7aff5638
commit f9c149b497
25 changed files with 202 additions and 101 deletions
+1 -1
View File
@@ -8,7 +8,7 @@ use craft_host::target::Os;
use craft_keymap::{Chord, Key, Mods};
/// What the focused stop is, as far as the table's rows differ.
#[derive(Clone, Copy, Debug, Default)]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
#[non_exhaustive]
pub struct KeyRole {
/// A value control with a reset value and no text part: Delete resets it.
+1 -1
View File
@@ -137,7 +137,7 @@ impl Lazy {
let real = !sizing && !crate::runtime::measure::active(&ctx);
let owner = view.map(|view| view.owner);
// A run around this one that is replayed later keeps the child's entry.
replay::journal(&ctx, || move |ctx: &egui::Context| lazy::keep(ctx, owner, id));
replay::journal(&ctx, || (owner, id), |ctx, &(owner, id)| lazy::keep(ctx, owner, id));
if let Some(view) = view {
let at = |size: Vec2| {
let x = if rtl { available.max.x - size.x } else { available.min.x };
+12 -14
View File
@@ -113,7 +113,7 @@ impl<V> TextOutcome<V> {
/// A part as the sensing core registers it.
// F2-MERGE: F3 (`PartBuilder` adds tooltip and `pointer_only`)
#[derive(Clone, Debug)]
#[derive(Clone, Debug, PartialEq)]
pub(crate) struct PartDecl {
pub key: PartKey,
pub index: Option<u64>,
@@ -153,7 +153,7 @@ impl PartDecl {
}
/// One member's registration for this pass.
#[derive(Clone, Debug)]
#[derive(Clone, Debug, PartialEq)]
pub(crate) struct MemberDecl {
pub id: Id,
pub rect: Rect,
@@ -174,7 +174,7 @@ impl MemberDecl {
}
/// What a root registers at step 8: its id and rect.
#[derive(Clone, Copy, Debug)]
#[derive(Clone, Copy, Debug, PartialEq)]
struct RootInfo {
id: Id,
rect: Rect,
@@ -396,7 +396,7 @@ pub fn cancel_press_of(ctx: &Context, owner: Id) {
/// Records the transformed body's egui layer.
pub(crate) fn set_layer(ctx: &Context, arena: ArenaId, layer: Layer) {
crate::runtime::replay::journal(ctx, || move |ctx: &Context| set_layer(ctx, arena, layer));
crate::runtime::replay::journal(ctx, || (arena, layer), |ctx, &(arena, layer)| set_layer(ctx, arena, layer));
let pass_nr = pass::pass_nr(ctx, pass::current_viewport(ctx));
with_arena(ctx, arena, pass_nr, |state| state.layer = Some(layer));
}
@@ -408,7 +408,7 @@ pub(crate) fn set_layer(ctx: &Context, arena: ArenaId, layer: Layer) {
// names their shapes as the press winner.
/// What a root registers in its arena at step 8, kept for a replay.
#[derive(Clone)]
#[derive(Clone, Debug, PartialEq)]
struct RootRegistration {
info: RootInfo,
own: Vec<PartDecl>,
@@ -419,10 +419,11 @@ struct RootRegistration {
/// Notes a root's step-8 registration in the open records.
fn journal_root(ctx: &Context, arena: ArenaId, info: RootInfo, own: &[PartDecl], widgets: &[Id], (layer, sense): (Layer, Sense)) {
crate::runtime::replay::journal(ctx, || {
let registration = RootRegistration { info, own: own.to_vec(), widgets: widgets.to_vec(), layer, sense };
move |ctx: &Context| register_root_again(ctx, arena, registration.clone())
});
crate::runtime::replay::journal(
ctx,
|| (arena, RootRegistration { info, own: own.to_vec(), widgets: widgets.to_vec(), layer, sense }),
|ctx, (arena, registration)| register_root_again(ctx, *arena, registration.clone()),
);
}
/// A replayed root's step-8 registration: its own parts, rect, widgets, layer and sense, with no press run.
@@ -441,10 +442,7 @@ fn register_root_again(ctx: &Context, arena: ArenaId, registration: RootRegistra
/// Notes in the open records the members that joined `arena`, as they joined.
fn journal_join(ctx: &Context, arena: ArenaId, joined: &[MemberDecl]) {
crate::runtime::replay::journal(ctx, || {
let joined = joined.to_vec();
move |ctx: &Context| join_again(ctx, arena, joined.clone())
});
crate::runtime::replay::journal(ctx, || (arena, joined.to_vec()), |ctx, (arena, joined)| join_again(ctx, *arena, joined.clone()));
}
/// Replayed members join their arena again.
@@ -463,7 +461,7 @@ fn join_again(ctx: &Context, arena: ArenaId, joined: Vec<MemberDecl>) {
/// Places the `over` parts of the root of `arena` (`member` None) or of its member `member` above the members joined
/// so far, as `place_over_widgets` does; journaled for a replay.
fn place_over(ctx: &Context, arena: ArenaId, member: Option<Id>) {
crate::runtime::replay::journal(ctx, || move |ctx: &Context| place_over(ctx, arena, member));
crate::runtime::replay::journal(ctx, || (arena, member), |ctx, &(arena, member)| place_over(ctx, arena, member));
let pass_nr = pass::pass_nr(ctx, pass::current_viewport(ctx));
with_arena(ctx, arena, pass_nr, |state| {
rotate(state, pass_nr);
@@ -696,7 +696,7 @@ pub(crate) fn register_instance(ctx: &Context, scope: CommandScope, id: Id) {
/// `register_instance` in the layer `layer`, which a replay of the registration keeps.
fn register_in(ctx: &Context, scope: CommandScope, id: Id, layer: Option<Id>) {
crate::runtime::replay::journal(ctx, || move |ctx: &Context| register_in(ctx, scope, id, layer));
crate::runtime::replay::journal(ctx, || (scope, id, layer), |ctx, &(scope, id, layer)| register_in(ctx, scope, id, layer));
let viewport = pass::current_viewport(ctx);
let stamp = pass::pass_nr(ctx, viewport);
with(ctx, |board| match board.instances.iter_mut().find(|i| i.id == id) {
@@ -1019,10 +1019,11 @@ pub(crate) fn publish(ctx: &Context, chain: &CommandChain, command: &CommandRef,
if !measure::effect(ctx, "commands::publish") {
return;
}
replay::journal(ctx, || {
let (chain, command, state) = (chain.clone(), command.clone(), state.clone());
move |ctx: &Context| publish(ctx, &chain, &command, state.clone())
});
replay::journal(
ctx,
|| (chain.clone(), command.clone(), state.clone()),
|ctx, (chain, command, state)| publish(ctx, chain, command, state.clone()),
);
let changed = with(ctx, |board| {
let scope = board.scope_of(command);
let declared = board.def(&command.id).is_some_and(|def| def.modal == ModalRule::Declared);
@@ -341,7 +341,7 @@ impl CommandInput {
/// The chain of container instances that receive scoped commands, innermost last. A private inherited field of
/// the env.
#[doc(hidden)]
#[derive(Clone, Default, PartialEq, Eq)]
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct CommandChain(Arc<[(CommandScope, Id)]>);
impl CommandChain {
+5 -4
View File
@@ -505,10 +505,11 @@ pub(crate) fn show_mark(ctx: &Context, mark: Option<DropMark>) {
/// Records that `owner`'s `ordinal`th target on `layer` accepts at the pointer, with its mark in layer space and the
/// tokens of the target's region. A `window` target covers the whole window.
pub(crate) fn register(ctx: &Context, owner: Id, layer: Layer, mark: DropMark, tokens: Arc<UiTokens>, window: bool) {
crate::runtime::replay::journal(ctx, || {
let tokens = tokens.clone();
move |ctx: &Context| register(ctx, owner, layer, mark, tokens.clone(), window)
});
crate::runtime::replay::journal(
ctx,
|| (owner, layer, mark, tokens.clone(), window),
|ctx, (owner, layer, mark, tokens, window)| register(ctx, *owner, *layer, *mark, tokens.clone(), *window),
);
let mark = match areas::layer_map(ctx, layer) {
Some(map) => mark.mapped(|point| map.to_screen(point)),
None => mark,
@@ -139,7 +139,7 @@ pub(crate) fn register_parent(ctx: &Context, id: Id, parent: Id) {
/// Notes that the runtime emitted the node of `id`.
fn emit(ctx: &Context, id: Id) {
with_emitted(ctx, |emitted| emitted.emit(id));
crate::runtime::replay::journal(ctx, || move |ctx: &Context| emit(ctx, id));
crate::runtime::replay::journal(ctx, || id, |ctx, &id| emit(ctx, id));
}
/// Notes that the node of the text widget `widget` folds into the node of `owner`.
@@ -147,7 +147,7 @@ fn note_folded(ctx: &Context, widget: Id, owner: Id) {
with_emitted(ctx, |emitted| {
emitted.folded.insert(widget, owner);
});
crate::runtime::replay::journal(ctx, || move |ctx: &Context| note_folded(ctx, widget, owner));
crate::runtime::replay::journal(ctx, || (widget, owner), |ctx, &(widget, owner)| note_folded(ctx, widget, owner));
}
/// Notes that the runtime wrote the node of `id`.
@@ -155,7 +155,7 @@ pub(crate) fn note_written(ctx: &Context, id: Id) {
with_emitted(ctx, |emitted| {
emitted.written.insert(id);
});
crate::runtime::replay::journal(ctx, || move |ctx: &Context| note_written(ctx, id));
crate::runtime::replay::journal(ctx, || id, |ctx, &id| note_written(ctx, id));
}
/// The pass-end step: the children of each node the runtime wrote follow the order the runtime emitted them in,
+5 -5
View File
@@ -42,7 +42,7 @@ pub enum FocusShape {
pub(crate) type StopKey = (Id, Option<PartRef>);
/// A registered stop with its place in the scope tree.
#[derive(Clone, Debug)]
#[derive(Clone, Debug, PartialEq, Eq)]
#[doc(hidden)]
pub struct StopRec {
#[doc(hidden)]
@@ -50,7 +50,7 @@ pub struct StopRec {
pub(crate) scope: Option<Id>,
}
#[derive(Clone, Debug)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub(crate) struct ScopeRec {
pub(crate) policy: FocusPolicy,
pub(crate) parent: Option<Id>,
@@ -116,7 +116,7 @@ pub(crate) struct BeginIn {
/// The row groups of one collection's visible rows in a pass: every one is a flat roving group of the same owner
/// and direction, so the collection registers them as one record.
#[derive(Clone)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub(crate) struct RowGroups {
owner: Id,
rtl: bool,
@@ -261,7 +261,7 @@ pub(crate) struct Mark {
/// What one run of a child registered with the focus service: its stops, the scopes it pushed, the roving groups
/// its stops belong to and its collections' row groups. A child out of view registers it again without running
/// (`runtime::lazy`), so its stops keep their place in Tab and F6 order.
#[derive(Clone, Default)]
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub(crate) struct Transcript {
stops: Vec<StopRec>,
scopes: Vec<(Id, ScopeRec)>,
@@ -431,7 +431,7 @@ pub(crate) fn pop_scope(ctx: &Context) {
/// Registers that the menu bar `bar` takes the menu-bar keys of the next input hook (spec 9.7). A settled bar
/// registers again when it replays its last run, and the keys it takes run it (`keys::routed_to`).
pub(crate) fn register_menu_bar(ctx: &Context, bar: Id) {
crate::runtime::replay::journal(ctx, || move |ctx: &Context| register_menu_bar(ctx, bar));
crate::runtime::replay::journal(ctx, || bar, |ctx, &bar| register_menu_bar(ctx, bar));
with(ctx, |state| state.menu_bar = Some(bar));
}
@@ -250,7 +250,7 @@ pub enum EndKey {
}
/// A component's declared keys.
#[derive(Clone, Copy, Debug)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct KeyUse {
/// The keys kept from the key stage.
@@ -8,7 +8,7 @@ use craft_behavior::{KeyRole, PartRef};
use egui::{Context, Id};
/// A stop as registered at step 7 of the pipeline.
#[derive(Clone, Debug)]
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct Stop {
/// The component.
@@ -124,7 +124,7 @@ impl Stop {
}
/// A roving group's registration: one Tab stop whose members take moves.
#[derive(Clone, Copy, Debug)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct Group {
/// The group.
+7 -3
View File
@@ -10,7 +10,7 @@ use egui::{Context, Id};
pub(crate) fn redirect_node(ctx: &Context, node: Id, owner: Id, part: PartRef) {
// Journaled after the `register_node` it amends, so a settled region's replay leaves the row's node with the
// collection, as a run does.
crate::runtime::replay::journal(ctx, || move |ctx: &Context| redirect_node(ctx, node, owner, part));
crate::runtime::replay::journal(ctx, || (node, owner, part), |ctx, &(node, owner, part)| redirect_node(ctx, node, owner, part));
current(ctx, |stage| {
if let Some(entry) = stage.nodes.get_mut(&node_key(node)) {
entry.owner = owner;
@@ -22,7 +22,7 @@ pub(crate) fn redirect_node(ctx: &Context, node: Id, owner: Id, part: PartRef) {
/// Records the expanded state of the node registered by `register_node`: an `Expand` or `Collapse` request on a node
/// with the state asks to change it, and acts as the node's activation.
pub(crate) fn register_expanded(ctx: &Context, node: Id, expanded: Option<bool>) {
crate::runtime::replay::journal(ctx, || move |ctx: &Context| register_expanded(ctx, node, expanded));
crate::runtime::replay::journal(ctx, || (node, expanded), |ctx, &(node, expanded)| register_expanded(ctx, node, expanded));
current(ctx, |stage| {
if let Some(entry) = stage.nodes.get_mut(&node_key(node)) {
entry.expanded = expanded;
@@ -32,7 +32,11 @@ pub(crate) fn register_expanded(ctx: &Context, node: Id, expanded: Option<bool>)
/// Registers an AccessKit node so a request that targets it reaches `owner`.
pub(crate) fn register_node(ctx: &Context, node: Id, owner: Id, part: Option<PartRef>, focusable: bool) {
crate::runtime::replay::journal(ctx, || move |ctx: &Context| register_node(ctx, node, owner, part, focusable));
crate::runtime::replay::journal(
ctx,
|| (node, owner, part, focusable),
|ctx, &(node, owner, part, focusable)| register_node(ctx, node, owner, part, focusable),
);
current(ctx, |stage| {
stage.nodes.insert(node_key(node), Node { owner, part, focusable, expanded: None });
});
@@ -1117,19 +1117,21 @@ pub(crate) fn ask_discard(ctx: &Context) {
/// Notes in the run records open around the running code that a replay keeps the entry and the kept transcript of
/// `id`: the replayed run does not reach them, and an entry no pass touched in a frame is dropped.
fn journal_keep(ctx: &Context, id: Id) {
crate::runtime::replay::journal(ctx, || {
move |ctx: &Context| {
crate::runtime::replay::journal(
ctx,
|| id,
|ctx, id| {
let moment = Moment::of(ctx);
with(ctx, &moment, |memory| {
if let Some(entry) = memory.entries.get_mut(&id) {
if let Some(entry) = memory.entries.get_mut(id) {
entry.touched = moment.frame;
}
if let Some(kept) = memory.kept.get_mut(&id) {
if let Some(kept) = memory.kept.get_mut(id) {
kept.touched = moment.frame;
}
});
}
});
},
);
}
/// The end hook: asks egui for at most one discard pass per frame, and for a repaint when a change cannot get one, so
+1 -1
View File
@@ -230,7 +230,7 @@ struct Seen(u64);
/// Registers `owner`'s pass, at step 3: eviction tests only owners. Shown entries of an owner not registered
/// for 3 passes of the viewport that last showed it and 0.5 s are evicted by `evict`.
pub(crate) fn register_owner(ctx: &Context, owner: Id) {
crate::runtime::replay::journal(ctx, || move |ctx: &Context| register_owner(ctx, owner));
crate::runtime::replay::journal(ctx, || owner, |ctx, &owner| register_owner(ctx, owner));
let facts = frame::facts(ctx);
pass_state::with::<Registry, _>(ctx, |reg| {
reg.owners.insert(owner, OwnerRecord { viewport: facts.viewport, pass: facts.pass_nr, at: facts.now });
+12 -10
View File
@@ -369,10 +369,11 @@ pub(crate) fn record_shapes(ctx: &Context, layer: Layer, root: Id, clip: Rect, s
/// `record_shapes` for a caller that already read the running viewport.
pub(crate) fn record_shapes_in(ctx: &Context, viewport: ViewportId, layer: Layer, root: Id, clip: Rect, shapes: impl IntoIterator<Item = Shape<Id>>) {
let shapes: Vec<Shape<Id>> = shapes.into_iter().collect();
crate::runtime::replay::journal(ctx, || {
let shapes = shapes.clone();
move |ctx: &Context| record_shapes(ctx, layer, root, clip, shapes.iter().cloned())
});
crate::runtime::replay::journal(
ctx,
|| (layer, root, clip, shapes.clone()),
|ctx, (layer, root, clip, shapes)| record_shapes(ctx, *layer, *root, *clip, shapes.iter().cloned()),
);
PerViewport::<Shapes>::with(ctx, viewport, |record| {
let order = record.next;
record.next += 1;
@@ -385,7 +386,7 @@ pub(crate) fn record_shapes_in(ctx: &Context, viewport: ViewportId, layer: Layer
/// Records the egui widget `widget` that the component `owner` made for its own text (a field's text, a selection
/// part): a press egui gives it is the widget's own and goes to no root, and the hover goes to `owner`.
pub(crate) fn record_text_widget(ctx: &Context, widget: Id, owner: Id) {
crate::runtime::replay::journal(ctx, || move |ctx: &Context| record_text_widget(ctx, widget, owner));
crate::runtime::replay::journal(ctx, || (widget, owner), |ctx, &(widget, owner)| record_text_widget(ctx, widget, owner));
PerViewport::<Shapes>::with(ctx, pass::current_viewport(ctx), |record| {
record.this_texts.insert(widget, owner);
});
@@ -403,7 +404,7 @@ pub(crate) fn record_layer_widget(ctx: &Context, widget: Id) {
/// Records that `layer` shows the transformed body of the root `root`, which is itself shown on `parent`: a press on
/// the body layer reaches the root's own shapes beneath the body's.
pub(crate) fn record_body_layer(ctx: &Context, layer: Layer, parent: Layer, root: Id) {
crate::runtime::replay::journal(ctx, || move |ctx: &Context| record_body_layer(ctx, layer, parent, root));
crate::runtime::replay::journal(ctx, || (layer, parent, root), |ctx, &(layer, parent, root)| record_body_layer(ctx, layer, parent, root));
PerViewport::<Shapes>::with(ctx, pass::current_viewport(ctx), |record| {
record.this_bodies.insert(layer, (root, parent));
});
@@ -417,10 +418,11 @@ pub(crate) fn record_widgets(ctx: &Context, layer: Layer, root: Id, widgets: &[I
/// `record_widgets` for a caller that already read the running viewport.
pub(crate) fn record_widgets_in(ctx: &Context, viewport: ViewportId, layer: Layer, root: Id, widgets: &[Id], click: bool) {
crate::runtime::replay::journal(ctx, || {
let widgets = widgets.to_vec();
move |ctx: &Context| record_widgets(ctx, layer, root, &widgets, click)
});
crate::runtime::replay::journal(
ctx,
|| (layer, root, widgets.to_vec(), click),
|ctx, (layer, root, widgets, click)| record_widgets(ctx, *layer, *root, widgets, *click),
);
PerViewport::<Shapes>::with(ctx, viewport, |record| {
let entry = record.this.entry(layer).or_default().entry(root).or_default();
entry.widgets.extend_from_slice(widgets);
+2 -5
View File
@@ -35,7 +35,7 @@ pub(crate) struct Sample {
pub took: Vec2,
}
#[derive(Clone, Debug)]
#[derive(Clone, Debug, PartialEq)]
struct Read {
key: BindKey,
reader: Id,
@@ -94,10 +94,7 @@ pub(crate) fn note(ctx: &Context, key: BindKey, reader: Id, measuring: bool, sam
} else {
let read = Read { key, reader, measuring, runs, samples };
crate::runtime::replay::note_read(ctx, key);
crate::runtime::replay::journal(ctx, || {
let read = read.clone();
move |ctx: &Context| with(ctx, |reads| reads.reads.push(read.clone()))
});
crate::runtime::replay::journal(ctx, || read.clone(), |ctx, read| with(ctx, |reads| reads.reads.push(read.clone())));
with(ctx, |reads| reads.reads.push(read));
}
}
+68 -9
View File
@@ -16,12 +16,63 @@ use crate::runtime::frame;
use crate::runtime::pass_state;
use crate::runtime::reads::BindKey;
use egui::{Context, IdSet};
use std::any::Any;
use std::collections::HashSet;
use std::fmt;
use std::sync::Arc;
use std::sync::atomic::{AtomicUsize, Ordering};
/// A registration of the recorded run, made again by calling it.
type Entry = Arc<dyn Fn(&Context) + Send + Sync>;
/// A registration of the recorded run: the call that makes it again and what it is called with. Two entries are equal
/// when they come from the same call (the same `again` of [`journal`]) with equal arguments.
#[derive(Clone)]
pub(crate) struct Entry(Arc<dyn Noted>);
trait Noted: Send + Sync {
fn call(&self, ctx: &Context);
fn as_any(&self) -> &dyn Any;
fn same(&self, other: &dyn Noted) -> bool;
fn describe(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result;
}
struct Note<A, F> {
args: A,
again: F,
}
impl<A, F> Noted for Note<A, F>
where
A: PartialEq + fmt::Debug + Send + Sync + 'static,
F: Fn(&Context, &A) + Send + Sync + 'static,
{
fn call(&self, ctx: &Context) {
(self.again)(ctx, &self.args);
}
fn as_any(&self) -> &dyn Any {
self
}
fn same(&self, other: &dyn Noted) -> bool {
// `F` is capture-free, so its type names the call: the same type is the same call.
other.as_any().downcast_ref::<Self>().is_some_and(|other| other.args == self.args)
}
fn describe(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}({:?})", std::any::type_name::<F>(), self.args)
}
}
impl PartialEq for Entry {
fn eq(&self, other: &Self) -> bool {
self.0.same(&*other.0)
}
}
impl fmt::Debug for Entry {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.describe(f)
}
}
/// Records open across all contexts, so a registration made while none is open takes no lock.
static OPEN: AtomicUsize = AtomicUsize::new(0);
@@ -68,7 +119,7 @@ pub(crate) struct Facts {
/// What one real run of a region added to its pass.
pub(crate) struct Record {
pub(crate) focus: Transcript,
journal: Vec<Entry>,
pub(crate) journal: Vec<Entry>,
egui: egui::PassRecords,
/// The egui widgets of the run.
pub(crate) widgets: IdSet,
@@ -136,7 +187,7 @@ pub(crate) fn replay(ctx: &Context, record: &Record) {
ctx.replay_pass_records(&record.egui);
focus::replay(ctx, &record.focus);
for entry in &record.journal {
entry(ctx);
entry.0.call(ctx);
}
if let Some(at) = record.facts.wake {
crate::runtime::egui::repaint::request_after(ctx, crate::runtime::egui::pass::current_viewport(ctx), at - frame::clock(ctx));
@@ -160,12 +211,20 @@ fn with_open(ctx: &Context, f: impl FnOnce(&mut Facts)) {
}
}
/// Notes, in the records open around the running code, the registration `make` builds: called again, it registers
/// what the running code registered. A service outside this crate that keeps registrations per pass (a dock's drop
/// spots) notes each one here, so a settled region's replay makes it again.
pub fn journal<F: Fn(&Context) + Send + Sync + 'static>(ctx: &Context, make: impl FnOnce() -> F) {
/// Notes, in the records open around the running code, the registration the running code made: `again(ctx, &args)`
/// registers it again. `args` builds the arguments only while a record is open. `again` captures nothing (a function
/// or a closure without captures; a capture does not compile), so everything the registration depends on is in the
/// arguments, and two notes of the same `again` with equal arguments are the same registration. A service outside
/// this crate that keeps registrations per pass (a dock's drop spots) notes each one here, so a settled region's replay
/// makes it again.
pub fn journal<A, F>(ctx: &Context, args: impl FnOnce() -> A, again: F)
where
A: PartialEq + fmt::Debug + Send + Sync + 'static,
F: Fn(&Context, &A) + Send + Sync + 'static,
{
const { assert!(std::mem::size_of::<F>() == 0, "`journal`'s `again` captures nothing: pass its state in `args`") };
if recording(ctx) {
let entry: Entry = Arc::new(make());
let entry = Entry(Arc::new(Note { args: args(), again }));
pass_state::with::<Recorder, _>(ctx, |recorder| recorder.journal.push(entry));
}
}
+1 -1
View File
@@ -25,7 +25,7 @@ pub(crate) struct State {
/// Registers a taker for next pass's split.
pub(crate) fn register(ctx: &Context, taker: WheelTaker<Id>) {
crate::runtime::replay::journal(ctx, || move |ctx: &Context| register(ctx, taker));
crate::runtime::replay::journal(ctx, || taker, |ctx, &taker| register(ctx, taker));
PerViewport::<State>::with(ctx, pass::current_viewport(ctx), |state| state.this.push(taker));
}
@@ -311,7 +311,7 @@ pub(super) fn with_exclusive<R>(ctx: &Context, viewport: ViewportId, f: impl FnO
/// A part declared again in the same pass replaces its entry. A settled region that replays its last run declares
/// its parts again, so a settled title bar keeps its caption regions.
pub(crate) fn note_exclusive(ctx: &Context, owner: Id, part: PartRef, hit: WindowHit, rect: Rect) {
crate::runtime::replay::journal(ctx, || move |ctx: &Context| note_exclusive(ctx, owner, part, hit, rect));
crate::runtime::replay::journal(ctx, || (owner, part, hit, rect), |ctx, &(owner, part, hit, rect)| note_exclusive(ctx, owner, part, hit, rect));
with_exclusive(ctx, pass::current_viewport(ctx), |exclusive| {
let entry = ExclusivePart { owner, part, hit, rect };
match exclusive.current.iter_mut().find(|held| held.owner == owner && held.part == part) {
+9
View File
@@ -42,6 +42,15 @@ pub struct UiTokens {
key: u64,
}
/// Two sets are equal when their content keys are: equal sets share a key.
impl PartialEq for UiTokens {
fn eq(&self, other: &Self) -> bool {
self.key == other.key
}
}
impl Eq for UiTokens {}
impl UiTokens {
/// A token set resolved under `contrast` and `density`, with no theme values for token groups, drawing the default
/// icon set.
+13 -5
View File
@@ -20,6 +20,7 @@ use craft_behavior::divider::{self as push, Segment};
use craft_behavior::dock::{Column, DockEdge, Group};
use craft_behavior::{Axis, DockSide, Flow, Metrics, PartKey, Sense, Value};
use egui::{Context, Id, Pos2, Rect, Response, Ui};
use std::fmt::Debug;
use std::hash::Hash;
#[cfg(feature = "testing")]
@@ -207,7 +208,7 @@ pub struct DockColumn<'a, P: Value + Hash + 'static> {
collapse: bool,
}
impl<'a, P: Value + Hash + 'static> DockColumn<'a, P> {
impl<'a, P: Value + Hash + Debug + 'static> DockColumn<'a, P> {
/// A column named `label` of the dock `dock`, over `column`; `spec` reads each panel's limits and heights.
pub fn new(label: impl Into<Label>, dock: Id, column: &'a Column<P>, spec: &'a dyn Fn(&P) -> PanelSpec) -> Self {
let props = ContainerProps::new().sizing(Sizing::Fill).pad(Pad::None);
@@ -386,7 +387,7 @@ impl Plan {
}
}
impl<P: Value + Hash + 'static> Component for DockColumn<'_, P> {
impl<P: Value + Debug + Hash + 'static> Component for DockColumn<'_, P> {
const ROLE: Role = Role::GROUP;
const KEYS: KeyUse = KeyUse::SPLITTER;
type Style = DockColumnStyle;
@@ -531,7 +532,14 @@ pub(super) fn column_grip<P: Value + Hash>(column: &Column<P>, spec: &dyn Fn(&P)
/// Registers the drop bands of the two edges of the column in `rect` with the dock `dock`: a drop there makes a new
/// column beside the one that holds `anchor`.
pub(super) fn register_edges<P: Clone + Send + Sync + 'static>(ctx: &Context, dock: Id, anchor: &P, rect: Rect, rtl: bool, sizes: &DockSizes) {
pub(super) fn register_edges<P: Clone + Send + Sync + PartialEq + Debug + 'static>(
ctx: &Context,
dock: Id,
anchor: &P,
rect: Rect,
rtl: bool,
sizes: &DockSizes,
) {
let flow = Flow::new(rect, rtl);
// A narrow column keeps a third of its width between its two edge bands, so a drop inside it still reaches its
// groups.
@@ -550,7 +558,7 @@ pub(super) fn register_edges<P: Clone + Send + Sync + 'static>(ctx: &Context, do
}
}
impl<P: Value + Hash + 'static> DockColumn<'_, P> {
impl<P: Value + Debug + Hash + 'static> DockColumn<'_, P> {
/// Registers the drop bands of the column's two edges, for a dock column, and of the seams between its groups.
fn register(&self, ctx: &Context, rect: Rect, rtl: bool, plan: &Plan, sizes: &DockSizes) {
let Some(first) = self.anchor(0) else { return };
@@ -568,4 +576,4 @@ impl<P: Value + Hash + 'static> DockColumn<'_, P> {
}
}
impl<P: Value + Hash + 'static> Container for DockColumn<'_, P> {}
impl<P: Value + Hash + Debug + 'static> Container for DockColumn<'_, P> {}
+2 -1
View File
@@ -9,6 +9,7 @@ use craft_behavior::dock::{Column, Floating, Group, Layout, Node, PanelPlace, Sp
use egui::{Context, Id, Pos2, Rect, Vec2};
use std::borrow::Cow;
use std::collections::HashMap;
use std::fmt::Debug;
use std::hash::Hash;
/// A layout as it is shown: a maximized frame alone, hidden panels left out.
@@ -251,7 +252,7 @@ pub fn edge_bands<P: Clone + Eq + Hash>(
/// Registers the bands as the dock's edge spots, for the next pass's drops; over a tab strip each reaches
/// `strip_reach` from its edge (`DockSizes::strip_reach`).
pub fn register_edge_bands<P: Clone + Send + Sync + 'static>(ctx: &Context, dock: Id, bands: &[EdgeBand], strip_reach: f32) {
pub fn register_edge_bands<P: Clone + PartialEq + Debug + Send + Sync + 'static>(ctx: &Context, dock: Id, bands: &[EdgeBand], strip_reach: f32) {
for band in bands {
DockTargets::<P>::register_band(ctx, dock, DockSpot::Edge(band.side), band.band, band.line, strip_reach);
}
+5 -4
View File
@@ -22,6 +22,7 @@ use craft_behavior::{DockSide, IconId, Metrics, PartKey, PressPhase, Sense, keye
use craft_theme::{ControlSize, Tokens};
use egui::{Id, Pos2, Rect, Response, Ui, Vec2};
use std::borrow::Cow;
use std::fmt::Debug;
use std::hash::Hash;
/// The style of a group grip: its size comes from the tokens.
@@ -265,7 +266,7 @@ pub struct DockGroup<'a, P: Clone + Hash + Send + Sync + 'static> {
reported: Reported,
}
impl<'a, P: Clone + Hash + Send + Sync + 'static> DockGroup<'a, P> {
impl<'a, P: Clone + Hash + Send + Sync + PartialEq + Debug + 'static> DockGroup<'a, P> {
/// The group named by `anchor` (one of its panels) with its `panels`, `active` showing. The group is named by the
/// active panel's title.
pub fn new(anchor: P, panels: &'a [PanelTitle], active: PanelKey) -> Self {
@@ -313,7 +314,7 @@ impl<'a, P: Clone + Hash + Send + Sync + 'static> DockGroup<'a, P> {
}
}
impl<P: Clone + Hash + Send + Sync + 'static> Component for DockGroup<'_, P> {
impl<P: Clone + PartialEq + Debug + Hash + Send + Sync + 'static> Component for DockGroup<'_, P> {
const ROLE: Role = Role::TAB_PANEL;
type Style = DockGroupStyle;
type Output = DockGroupOutput;
@@ -427,7 +428,7 @@ impl<P: Clone + Hash + Send + Sync + 'static> Component for DockGroup<'_, P> {
}
}
impl<P: Clone + Hash + Send + Sync + 'static> Container for DockGroup<'_, P> {
impl<P: Clone + Hash + Send + Sync + PartialEq + Debug + 'static> Container for DockGroup<'_, P> {
/// Closed while minimized: the body step runs the header alone, and the body leaves no node, shape or stop.
fn open(&mut self) -> Option<BindMut<'_, bool>> {
self.open = Bind::given(!self.minimized);
@@ -527,7 +528,7 @@ impl<P: Clone + Hash + Send + Sync + 'static> Container for DockGroup<'_, P> {
/// Registers the tab insertion spots of a group: the half of each shown tab nearer the start edge inserts before
/// it, the other half after it, and each spot's mark is the line at the boundary it inserts at.
fn register_insertions<P: Clone + Hash + Send + Sync + 'static>(
fn register_insertions<P: Clone + PartialEq + Debug + Hash + Send + Sync + 'static>(
ctx: &egui::Context,
dock: Id,
anchor: &P,
+5 -4
View File
@@ -24,6 +24,7 @@ use craft_behavior::overlay::Side;
use craft_behavior::{Axis, CursorIcon, DockSide, Metrics, PartKey, PressPhase, Sense, Value};
use craft_theme::ControlSize;
use egui::{Id, Pos2, Rect, Response, Ui, Vec2};
use std::fmt::Debug;
use std::hash::Hash;
#[cfg(feature = "testing")]
@@ -235,7 +236,7 @@ struct Plan {
body: Rect,
}
impl<'a, P: Value + Hash + 'static> IconicColumn<'a, P> {
impl<'a, P: Value + Hash + Debug + 'static> IconicColumn<'a, P> {
/// A column named `label` of the dock `dock`, over `column`, whose open flyout is the panel in `open`; `spec`
/// reads each panel's label, icon and limits.
pub fn new(label: impl Into<Label>, dock: Id, column: &'a Column<P>, open: Bind<'a, Option<P>>, spec: &'a dyn Fn(&P) -> PanelSpec) -> Self {
@@ -388,7 +389,7 @@ impl<'a, P: Value + Hash + 'static> IconicColumn<'a, P> {
/// What measures and shows the group of an open flyout.
type FlyoutView<'a, P> = Box<dyn FnMut(&Group<P>, GroupAt, &mut Ui, &mut BodyCx<'_>) -> Option<f32> + 'a>;
impl<P: Value + Hash + 'static> Component for IconicColumn<'_, P> {
impl<P: Value + Hash + Debug + 'static> Component for IconicColumn<'_, P> {
const ROLE: Role = Role::GROUP;
const KEYS: KeyUse = KeyUse::SPLITTER;
type Style = IconicColumnStyle;
@@ -635,7 +636,7 @@ impl<P: Value + Hash + 'static> Component for IconicColumn<'_, P> {
}
}
impl<P: Value + Hash + 'static> IconicColumn<'_, P> {
impl<P: Value + Debug + Hash + 'static> IconicColumn<'_, P> {
/// Registers the drop spots of the column the way an expanded column registers them: the bands of a dock
/// column's two edges (a new column beside it), the seam on the separator between two icon groups (a new group
/// between them), the top of the first group and the bottom of the last down to the column's foot (a new group
@@ -692,7 +693,7 @@ fn chevron_edge(edge: DockEdge) -> HeaderEdge {
if edge == DockEdge::End { HeaderEdge::End } else { HeaderEdge::Start }
}
impl<P: Value + Hash + 'static> Container for IconicColumn<'_, P> {
impl<P: Value + Hash + Debug + 'static> Container for IconicColumn<'_, P> {
/// The chevron's square at the bar's outer end; nothing in a floating window, whose title row is the bar.
fn header_parts(&self, cx: &MeasureCx<'_, Self>) -> HeaderParts {
if self.bar == ColumnBar::Window {
+25 -13
View File
@@ -11,6 +11,7 @@ use crate::style::StyleCx;
use craft_behavior::DockSide;
use craft_behavior::dock::{Action, Column, DockEdge, Layout, Node, ZoneSize, node_at, zones};
use egui::{Context, Id, Pos2, Rect, Vec2};
use std::fmt::Debug;
pub use craft_behavior::dock::{SIDE_ZONE_DEPTH_SHARE, SIDE_ZONE_FRACTION};
@@ -453,8 +454,9 @@ impl<P: Clone + Send + 'static> DockTargets<P> {
}
}
/// The registrations of a pass. A settled region's run record keeps each one to make it again, so the panel type is `Sync`.
impl<P: Clone + Send + Sync + 'static> DockTargets<P> {
/// The registrations of a pass. A settled region's run record keeps each one to make it again and compares it with a
/// real run's, so the panel type is `Sync`, `PartialEq` and `Debug`.
impl<P: Clone + PartialEq + Debug + Send + Sync + 'static> DockTargets<P> {
/// Registers `spot` over `rect` for the dock `dock` in the running pass of this viewport. Group and column
/// rendering call it; it does nothing outside a pass. A floating window registers on its own egui layer, and
/// the drag session orders the layers, so no registry orders them.
@@ -468,10 +470,13 @@ impl<P: Clone + Send + Sync + 'static> DockTargets<P> {
if !crate::runtime::measure::effect(ctx, "dock::register_target") {
return;
}
Self::journal(ctx, || {
let spot = spot.clone();
move |ctx: &Context| Self::register_in(ctx, dock, spot.clone(), hit, applies)
});
Self::journal(
ctx,
|| (dock, spot.clone(), hit, applies),
|ctx, (dock, spot, hit, applies)| {
Self::register_in(ctx, *dock, spot.clone(), *hit, *applies);
},
);
Self::with_dock(ctx, dock, |targets| targets.add(spot, hit, applies, hit));
}
@@ -482,10 +487,13 @@ impl<P: Clone + Send + Sync + 'static> DockTargets<P> {
if !crate::runtime::measure::effect(ctx, "dock::register_target") {
return;
}
Self::journal(ctx, || {
let spot = spot.clone();
move |ctx: &Context| Self::register_band(ctx, dock, spot.clone(), band, line, reach)
});
Self::journal(
ctx,
|| (dock, spot.clone(), band, line, reach),
|ctx, (dock, spot, band, line, reach)| {
Self::register_band(ctx, *dock, spot.clone(), *band, *line, *reach);
},
);
let near = line.expand(reach).intersect(band);
Self::with_dock(ctx, dock, |targets| targets.add(spot, band, band, near));
}
@@ -497,14 +505,18 @@ impl<P: Clone + Send + Sync + 'static> DockTargets<P> {
if !crate::runtime::measure::effect(ctx, "dock::register_room") {
return;
}
Self::journal(ctx, || move |ctx: &Context| Self::register_room(ctx, dock, room));
Self::journal(ctx, || (dock, room), |ctx, &(dock, room)| Self::register_room(ctx, dock, room));
Self::with_dock(ctx, dock, |targets| targets.room = Some(room));
}
/// Notes a registration in the records of the settling regions around the running code, so a region that settles
/// registers its drop spots again when it replays its last run.
fn journal<F: Fn(&Context) + Send + Sync + 'static>(ctx: &Context, make: impl FnOnce() -> F) {
crate::runtime::journal(ctx, make);
fn journal<A, F>(ctx: &Context, args: impl FnOnce() -> A, again: F)
where
A: PartialEq + Debug + Send + Sync + 'static,
F: Fn(&Context, &A) + Send + Sync + 'static,
{
crate::runtime::journal(ctx, args, again);
}
}
+6 -1
View File
@@ -673,7 +673,12 @@ fn show_area<P: Clone + Eq + Hash + Debug + Send + Sync + 'static>(
/// Registers the outer-edge bands and the new-dock bands as the dock's drop spots for the next pass, from the leaves
/// the split area placed this pass (each as its tree path and rect). A new-dock band runs along a start or end edge
/// that holds no dock.
fn register_bands<P: Clone + Eq + Hash + Send + Sync + 'static>(scene: &Scene<'_, P>, ctx: &Context, area: Rect, leaves: &[(Vec<bool>, Rect)]) {
fn register_bands<P: Clone + Eq + Hash + Send + Sync + Debug + 'static>(
scene: &Scene<'_, P>,
ctx: &Context,
area: Rect,
leaves: &[(Vec<bool>, Rect)],
) {
if scene.layout.root.is_none() {
return;
}