mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-25 20:22:39 +00:00
Merge pull request #2344 from aiongg/memo-records
Comparable replay records: journal entries, focus transcripts, egui pass records (#2336)
This commit is contained in:
Generated
+14
-14
@@ -5324,7 +5324,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "ecolor"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=e9711ca9b69772f875ae0d1cef1977ff8c16234d#e9711ca9b69772f875ae0d1cef1977ff8c16234d"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=7e1c30d142bc7879d043e74b5ceb3ecfe7f51329#7e1c30d142bc7879d043e74b5ceb3ecfe7f51329"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"emath",
|
||||
@@ -5380,7 +5380,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "eframe"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=e9711ca9b69772f875ae0d1cef1977ff8c16234d#e9711ca9b69772f875ae0d1cef1977ff8c16234d"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=7e1c30d142bc7879d043e74b5ceb3ecfe7f51329#7e1c30d142bc7879d043e74b5ceb3ecfe7f51329"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"bytemuck",
|
||||
@@ -5415,7 +5415,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "egui"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=e9711ca9b69772f875ae0d1cef1977ff8c16234d#e9711ca9b69772f875ae0d1cef1977ff8c16234d"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=7e1c30d142bc7879d043e74b5ceb3ecfe7f51329#7e1c30d142bc7879d043e74b5ceb3ecfe7f51329"
|
||||
dependencies = [
|
||||
"accesskit",
|
||||
"ahash",
|
||||
@@ -5434,7 +5434,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "egui-wgpu"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=e9711ca9b69772f875ae0d1cef1977ff8c16234d#e9711ca9b69772f875ae0d1cef1977ff8c16234d"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=7e1c30d142bc7879d043e74b5ceb3ecfe7f51329#7e1c30d142bc7879d043e74b5ceb3ecfe7f51329"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"bytemuck",
|
||||
@@ -5453,7 +5453,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "egui-winit"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=e9711ca9b69772f875ae0d1cef1977ff8c16234d#e9711ca9b69772f875ae0d1cef1977ff8c16234d"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=7e1c30d142bc7879d043e74b5ceb3ecfe7f51329#7e1c30d142bc7879d043e74b5ceb3ecfe7f51329"
|
||||
dependencies = [
|
||||
"block2 0.6.2",
|
||||
"bytemuck",
|
||||
@@ -5473,7 +5473,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "egui_glow"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=e9711ca9b69772f875ae0d1cef1977ff8c16234d#e9711ca9b69772f875ae0d1cef1977ff8c16234d"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=7e1c30d142bc7879d043e74b5ceb3ecfe7f51329#7e1c30d142bc7879d043e74b5ceb3ecfe7f51329"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"egui",
|
||||
@@ -5486,7 +5486,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "egui_kittest"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=e9711ca9b69772f875ae0d1cef1977ff8c16234d#e9711ca9b69772f875ae0d1cef1977ff8c16234d"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=7e1c30d142bc7879d043e74b5ceb3ecfe7f51329#7e1c30d142bc7879d043e74b5ceb3ecfe7f51329"
|
||||
dependencies = [
|
||||
"eframe",
|
||||
"egui",
|
||||
@@ -5563,7 +5563,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "emath"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=e9711ca9b69772f875ae0d1cef1977ff8c16234d#e9711ca9b69772f875ae0d1cef1977ff8c16234d"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=7e1c30d142bc7879d043e74b5ceb3ecfe7f51329#7e1c30d142bc7879d043e74b5ceb3ecfe7f51329"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
]
|
||||
@@ -5636,7 +5636,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "epaint"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=e9711ca9b69772f875ae0d1cef1977ff8c16234d#e9711ca9b69772f875ae0d1cef1977ff8c16234d"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=7e1c30d142bc7879d043e74b5ceb3ecfe7f51329#7e1c30d142bc7879d043e74b5ceb3ecfe7f51329"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"bytemuck",
|
||||
@@ -5662,7 +5662,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "epaint_default_fonts"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=e9711ca9b69772f875ae0d1cef1977ff8c16234d#e9711ca9b69772f875ae0d1cef1977ff8c16234d"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=7e1c30d142bc7879d043e74b5ceb3ecfe7f51329#7e1c30d142bc7879d043e74b5ceb3ecfe7f51329"
|
||||
|
||||
[[package]]
|
||||
name = "equator"
|
||||
@@ -14980,19 +14980,19 @@ dependencies = [
|
||||
[[patch.unused]]
|
||||
name = "egui_demo_lib"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=e9711ca9b69772f875ae0d1cef1977ff8c16234d#e9711ca9b69772f875ae0d1cef1977ff8c16234d"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=7e1c30d142bc7879d043e74b5ceb3ecfe7f51329#7e1c30d142bc7879d043e74b5ceb3ecfe7f51329"
|
||||
|
||||
[[patch.unused]]
|
||||
name = "egui_extras"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=e9711ca9b69772f875ae0d1cef1977ff8c16234d#e9711ca9b69772f875ae0d1cef1977ff8c16234d"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=7e1c30d142bc7879d043e74b5ceb3ecfe7f51329#7e1c30d142bc7879d043e74b5ceb3ecfe7f51329"
|
||||
|
||||
[[patch.unused]]
|
||||
name = "egui_inspection"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=e9711ca9b69772f875ae0d1cef1977ff8c16234d#e9711ca9b69772f875ae0d1cef1977ff8c16234d"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=7e1c30d142bc7879d043e74b5ceb3ecfe7f51329#7e1c30d142bc7879d043e74b5ceb3ecfe7f51329"
|
||||
|
||||
[[patch.unused]]
|
||||
name = "egui_system_font_provider"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=e9711ca9b69772f875ae0d1cef1977ff8c16234d#e9711ca9b69772f875ae0d1cef1977ff8c16234d"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=7e1c30d142bc7879d043e74b5ceb3ecfe7f51329#7e1c30d142bc7879d043e74b5ceb3ecfe7f51329"
|
||||
|
||||
+14
-14
@@ -294,20 +294,20 @@ hayro-jbig2 = { path = "vendor/hayro-jbig2" }
|
||||
hayro-cmap = { path = "vendor/hayro-cmap" }
|
||||
hayro-postscript = { path = "vendor/hayro-postscript" }
|
||||
linesweeper = { path = "vendor/linesweeper" }
|
||||
ecolor = { git = "https://github.com/storytold/egui.git", rev = "e9711ca9b69772f875ae0d1cef1977ff8c16234d" }
|
||||
emath = { git = "https://github.com/storytold/egui.git", rev = "e9711ca9b69772f875ae0d1cef1977ff8c16234d" }
|
||||
epaint = { git = "https://github.com/storytold/egui.git", rev = "e9711ca9b69772f875ae0d1cef1977ff8c16234d" }
|
||||
epaint_default_fonts = { git = "https://github.com/storytold/egui.git", rev = "e9711ca9b69772f875ae0d1cef1977ff8c16234d" }
|
||||
egui = { git = "https://github.com/storytold/egui.git", rev = "e9711ca9b69772f875ae0d1cef1977ff8c16234d" }
|
||||
egui-winit = { git = "https://github.com/storytold/egui.git", rev = "e9711ca9b69772f875ae0d1cef1977ff8c16234d" }
|
||||
egui-wgpu = { git = "https://github.com/storytold/egui.git", rev = "e9711ca9b69772f875ae0d1cef1977ff8c16234d" }
|
||||
egui_glow = { git = "https://github.com/storytold/egui.git", rev = "e9711ca9b69772f875ae0d1cef1977ff8c16234d" }
|
||||
egui_extras = { git = "https://github.com/storytold/egui.git", rev = "e9711ca9b69772f875ae0d1cef1977ff8c16234d" }
|
||||
egui_kittest = { git = "https://github.com/storytold/egui.git", rev = "e9711ca9b69772f875ae0d1cef1977ff8c16234d" }
|
||||
egui_system_font_provider = { git = "https://github.com/storytold/egui.git", rev = "e9711ca9b69772f875ae0d1cef1977ff8c16234d" }
|
||||
eframe = { git = "https://github.com/storytold/egui.git", rev = "e9711ca9b69772f875ae0d1cef1977ff8c16234d" }
|
||||
egui_demo_lib = { git = "https://github.com/storytold/egui.git", rev = "e9711ca9b69772f875ae0d1cef1977ff8c16234d" }
|
||||
egui_inspection = { git = "https://github.com/storytold/egui.git", rev = "e9711ca9b69772f875ae0d1cef1977ff8c16234d" }
|
||||
ecolor = { git = "https://github.com/storytold/egui.git", rev = "7e1c30d142bc7879d043e74b5ceb3ecfe7f51329" }
|
||||
emath = { git = "https://github.com/storytold/egui.git", rev = "7e1c30d142bc7879d043e74b5ceb3ecfe7f51329" }
|
||||
epaint = { git = "https://github.com/storytold/egui.git", rev = "7e1c30d142bc7879d043e74b5ceb3ecfe7f51329" }
|
||||
epaint_default_fonts = { git = "https://github.com/storytold/egui.git", rev = "7e1c30d142bc7879d043e74b5ceb3ecfe7f51329" }
|
||||
egui = { git = "https://github.com/storytold/egui.git", rev = "7e1c30d142bc7879d043e74b5ceb3ecfe7f51329" }
|
||||
egui-winit = { git = "https://github.com/storytold/egui.git", rev = "7e1c30d142bc7879d043e74b5ceb3ecfe7f51329" }
|
||||
egui-wgpu = { git = "https://github.com/storytold/egui.git", rev = "7e1c30d142bc7879d043e74b5ceb3ecfe7f51329" }
|
||||
egui_glow = { git = "https://github.com/storytold/egui.git", rev = "7e1c30d142bc7879d043e74b5ceb3ecfe7f51329" }
|
||||
egui_extras = { git = "https://github.com/storytold/egui.git", rev = "7e1c30d142bc7879d043e74b5ceb3ecfe7f51329" }
|
||||
egui_kittest = { git = "https://github.com/storytold/egui.git", rev = "7e1c30d142bc7879d043e74b5ceb3ecfe7f51329" }
|
||||
egui_system_font_provider = { git = "https://github.com/storytold/egui.git", rev = "7e1c30d142bc7879d043e74b5ceb3ecfe7f51329" }
|
||||
eframe = { git = "https://github.com/storytold/egui.git", rev = "7e1c30d142bc7879d043e74b5ceb3ecfe7f51329" }
|
||||
egui_demo_lib = { git = "https://github.com/storytold/egui.git", rev = "7e1c30d142bc7879d043e74b5ceb3ecfe7f51329" }
|
||||
egui_inspection = { git = "https://github.com/storytold/egui.git", rev = "7e1c30d142bc7879d043e74b5ceb3ecfe7f51329" }
|
||||
winit = { git = "https://github.com/storytold/winit.git", rev = "a517b3846ee8457d84ee4975110bfda6797c44dc" }
|
||||
|
||||
# symphonia's FLAC decoder restores LPC samples as `residual + (prediction as i32)`. In a valid
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
/// The egui fork the library is built and tested with. Apps patch egui to exactly this.
|
||||
pub const GIT: &str = "https://github.com/storytold/egui.git";
|
||||
/// The commit of [`GIT`].
|
||||
pub const REV: &str = "e9711ca9b69772f875ae0d1cef1977ff8c16234d";
|
||||
pub const REV: &str = "7e1c30d142bc7879d043e74b5ceb3ecfe7f51329";
|
||||
|
||||
/// The packages the workspace patches to the fork (the `[patch.crates-io]` entries that name [`GIT`]).
|
||||
pub const PACKAGES: &[&str] = &[
|
||||
|
||||
@@ -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 };
|
||||
|
||||
@@ -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.
|
||||
@@ -439,44 +440,61 @@ 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())
|
||||
});
|
||||
/// Notes in the open records the members that joined `arena` on `layer` through `clip`, as declared: a replay joins
|
||||
/// them at the stack positions the arena gives them then.
|
||||
fn journal_join(ctx: &Context, arena: ArenaId, layer: Layer, clip: Rect, joined: &[MemberDecl]) {
|
||||
crate::runtime::replay::journal(
|
||||
ctx,
|
||||
|| (arena, layer, clip, joined.to_vec()),
|
||||
|ctx, (arena, layer, clip, joined)| join_again(ctx, *arena, *layer, *clip, joined),
|
||||
);
|
||||
}
|
||||
|
||||
/// Replayed members join their arena again.
|
||||
fn join_again(ctx: &Context, arena: ArenaId, joined: Vec<MemberDecl>) {
|
||||
journal_join(ctx, arena, &joined);
|
||||
let pass_nr = pass::pass_nr(ctx, pass::current_viewport(ctx));
|
||||
with_arena(ctx, arena, pass_nr, |state| {
|
||||
rotate(state, pass_nr);
|
||||
/// Replayed members join their arena again, after the members that joined before them in this pass.
|
||||
fn join_again(ctx: &Context, arena: ArenaId, layer: Layer, clip: Rect, joined: &[MemberDecl]) {
|
||||
journal_join(ctx, arena, layer, clip, joined);
|
||||
let read = PassRead::of(ctx);
|
||||
let mut shapes = Vec::new();
|
||||
with_arena_in(ctx, read.viewport, arena, read.pass_nr, |state| {
|
||||
rotate(state, read.pass_nr);
|
||||
for decl in joined {
|
||||
state.union_sense |= decl.parts.iter().fold(decl.sense, |sense, part| sense | part.sense);
|
||||
state.members.push(decl);
|
||||
join_member(state, decl.clone(), layer, read.target(), &mut shapes);
|
||||
}
|
||||
});
|
||||
pointer::add_shapes_in(ctx, read.viewport, layer, arena.0, clip, shapes);
|
||||
}
|
||||
|
||||
/// 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));
|
||||
let pass_nr = pass::pass_nr(ctx, pass::current_viewport(ctx));
|
||||
with_arena(ctx, arena, pass_nr, |state| {
|
||||
rotate(state, pass_nr);
|
||||
/// Joins `decl`, as declared, to the arena `state` on `layer`: at the next stack position, its `over` parts just above
|
||||
/// it, its shapes added to `shapes`.
|
||||
fn join_member(state: &mut ArenaState, mut decl: MemberDecl, layer: Layer, target: f32, shapes: &mut Vec<Shape<Id>>) {
|
||||
decl.local = state.layer == Some(layer);
|
||||
let position = member_position(state.members.len());
|
||||
decl.over_at = position + 1;
|
||||
shapes.extend(member_shapes(&decl, position, target));
|
||||
state.union_sense |= decl.parts.iter().fold(decl.sense, |sense, part| sense | part.sense);
|
||||
state.members.push(decl);
|
||||
}
|
||||
|
||||
/// Places the `over` parts of the root `id` of `arena` (`member` false) or of its member `id` above the members joined
|
||||
/// so far, as `place_over_widgets` does, and records their shapes on `layer` through `clip`; journaled, so a replay
|
||||
/// places them above the members joined in the replaying pass.
|
||||
fn place_over(ctx: &Context, (arena, id, member, layer, clip): (ArenaId, Id, bool, Layer, Rect)) {
|
||||
crate::runtime::replay::journal(ctx, || (arena, id, member, layer, clip), |ctx, &args| place_over(ctx, args));
|
||||
let read = PassRead::of(ctx);
|
||||
let shapes = with_arena_in(ctx, read.viewport, arena, read.pass_nr, |state| {
|
||||
rotate(state, read.pass_nr);
|
||||
let at = over_position(state.members.len());
|
||||
match member {
|
||||
None => state.own_over_at = at,
|
||||
Some(id) => {
|
||||
if let Some(joined) = state.members.iter_mut().rev().find(|joined| joined.id == id) {
|
||||
joined.over_at = at;
|
||||
}
|
||||
}
|
||||
if !member {
|
||||
state.own_over_at = at;
|
||||
return Some(own_over_shapes(&state.own, id, at, read.target()));
|
||||
}
|
||||
let joined = state.members.iter_mut().rev().find(|joined| joined.id == id)?;
|
||||
joined.over_at = at;
|
||||
Some(member_over_shapes(joined, read.target()).collect())
|
||||
});
|
||||
if let Some(shapes) = shapes {
|
||||
pointer::add_shapes_in(ctx, read.viewport, layer, arena.0, clip, shapes);
|
||||
}
|
||||
}
|
||||
|
||||
/// What step 8 reads of the running pass, fetched once per root: the viewport, the pass number and the pointer
|
||||
@@ -691,20 +709,10 @@ pub(crate) fn place_over_widgets(ui: &Ui, id: Id, member: Option<ArenaId>, decls
|
||||
}
|
||||
let arena = member.unwrap_or_else(|| ArenaId::new(id));
|
||||
let layer = ui.layer_id();
|
||||
let read = PassRead::of(ctx);
|
||||
place_over(ctx, arena, member.map(|_| id));
|
||||
let shapes = with_arena_in(ctx, read.viewport, arena, read.pass_nr, |state| {
|
||||
if member.is_none() {
|
||||
return Some(own_over_shapes(&state.own, id, state.own_over_at, read.target()));
|
||||
}
|
||||
let joined = state.members.iter().rev().find(|joined| joined.id == id)?;
|
||||
Some(member_over_shapes(joined, read.target()).collect::<Vec<_>>())
|
||||
});
|
||||
let Some(shapes) = shapes else { return };
|
||||
pointer::record_shapes_in(ctx, read.viewport, layer, arena.0, clip, shapes);
|
||||
place_over(ctx, (arena, id, member.is_some(), layer, clip));
|
||||
// A root's widgets are in its widget record from step 8.
|
||||
if member.is_some() && !widgets.is_empty() {
|
||||
pointer::record_widgets_in(ctx, read.viewport, layer, arena.0, &widgets, decls.iter().any(|part| part.sense.contains(Sense::CLICK)));
|
||||
pointer::record_widgets(ctx, layer, arena.0, &widgets, decls.iter().any(|part| part.sense.contains(Sense::CLICK)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -758,27 +766,19 @@ pub(crate) fn sense_members(ui: &Ui, arena: ArenaId, specs: &[MemberSpec<'_>]) -
|
||||
let outcome = with_arena(ctx, arena, pass_nr, |state| {
|
||||
rotate(state, pass_nr);
|
||||
for spec in specs {
|
||||
let mut decl = MemberDecl::new(spec.id, spec.rect, spec.sense, spec.parts);
|
||||
decl.local = state.layer == Some(layer);
|
||||
let position = member_position(state.members.len());
|
||||
decl.over_at = position + 1;
|
||||
shapes.extend(member_shapes(&decl, position, target));
|
||||
state.union_sense |= decl.sense;
|
||||
for part in &decl.parts {
|
||||
state.union_sense |= part.sense;
|
||||
}
|
||||
joined.push((decl.local, known_in(state, spec.id)));
|
||||
let decl = MemberDecl::new(spec.id, spec.rect, spec.sense, spec.parts);
|
||||
if recording {
|
||||
recorded.push(decl.clone());
|
||||
}
|
||||
state.members.push(decl);
|
||||
join_member(state, decl, layer, target, &mut shapes);
|
||||
joined.push((state.layer == Some(layer), known_in(state, spec.id)));
|
||||
}
|
||||
state.outcome.filter(|outcome| outcome.pass == pass_nr).unwrap_or_default()
|
||||
});
|
||||
if recording {
|
||||
journal_join(ctx, arena, &recorded);
|
||||
journal_join(ctx, arena, layer, ui.clip_rect(), &recorded);
|
||||
}
|
||||
pointer::record_shapes(ctx, layer, arena.0, ui.clip_rect(), shapes);
|
||||
pointer::add_shapes_in(ctx, pass::current_viewport(ctx), layer, arena.0, ui.clip_rect(), shapes);
|
||||
specs
|
||||
.iter()
|
||||
.zip(joined)
|
||||
|
||||
@@ -762,7 +762,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| board.instances.upsert(Instance { id, scope, viewport, stamp, layer }));
|
||||
@@ -1079,10 +1079,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);
|
||||
|
||||
@@ -343,7 +343,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, Hash)]
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
|
||||
pub struct CommandChain(Arc<[(CommandScope, Id)]>);
|
||||
|
||||
impl CommandChain {
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -137,7 +137,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`.
|
||||
@@ -145,7 +145,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`.
|
||||
@@ -153,7 +153,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,
|
||||
|
||||
@@ -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,
|
||||
@@ -260,8 +260,9 @@ 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)]
|
||||
/// (`runtime::lazy`), so its stops keep their place in Tab and F6 order. Two transcripts are equal when their replays
|
||||
/// register the same records under the same open scope (`Transcript::placed`).
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub(crate) struct Transcript {
|
||||
stops: Vec<StopRec>,
|
||||
scopes: Vec<(Id, ScopeRec)>,
|
||||
@@ -276,8 +277,34 @@ impl Transcript {
|
||||
pub(crate) fn stop_ids(&self) -> impl Iterator<Item = Id> + '_ {
|
||||
self.stops.iter().map(|rec| rec.stop.id)
|
||||
}
|
||||
|
||||
/// The transcript as a replay registers it with `outer` the innermost open scope: a record under the scope that
|
||||
/// was open around the run goes under `outer`, and a replayed scope is no new scope (`entering` is false).
|
||||
fn placed(&self, outer: Option<Id>) -> Transcript {
|
||||
let place = |scope: Option<Id>| if scope == self.outer { outer } else { scope };
|
||||
Transcript {
|
||||
stops: self.stops.iter().map(|rec| StopRec { stop: rec.stop.clone(), scope: place(rec.scope) }).collect(),
|
||||
scopes: self
|
||||
.scopes
|
||||
.iter()
|
||||
.map(|(id, scope)| (*id, ScopeRec { parent: place(scope.parent), entering: scope.entering.map(|_| false), ..scope.clone() }))
|
||||
.collect(),
|
||||
groups: self.groups.clone(),
|
||||
row_sets: self.row_sets.clone(),
|
||||
outer,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for Transcript {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
let [a, b] = [self.placed(None), other.placed(None)];
|
||||
(a.stops, a.scopes, a.groups, a.row_sets) == (b.stops, b.scopes, b.groups, b.row_sets)
|
||||
}
|
||||
}
|
||||
|
||||
impl Eq for Transcript {}
|
||||
|
||||
/// Where the running pass's registrations stand.
|
||||
pub(crate) fn mark(ctx: &Context) -> Mark {
|
||||
with(ctx, |state| Mark {
|
||||
@@ -310,21 +337,19 @@ pub(crate) fn transcript(ctx: &Context, mark: Mark) -> Transcript {
|
||||
pub(crate) fn replay(ctx: &Context, transcript: &Transcript) {
|
||||
let frame = crate::runtime::egui::pass::frame_nr(ctx, viewport(ctx));
|
||||
with(ctx, |state| {
|
||||
let outer = state.open.last().map(|(id, _)| *id);
|
||||
let place = |scope: Option<Id>| if scope == transcript.outer { outer } else { scope };
|
||||
for (id, scope) in &transcript.scopes {
|
||||
let parent = place(scope.parent);
|
||||
state.scopes.insert(*id, ScopeRec { parent, entering: scope.entering.map(|_| false), ..scope.clone() });
|
||||
state.scope_order.push(*id);
|
||||
let placed = transcript.placed(state.open.last().map(|(id, _)| *id));
|
||||
for (id, scope) in placed.scopes {
|
||||
if scope.entering.is_none() {
|
||||
state.seen.insert(*id, frame);
|
||||
state.seen.insert(id, frame);
|
||||
}
|
||||
state.scopes.insert(id, scope);
|
||||
state.scope_order.push(id);
|
||||
}
|
||||
state.stops.extend(transcript.stops.iter().map(|rec| StopRec { stop: rec.stop.clone(), scope: place(rec.scope) }));
|
||||
for group in &transcript.groups {
|
||||
state.groups.insert(group.id, *group);
|
||||
state.stops.extend(placed.stops);
|
||||
for group in placed.groups {
|
||||
state.groups.insert(group.id, group);
|
||||
}
|
||||
state.row_sets.extend(transcript.row_sets.iter().cloned());
|
||||
state.row_sets.extend(placed.row_sets);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -431,7 +456,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.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 });
|
||||
|
||||
@@ -369,10 +369,17 @@ 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()),
|
||||
);
|
||||
add_shapes_in(ctx, viewport, layer, root, clip, shapes);
|
||||
}
|
||||
|
||||
/// `record_shapes_in` with no note in the run records, for a caller whose own note makes the shapes again: shapes at
|
||||
/// stack positions a replay takes from the arena it joins (`sensing`), not from the recorded run.
|
||||
pub(crate) fn add_shapes_in(ctx: &Context, viewport: ViewportId, layer: Layer, root: Id, clip: Rect, shapes: Vec<Shape<Id>>) {
|
||||
PerViewport::<Shapes>::with(ctx, viewport, |record| {
|
||||
let order = record.next;
|
||||
record.next += 1;
|
||||
@@ -385,7 +392,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 +410,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 +424,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);
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,21 @@ 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), so everything the registration depends on is in the arguments. A capture fails
|
||||
/// the build, not `cargo check`: the size assert is a constant that is evaluated only when the code is generated.
|
||||
/// 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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -1,8 +1,15 @@
|
||||
//! Trials of the replay records' notes.
|
||||
//! Trials of the replay records: their notes and their comparison.
|
||||
|
||||
#![allow(clippy::expect_used, reason = "trial code: clippy.toml allows expect in tests, and trials are compiled into the library")]
|
||||
|
||||
use crate::primitives::sensing::{self, MemberSpec};
|
||||
use crate::runtime::egui::{fixture, repaint};
|
||||
use crate::runtime::env::ArenaId;
|
||||
use crate::runtime::focus::{self, FocusPolicy, KeyUse, Stop};
|
||||
use crate::runtime::replay;
|
||||
use crate::testing::{Frames, trial};
|
||||
use crate::testing::{Frames, pointer, trial};
|
||||
use craft_behavior::Sense;
|
||||
use egui::{Pos2, Rect, Vec2};
|
||||
|
||||
// A job's thread asks for a pass (a finished job's wake, a progress report) while a pass of the same context records a
|
||||
// region on the UI thread: the request notes nothing in that pass's records and leaves its pass state alone.
|
||||
@@ -19,3 +26,151 @@ fn a_repaint_from_a_job_thread_leaves_the_running_pass_s_records_alone() {
|
||||
});
|
||||
assert_eq!(joined, Some(true), "the job thread's repaint request returns");
|
||||
}
|
||||
|
||||
/// Records one frame's run of `run` in `frames`.
|
||||
fn record(frames: &mut Frames, mut run: impl FnMut(&egui::Context)) -> replay::Record {
|
||||
let mut record = None;
|
||||
frames.frame(Vec::new(), |ui| {
|
||||
let ctx = ui.ctx().clone();
|
||||
replay::open(&ctx);
|
||||
run(&ctx);
|
||||
record = Some(replay::close(&ctx, fixture::layer_of(ui)));
|
||||
});
|
||||
record.expect("the frame ran")
|
||||
}
|
||||
|
||||
fn note_a(_: &egui::Context, _: &(egui::Id, u32)) {}
|
||||
|
||||
fn note_b(_: &egui::Context, _: &(egui::Id, u32)) {}
|
||||
|
||||
// A journal entry is the same registration as another only when both come from the same call with equal arguments: a
|
||||
// replay and a real run compare by it.
|
||||
#[trial]
|
||||
fn journal_entries_compare_by_their_call_and_arguments() {
|
||||
let mut frames = Frames::new();
|
||||
let id = fixture::named_id("owner");
|
||||
let notes = |calls: [(bool, u32); 2]| {
|
||||
move |ctx: &egui::Context| {
|
||||
for (a, n) in calls {
|
||||
if a {
|
||||
replay::journal(ctx, || (id, n), note_a);
|
||||
} else {
|
||||
replay::journal(ctx, || (id, n), note_b);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
let first = record(&mut frames, notes([(true, 1), (true, 2)]));
|
||||
let again = record(&mut frames, notes([(true, 1), (true, 2)]));
|
||||
let changed_argument = record(&mut frames, notes([(true, 1), (true, 3)]));
|
||||
let other_call = record(&mut frames, notes([(true, 1), (false, 2)]));
|
||||
assert_eq!(first.journal.len(), 2, "both notes are in the record");
|
||||
assert_eq!(first.journal, again.journal, "the same calls with the same arguments");
|
||||
assert_ne!(first.journal[1], changed_argument.journal[1], "one argument changed");
|
||||
assert_eq!(first.journal[0], changed_argument.journal[0]);
|
||||
assert_ne!(first.journal[1], other_call.journal[1], "another call with the same arguments");
|
||||
}
|
||||
|
||||
// A focus transcript with one changed stop compares unequal to the run before it; one with the same stops equal.
|
||||
#[trial]
|
||||
fn a_transcript_with_one_changed_stop_compares_unequal() {
|
||||
let mut frames = Frames::new();
|
||||
let [one, two] = [fixture::named_id("one"), fixture::named_id("two")];
|
||||
let stops = |second: KeyUse| {
|
||||
move |ctx: &egui::Context| {
|
||||
focus::register_stop(ctx, Stop::new(one, KeyUse::CODE));
|
||||
focus::register_stop(ctx, Stop::new(two, second));
|
||||
}
|
||||
};
|
||||
let first = record(&mut frames, stops(KeyUse::CODE));
|
||||
let again = record(&mut frames, stops(KeyUse::CODE));
|
||||
let changed = record(&mut frames, stops(KeyUse::TEXT_MULTILINE));
|
||||
assert_eq!(first.focus.stop_ids().count(), 2, "both stops are in the transcript");
|
||||
assert_eq!(first.focus, again.focus);
|
||||
assert_ne!(first.focus, changed.focus, "the second stop's keys changed");
|
||||
}
|
||||
|
||||
/// Records `stops` run inside a record, with `entering` the first-pass flag of the layer scope it pushes, inside the
|
||||
/// scope `outer` when one is given.
|
||||
fn layer_scope_record(frames: &mut Frames, outer: Option<egui::Id>, entering: bool) -> replay::Record {
|
||||
let [scope, stop] = [fixture::named_id("layer scope"), fixture::named_id("stop")];
|
||||
let mut record = None;
|
||||
frames.frame(Vec::new(), |ui| {
|
||||
let ctx = ui.ctx().clone();
|
||||
if let Some(outer) = outer {
|
||||
focus::push_scope(&ctx, outer, FocusPolicy::NONE, None);
|
||||
}
|
||||
replay::open(&ctx);
|
||||
focus::register_stop(&ctx, Stop::new(fixture::named_id("beside"), KeyUse::CODE));
|
||||
focus::push_scope_from(&ctx, scope, FocusPolicy::NONE, None, None, false, Some(entering));
|
||||
focus::register_stop(&ctx, Stop::new(stop, KeyUse::CODE));
|
||||
focus::pop_scope(&ctx);
|
||||
record = Some(replay::close(&ctx, fixture::layer_of(ui)));
|
||||
if outer.is_some() {
|
||||
focus::pop_scope(&ctx);
|
||||
}
|
||||
});
|
||||
record.expect("the frame ran")
|
||||
}
|
||||
|
||||
// A view recorded in the pass its layer appeared (`entering`) and the real run of the next pass register the same
|
||||
// once replayed: a replayed scope is no new scope.
|
||||
#[trial]
|
||||
fn a_first_pass_transcript_equals_the_next_real_run() {
|
||||
let mut frames = Frames::new();
|
||||
let first = layer_scope_record(&mut frames, None, true);
|
||||
let next = layer_scope_record(&mut frames, None, false);
|
||||
assert_eq!(first.focus, next.focus);
|
||||
}
|
||||
|
||||
// The same view shown inside two different scopes registers the same records under each.
|
||||
#[trial]
|
||||
fn a_transcript_under_another_open_scope_compares_equal() {
|
||||
let mut frames = Frames::new();
|
||||
let one = layer_scope_record(&mut frames, Some(fixture::named_id("outer one")), false);
|
||||
let other = layer_scope_record(&mut frames, Some(fixture::named_id("outer other")), false);
|
||||
assert_eq!(one.focus, other.focus);
|
||||
}
|
||||
|
||||
// A child recorded as the arena's first member and replayed after two members that cover it stacks above them, as a
|
||||
// real run after them would: its stack positions come from the arena it joins, not from the recorded run.
|
||||
#[trial]
|
||||
fn a_replayed_member_stacks_above_the_members_before_it() {
|
||||
let mut frames = Frames::new();
|
||||
let arena = ArenaId::new(fixture::named_id("arena"));
|
||||
let [before, cover, child] = [fixture::named_id("before"), fixture::named_id("cover"), fixture::named_id("child")];
|
||||
let rect = Rect::from_min_size(Pos2::new(20.0, 20.0), Vec2::splat(40.0));
|
||||
let spec = |id, rect| MemberSpec { id, rect, sense: Sense::HOVER | Sense::CLICK, parts: &[], enabled: true };
|
||||
let mut recorded = None;
|
||||
frames.frame(Vec::new(), |ui| {
|
||||
let ctx = ui.ctx().clone();
|
||||
replay::open(&ctx);
|
||||
sensing::sense_members(ui, arena, &[spec(child, rect)]);
|
||||
recorded = Some(replay::close(&ctx, fixture::layer_of(ui)));
|
||||
});
|
||||
let recorded = recorded.expect("the frame ran");
|
||||
let shown = |ui: &mut egui::Ui, replayed: bool| {
|
||||
sensing::sense_members(ui, arena, &[spec(before, Rect::from_min_size(Pos2::ZERO, Vec2::splat(10.0))), spec(cover, rect)]);
|
||||
if replayed {
|
||||
replay::replay(ui.ctx(), &recorded);
|
||||
return None;
|
||||
}
|
||||
let ctx = ui.ctx().clone();
|
||||
replay::open(&ctx);
|
||||
sensing::sense_members(ui, arena, &[spec(child, rect)]);
|
||||
Some(replay::close(&ctx, fixture::layer_of(ui)))
|
||||
};
|
||||
let mut real = None;
|
||||
frames.frame(Vec::new(), |ui| real = shown(ui, false));
|
||||
let real = real.expect("the frame ran");
|
||||
assert_eq!(recorded.journal, real.journal, "the join is noted as declared, without its stack positions");
|
||||
frames.frame(Vec::new(), |ui| {
|
||||
let _ = shown(ui, true);
|
||||
});
|
||||
let mut hovered = None;
|
||||
frames.frame(vec![pointer::moved(rect.center())], |ui| {
|
||||
hovered = Some([crate::runtime::pointer::hovers(ui.ctx(), child), crate::runtime::pointer::hovers(ui.ctx(), cover)]);
|
||||
let _ = shown(ui, true);
|
||||
});
|
||||
assert_eq!(hovered, Some([true, false]), "the replayed child is above the member that covers it");
|
||||
}
|
||||
|
||||
@@ -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> {}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user