Runtime maps keyed by egui Ids use IdMap and IdSet

The ids already carry their hash: the runtime's per-pass stores (lazy, layout memory, sensing arenas, id pass,
reads of overlays, inspect, keys, pointer, access) look them up without SipHash. The id pass keys its Auto
ordinals by the scope's id joined with the component type.
This commit is contained in:
aiongg
2026-11-16 17:42:23 +00:00
parent a0e01972e0
commit cf72d57473
19 changed files with 89 additions and 106 deletions
@@ -11,8 +11,7 @@ use crate::runtime::overlay::{self, CloseReason};
use crate::runtime::pass_state;
use craft_behavior::Intent;
use craft_behavior::{EditEvent, Mixed};
use egui::{Context, Id};
use std::collections::HashMap;
use egui::{Context, Id, IdMap};
/// An id and a name; `Copy`, never a snapshot of the open state.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
@@ -77,7 +76,7 @@ pub(crate) struct Popups {
pub(super) anchors: Vec<(Id, PopupShown)>,
/// The opener that opened each layer with openers, by the layer's first opener: its id and trigger (two
/// openers on one response differ by trigger) and how it fired.
pub(super) opened_by: HashMap<Id, (Id, Trigger, Opening)>,
pub(super) opened_by: IdMap<(Id, Trigger, Opening)>,
/// The popups whose layer is a container running now (`OverlayUi::show_container`), innermost last.
pub(super) layers: Vec<PopupLayer>,
}
@@ -159,7 +158,7 @@ pub(crate) fn popup_shown(ctx: &Context, owner: Id) -> bool {
}
/// Step 10: the open state of every popup `owner` registered, with the closes `request_close` queued applied.
pub(crate) fn open_map(stage: &mut MemoryStage, owner: Id) -> HashMap<Id, bool> {
pub(crate) fn open_map(stage: &mut MemoryStage, owner: Id) -> IdMap<bool> {
let ctx = stage.ctx().clone();
let popups: Vec<Id> =
with_popups(&ctx, |popups| popups.registered.iter().filter(|(registered, _)| *registered == owner).map(|(_, popup)| *popup).collect());
@@ -17,8 +17,7 @@ use crate::runtime::motion::{self};
use crate::runtime::overlay::{self, CloseReason};
use crate::style::SurfaceKind;
use craft_behavior::PartRef;
use egui::{Context, Id, Rect, Ui, UiBuilder};
use std::collections::HashMap;
use egui::{Context, Id, IdMap, Rect, Ui, UiBuilder};
/// What the `overlay` hook gets: one call per anchored popup of this component, built at step 10 with the open state
/// of every popup `cx.popup` registered this pass.
@@ -33,7 +32,7 @@ pub struct OverlayUi<'a> {
pub(crate) to_screen: egui::emath::TSTransform,
pub(crate) resolved: &'a Resolved<'a>,
pub(crate) env: Env,
pub(crate) open: HashMap<Id, bool>,
pub(crate) open: IdMap<bool>,
/// Popups whose dismissal or body request was decided in this pass; step 15 writes their slots.
#[doc(hidden)]
pub closed: Vec<(Id, CloseReason)>,
@@ -49,7 +48,7 @@ pub(crate) struct OverlayOwner {
}
impl<'a> OverlayUi<'a> {
pub(crate) fn new(ctx: &'a Context, owner: OverlayOwner, ui: &'a mut Ui, resolved: &'a Resolved<'a>, env: Env, open: HashMap<Id, bool>) -> Self {
pub(crate) fn new(ctx: &'a Context, owner: OverlayOwner, ui: &'a mut Ui, resolved: &'a Resolved<'a>, env: Env, open: IdMap<bool>) -> Self {
let to_screen = areas::layer_to_screen(ctx, ui.layer_id());
let OverlayOwner { id, anchor, parts } = owner;
OverlayUi { ctx, ui, owner: id, anchor, to_screen, resolved, env, open, closed: Vec::new(), parts }
+2 -2
View File
@@ -20,7 +20,7 @@ use crate::runtime::{commands, focus, inspect, keys, memory};
use crate::style::{Ink, StateSet, StyleCx, StyleView, UiTokens};
use craft_behavior::{Flow, Input, KeyRole, NavMove, PartRef, PressState, Proposal, Roving, Sense};
use craft_theme::Variant;
use egui::{Context, Id, Pos2, Rect, Response, Ui, Vec2};
use egui::{Context, Id, IdMap, Pos2, Rect, Response, Ui, Vec2};
use std::any::TypeId;
use std::cell::RefCell;
use std::collections::HashMap;
@@ -1213,7 +1213,7 @@ pub(crate) fn bar_member(ctx: &Context, env: &Env, hit: Rect, rule: bool) -> boo
/// The rules a bar line shows this pass that wait for the member after them: the shapes each painted, by line.
#[derive(Default)]
pub(crate) struct BarRules(HashMap<Id, Vec<HeldRule>>);
pub(crate) struct BarRules(IdMap<Vec<HeldRule>>);
/// A rule's paint: `shapes` of the paint list of `layer`, in the pass `pass`.
struct HeldRule {
+6 -6
View File
@@ -4,15 +4,15 @@ use crate::contract::IdSource;
use crate::runtime::egui::pass;
use crate::runtime::frame::{PerViewport, Stamped};
use crate::runtime::inspect;
use egui::{Context, Id, Ui};
use egui::{Context, Id, IdMap, IdSet, Ui};
use std::any::TypeId;
use std::collections::{HashMap, HashSet};
/// The `Auto` ordinals and the ids registered in one pass of one viewport.
#[derive(Default)]
pub(crate) struct IdPass {
next: HashMap<(Id, TypeId), u32>,
seen: HashSet<Id>,
/// Under the scope's id joined with the component type's.
next: IdMap<u32>,
seen: IdSet,
}
/// Runs `f` as a measuring run that leaves the `Auto` ordinals as it found them, so the run that follows in the same
@@ -36,7 +36,7 @@ pub(crate) fn draft<R>(ctx: &Context, run: impl FnOnce() -> R, keep: impl FnOnce
pub(crate) fn keeping_ids<R>(ctx: &Context, f: impl FnOnce() -> (R, bool)) -> R {
let viewport = pass::current_viewport(ctx);
let pass_nr = pass::pass_nr(ctx, viewport);
let ordinals = |take: Option<HashMap<(Id, TypeId), u32>>| {
let ordinals = |take: Option<IdMap<u32>>| {
PerViewport::<Stamped<IdPass>>::with_pass(
ctx,
viewport,
@@ -80,7 +80,7 @@ pub(crate) fn id(ui: &Ui, source: &IdSource, register: bool, advance: bool, ty:
pass_nr,
|pass, _| *pass = IdPass::default(),
|pass| {
let slot = pass.next.entry((scope, ty)).or_insert(0);
let slot = pass.next.entry(scope.with(ty)).or_insert(0);
let n = *slot;
if advance {
*slot += 1;
+9 -10
View File
@@ -9,9 +9,8 @@ use crate::runtime::measure;
use crate::runtime::memory::sub;
use crate::runtime::pass_state;
use craft_behavior::{Axis, ColumnWidth, Flow, GridCursor, GridMeasure};
use egui::{Id, Rect, Ui, Vec2};
use egui::{Id, IdMap, Rect, Ui, Vec2};
use std::borrow::Cow;
use std::collections::HashMap;
/// How a body lays out its children, in reading order: mirrored under a right-to-left direction.
#[derive(Clone, Debug, PartialEq)]
@@ -87,16 +86,16 @@ impl BodyLayout {
/// The cursors of the `Grid` and spread `Row` bodies running this pass, by body id.
#[derive(Default)]
pub(crate) struct Cursors(HashMap<Id, Cursor>);
pub(crate) struct Cursors(IdMap<Cursor>);
/// The number of children that fill the main axis of each `Stack` or `Row` body measured this pass, by body id.
#[derive(Default)]
pub(crate) struct FillCounts(HashMap<Id, u32>);
pub(crate) struct FillCounts(IdMap<u32>);
/// The narrowest width a held fill-width child of each content-sized `Stack` column measured at in the first sweep of
/// the column's measuring run (`report_held`), by column id.
#[derive(Default)]
pub(crate) struct HeldWidths(HashMap<Id, f32>);
pub(crate) struct HeldWidths(IdMap<f32>);
/// Reports a held fill-width child of the content-sized column `column` in its first sweep: the `width` it measured
/// at. A column with no first sweep open takes no report.
@@ -112,11 +111,11 @@ pub(crate) fn report_held(ctx: &egui::Context, column: Id, width: f32) {
/// of its first line's centre, or `None` for a child with no line of its own. A container's measuring sweep opens and
/// closes its header's and body's targets; a body's sweep starts its own target afresh.
#[derive(Default)]
pub(crate) struct FirstLines(HashMap<Id, Option<f32>>);
pub(crate) struct FirstLines(IdMap<Option<f32>>);
/// What the children of each unwrapped `Row` body took in the sweep of a measuring run running now, by body id.
#[derive(Default)]
pub(crate) struct RowLines(HashMap<Id, LineTook>);
pub(crate) struct RowLines(IdMap<LineTook>);
/// What the children of a row took about its line.
#[derive(Clone, Copy, Default)]
@@ -279,11 +278,11 @@ impl ShrinkUnit {
/// The units each `Row` body counting this pass reported, in order, by body id.
#[derive(Default)]
pub(crate) struct ShrinkReports(HashMap<Id, Vec<Reported>>);
pub(crate) struct ShrinkReports(IdMap<Vec<Reported>>);
/// The least widths the body units of each `Row` body asking for them this pass reported, by row id.
#[derive(Default)]
pub(crate) struct LeastReports(HashMap<Id, HashMap<Id, f32>>);
pub(crate) struct LeastReports(IdMap<IdMap<f32>>);
/// Reports the widths of the unit `leaf` of the row `row` that counts them: a leaf's whole and least widths, or `None`
/// for a body.
@@ -520,7 +519,7 @@ fn run_shrinking<R>(ui: &mut Ui, id: Id, mut body: impl FnMut(&mut Ui) -> R) ->
if probe {
#[cfg(feature = "testing")]
measure::count_least(&ctx, id);
pass_state::with::<LeastReports, _>(&ctx, |reports| reports.0.insert(id, HashMap::new()));
pass_state::with::<LeastReports, _>(&ctx, |reports| reports.0.insert(id, IdMap::default()));
crate::contract::keeping_ids(&ctx, || {
layout_memory::probing(&ctx, || {
let mut least = ui.new_child(egui::UiBuilder::new().layout(layout));
+2 -2
View File
@@ -20,7 +20,7 @@ use craft_behavior::{
};
use craft_keymap::Mods;
use craft_theme::Flags;
use egui::{Context, Id, Pos2, Rect, Response, Ui, ViewportId};
use egui::{Context, Id, IdMap, Pos2, Rect, Response, Ui, ViewportId};
use smallvec::SmallVec;
use std::collections::HashMap;
use std::sync::Arc;
@@ -243,7 +243,7 @@ struct ArenaState {
#[derive(Default)]
pub(crate) struct Arenas {
by_root: HashMap<Id, ArenaState>,
by_root: IdMap<ArenaState>,
swept: u64,
/// The end sweep is registered; the runtime layer below cannot register it at install.
sweep_registered: bool,
@@ -8,8 +8,7 @@ use crate::runtime::egui::memory::Service;
use crate::runtime::keys;
use crate::runtime::memory::sub;
use craft_behavior::{AccessRequest, PartKey, PartRef, TextPos};
use egui::{Context, Id, Rect};
use std::collections::HashMap;
use egui::{Context, Id, IdMap, Rect};
use std::ops::Range;
/// The part key of a run node, indexed in document order.
@@ -58,7 +57,7 @@ struct Entry {
}
#[derive(Default)]
struct Tables(HashMap<Id, Vec<Entry>>);
struct Tables(IdMap<Vec<Entry>>);
pub(crate) fn run_id(owner: Id, line: usize, run: usize) -> Id {
sub(owner, ("text_run", line, run))
@@ -10,10 +10,10 @@ mod text;
mod tree;
use crate::runtime::pass_state;
#[cfg(feature = "testing")]
use egui::FullOutput;
use egui::{Context, Id, ViewportId};
use std::collections::{HashMap, HashSet};
#[cfg(feature = "testing")]
use egui::{FullOutput, IdMap, IdSet};
use std::collections::HashMap;
use super::pass;
@@ -106,9 +106,9 @@ pub(crate) fn set_focus(ctx: &Context, id: Id) {
#[derive(Default)]
struct Emitted {
order: HashMap<u64, usize>,
written: HashSet<Id>,
written: IdSet,
/// Text widgets whose node folds into their owner's node, each with its owner.
folded: HashMap<Id, Id>,
folded: IdMap<Id>,
/// Whether the runtime reported a focused node this pass.
focus_set: bool,
}
@@ -182,7 +182,7 @@ pub(crate) fn order_children(ctx: &Context) {
/// While a modal layer is open in `viewport`, hides the nodes the runtime wrote on layers below it: what sits behind
/// a modal is inert for assistive technology, as it is for the pointer and the keys.
fn hide_behind_modal(ctx: &Context, viewport: ViewportId, written: &HashSet<Id>) {
fn hide_behind_modal(ctx: &Context, viewport: ViewportId, written: &IdSet) {
// Without a modal nothing is behind one; this spares reading every written node's response.
if crate::runtime::commands::modal_root(ctx, viewport).is_none() {
return;
+6 -7
View File
@@ -8,8 +8,7 @@ use crate::runtime::egui::sizing::{Rerun, request_discard};
use crate::runtime::reads::{self, BindKey};
use crate::runtime::{focus, measure, pass_state, pointer};
use craft_behavior::PartRef;
use egui::{Context, Id, Rect, Ui};
use std::collections::{HashMap, HashSet};
use egui::{Context, Id, IdMap, IdSet, Rect, Ui};
use std::sync::Arc;
/// A rule a component broke that the pipeline reports instead of panicking.
@@ -27,13 +26,13 @@ pub struct Finding {
#[derive(Default)]
pub(crate) struct Log {
steps: HashMap<Id, Vec<&'static str>>,
steps: IdMap<Vec<&'static str>>,
findings: Vec<Finding>,
canvas_controls: Vec<&'static str>,
/// The inspected regions open in the running pass, innermost last.
open: Vec<Open>,
/// The latest record of each region, and the element its list points at, by the region's key.
kept: HashMap<Id, Kept>,
kept: IdMap<Kept>,
}
/// Whether records are kept: in frames a test fixture drives, and inside an inspected region in any build.
@@ -289,7 +288,7 @@ fn edited(ctx: &Context, read: BindKey, editor: Id) {
fn finish(ctx: &Context, open: Open) -> Recorded {
let from_screen = areas::layer_to_screen(ctx, open.layer).inverse();
let to_region = |layer: Layer, rect: Rect| from_screen * (areas::layer_to_screen(ctx, layer) * rect);
let ids: HashSet<Id> = open.elements.iter().map(|(element, _)| element.id).collect();
let ids: IdSet = open.elements.iter().map(|(element, _)| element.id).collect();
let mut elements: Vec<Element> = Vec::with_capacity(open.elements.len() + open.parts.len());
let mut parts = open.parts;
let labels = open.labels;
@@ -316,7 +315,7 @@ fn finish(ctx: &Context, open: Open) -> Recorded {
}
name_from_labels(&mut elements);
// The sensing core keeps its shapes by root, in no order; a record compares equal to the same region's next one.
let place: HashMap<Id, usize> = elements.iter().enumerate().rev().map(|(index, element)| (element.id, index)).collect();
let place: IdMap<usize> = elements.iter().enumerate().rev().map(|(index, element)| (element.id, index)).collect();
hits.sort_by(|a, b| {
let key = |hit: &HitArea| (place.get(&hit.owner).copied(), hit.rect.min.y, hit.rect.min.x);
key(a).partial_cmp(&key(b)).unwrap_or(std::cmp::Ordering::Equal)
@@ -341,7 +340,7 @@ fn finish(ctx: &Context, open: Open) -> Recorded {
/// Names each node without a name of its own by the nodes of the region that label it, as a screen reader reads it.
fn name_from_labels(elements: &mut [Element]) {
let names: HashMap<Id, String> = elements
let names: IdMap<String> = elements
.iter()
.filter(|element| element.part.is_none())
.filter_map(|element| Some((element.id, element.facts.as_ref()?.name.clone()?)))
+2 -2
View File
@@ -7,7 +7,7 @@ use crate::runtime::egui::input::Action;
use crate::runtime::frame::PerViewport;
use craft_behavior::EditCommand;
use craft_keymap::{Chord, Key, KeyInput, Layout, Mods};
use egui::{Context, Id, Vec2, ViewportId};
use egui::{Context, Id, IdMap, Vec2, ViewportId};
use std::collections::HashMap;
use std::sync::Arc;
@@ -218,7 +218,7 @@ pub(crate) struct Stage {
layout: Layout,
nodes: HashMap<u64, Node>,
last_nodes: HashMap<u64, Node>,
activated: HashMap<Id, Id>,
activated: IdMap<Id>,
alt: AltTrack,
/// The keys down now, as the input hook read them before it withheld any press.
down: Vec<Key>,
+5 -11
View File
@@ -12,7 +12,7 @@ use craft_behavior::keys;
use craft_behavior::{EditCommand, Intent, KeyOwner, MoveMods, NavMove, OwnerClass};
use craft_host::target::Os;
use craft_keymap::{Chord, Key, Layout, Mods};
use egui::{Context, Id, Vec2};
use egui::{Context, Id, IdMap, Vec2};
use std::collections::HashMap;
use std::sync::Arc;
@@ -47,7 +47,7 @@ pub(crate) fn begin(ctx: &Context, press_captured: bool) -> EscapeRouting {
stage.enter_stale
});
let mut routed: HashMap<Option<Id>, Routed> = HashMap::new();
let mut activated = HashMap::new();
let mut activated = IdMap::default();
let mut consumed = vec![Taken::No; batch.presses.len()];
let driven = target.as_ref().and_then(|rec| Driven::of(ctx, rec));
let field_list = target.as_ref().filter(|_| driven.is_none()).and_then(|rec| list_of_field(ctx, rec));
@@ -542,7 +542,7 @@ fn apply_press(
press: &Press,
route: PressRoute,
routed: &mut HashMap<Option<Id>, Routed>,
activated: &mut HashMap<Id, Id>,
activated: &mut IdMap<Id>,
) -> Taken {
let stop = &rec.stop;
let id = Some(stop.id);
@@ -572,7 +572,7 @@ fn apply_press(
/// `Activate` of a group member goes to the group's root, which reads `activated_member`. A child or part of a
/// collection row activates itself.
fn route_activate(ctx: &Context, rec: &StopRec, routed: &mut HashMap<Option<Id>, Routed>, activated: &mut HashMap<Id, Id>) {
fn route_activate(ctx: &Context, rec: &StopRec, routed: &mut HashMap<Option<Id>, Routed>, activated: &mut IdMap<Id>) {
let target = if rec.stop.group.is_some() && !focus::is_row_child(ctx, &rec.stop) {
activated.insert(rec.stop.root, rec.stop.id);
rec.stop.root
@@ -595,13 +595,7 @@ fn nudge_of(key: Key, mods: Mods) -> Option<(Vec2, Mods)> {
}
/// Routes an AccessKit action request to the owner of its target node, whatever the focus (9.2 rule 2).
fn route_access(
ctx: &Context,
request: &Action,
nodes: &HashMap<u64, Node>,
routed: &mut HashMap<Option<Id>, Routed>,
activated: &mut HashMap<Id, Id>,
) {
fn route_access(ctx: &Context, request: &Action, nodes: &HashMap<u64, Node>, routed: &mut HashMap<Option<Id>, Routed>, activated: &mut IdMap<Id>) {
let Some(node) = nodes.get(&request.node()).copied() else { return };
let owner = Some(node.owner);
if node.focusable {
+19 -17
View File
@@ -17,9 +17,9 @@ use crate::runtime::egui::sizing;
use crate::runtime::frame::{self, PerViewport};
use craft_behavior::layout_memory::{SizeTween, measure_tolerance, measured_change_asks_for_discard};
use craft_behavior::{Axis, Proposal};
use egui::{Context, Id, Vec2};
use egui::{Context, Id, IdMap, IdSet, Vec2};
use std::any::Any;
use std::collections::{HashMap, HashSet};
use std::collections::HashSet;
use std::sync::{Arc, Mutex};
/// What an entry holds.
@@ -111,7 +111,7 @@ enum Item {
}
/// The inputs outside a measure that it read (`read_input`), by key: the widest value of each.
pub(crate) type Inputs = HashMap<Id, f32>;
pub(crate) type Inputs = IdMap<f32>;
/// One measure call a component got, the inputs besides its room it read, and its answer.
#[derive(Clone)]
@@ -135,10 +135,10 @@ struct Transcript {
/// The inputs the run measured under.
key: Box<dyn Any + Send + Sync>,
items: Vec<Item>,
leaves: HashMap<Id, Leaf>,
leaves: IdMap<Leaf>,
/// What the real run of the pass that measured found for the body's regions and its rows that run lazily: the
/// backstop for content that allocates without a component.
real: Mutex<Option<HashMap<Id, Vec2>>>,
real: Mutex<Option<IdMap<Vec2>>>,
}
/// A record of this pass's runs.
@@ -191,7 +191,7 @@ enum Undo {
impl Scope {
fn boundary() -> Scope {
Scope { body: None, boundary: true, served: None, fresh: None, visited: HashSet::new(), fills: HashSet::new(), reported: Vec::new() }
Scope { body: None, boundary: true, served: None, fresh: None, visited: IdSet::default(), fills: IdSet::default(), reported: Vec::new() }
}
}
@@ -202,7 +202,7 @@ enum Open {
Body {
id: Id,
items: Vec<Item>,
leaves: HashMap<Id, Leaf>,
leaves: IdMap<Leaf>,
inputs: Inputs,
},
Boundary,
@@ -223,19 +223,19 @@ struct Scope {
/// this pass left (whose `real` this run fills).
served: Option<Arc<Transcript>>,
fresh: Option<Arc<Transcript>>,
visited: HashSet<Id>,
fills: HashSet<Id>,
visited: IdSet,
fills: IdSet,
/// What the real run contributed in this scope.
reported: Vec<(Id, f32)>,
}
#[derive(Default)]
pub(crate) struct Entries {
entries: HashMap<Id, Entry>,
measured: HashMap<Id, Found>,
kept: HashMap<Id, Kept>,
entries: IdMap<Entry>,
measured: IdMap<Found>,
kept: IdMap<Kept>,
/// The bodies whose records a kept transcript gave in this pass, with that transcript.
served: HashMap<Id, Arc<Transcript>>,
served: IdMap<Arc<Transcript>>,
measuring: Vec<Open>,
scopes: Vec<Scope>,
/// The kept calls a real run asks again, as the transcript, the component and the call's index, innermost last:
@@ -252,7 +252,7 @@ impl Entries {
/// inside, up to the first boundary, and asks for the discard pass.
fn changed(&mut self, frame: u64, body: Option<Id>) {
log::debug!(target: sizing::RERUN_LOG, "the content of {body:?} changed from its kept transcript");
let invalidate = |kept: &mut HashMap<Id, Kept>, body: Id| {
let invalidate = |kept: &mut IdMap<Kept>, body: Id| {
if let Some(kept) = kept.get_mut(&body) {
kept.valid = false;
kept.moved = Some(frame);
@@ -598,10 +598,10 @@ pub(crate) fn read_input(ctx: &Context, from: usize, key: Id, value: f32) -> f32
/// outside its room, which the call's transcript entry keeps.
pub(crate) fn measure_call<R>(ctx: &Context, f: impl FnOnce() -> R) -> (R, Inputs) {
if !crate::runtime::measure::active(ctx) {
return (f(), Inputs::new());
return (f(), Inputs::default());
}
let moment = Moment::of(ctx);
with(ctx, &moment, |memory| memory.measuring.push(Open::Call { inputs: Inputs::new() }));
with(ctx, &moment, |memory| memory.measuring.push(Open::Call { inputs: Inputs::default() }));
let out = f();
let inputs = with(ctx, &moment, |memory| {
let at = memory.measuring.iter().rposition(|open| matches!(open, Open::Call { .. }))?;
@@ -898,7 +898,9 @@ pub(crate) fn run_found(ctx: &Context, id: Id) -> bool {
/// Opens the measuring run of `body`: what it hands forward until `end_measure` becomes its transcript.
pub(crate) fn begin_measure(ctx: &Context, body: Id) {
let moment = Moment::of(ctx);
with(ctx, &moment, |memory| memory.measuring.push(Open::Body { id: body, items: Vec::new(), leaves: HashMap::new(), inputs: Inputs::new() }));
with(ctx, &moment, |memory| {
memory.measuring.push(Open::Body { id: body, items: Vec::new(), leaves: IdMap::default(), inputs: Inputs::default() })
});
}
/// Closes the measuring run of `body` and keeps its transcript under the inputs `key` it ran under.
+6 -6
View File
@@ -19,8 +19,8 @@ use crate::runtime::focus::{self, Transcript};
use crate::runtime::frame::{self, PerViewport};
use crate::runtime::reads::BindKey;
use crate::runtime::replay::{self, Record};
use egui::{Context, Id, Layout, Rect, Vec2};
use std::collections::{HashMap, HashSet};
use egui::{Context, Id, IdMap, IdSet, Layout, Rect, Vec2};
use std::collections::HashSet;
use std::sync::Arc;
/// The view of the innermost scroll area, as the run that lays its content out sees it: the rect the pass shows,
@@ -161,12 +161,12 @@ struct Changes {
#[derive(Default)]
pub(crate) struct Store {
entries: HashMap<Id, Entry>,
entries: IdMap<Entry>,
changes: Changes,
/// The last frame each scroll area reached one of its children in.
reached: HashMap<Id, u64>,
reached: IdMap<u64>,
/// What the real run that lays a scroll area's content out found, by area, from `begin` to `placed`.
placed: HashMap<Id, Placed>,
placed: IdMap<Placed>,
/// The frame the entries were last pruned in.
pruned: u64,
}
@@ -196,7 +196,7 @@ fn with<R>(ctx: &Context, f: impl FnOnce(&mut Store, u64, u64) -> R) -> R {
store.entries.retain(|_, entry| {
entry.touched + 1 >= frame || entry.owner.is_some_and(|owner| reached.get(&owner).is_none_or(|ran| ran + 1 < frame))
});
let owners: HashSet<Id> = store.entries.values().filter_map(|entry| entry.owner).collect();
let owners: IdSet = store.entries.values().filter_map(|entry| entry.owner).collect();
store.reached.retain(|owner, _| owners.contains(owner));
}
f(store, pass_nr, frame)
+4 -10
View File
@@ -9,13 +9,12 @@ use crate::runtime::pending::{self, Job, Pending};
use craft_behavior::eviction::owner_due;
use craft_host::Host;
use craft_settings::Remembered;
use egui::{Context, Id, ViewportId};
use egui::{Context, Id, IdSet, ViewportId};
use serde::Serialize;
use serde::de::DeserializeOwned;
use std::any::{Any, TypeId};
use std::borrow::Cow;
use std::cell::RefCell;
use std::collections::HashSet;
use std::fmt::Debug;
use std::hash::{Hash, Hasher};
use std::marker::PhantomData;
@@ -246,7 +245,7 @@ pub(crate) fn evict(ctx: &Context) {
let live = pass::live_viewports(ctx);
pass_state::with::<Registry, _>(ctx, |reg| {
let due = |r: &OwnerRecord| owner_due(r.pass, r.at, pass::pass_nr(ctx, r.viewport), now, live.contains(&r.viewport));
let dead: HashSet<Id> = reg.owners.iter().filter(|(_, r)| due(r)).map(|(id, _)| *id).collect();
let dead: IdSet = reg.owners.iter().filter(|(_, r)| due(r)).map(|(id, _)| *id).collect();
if dead.is_empty() {
return;
}
@@ -457,13 +456,8 @@ impl MemoryStage {
self.claimed.borrow_mut().push(base);
let viewport = pass::current_viewport(&self.ctx);
let pass_nr = pass::pass_nr(&self.ctx, viewport);
let duplicate = PerViewport::<Stamped<HashSet<Id>>>::with_pass(
&self.ctx,
viewport,
pass_nr,
|claimed, _| claimed.clear(),
|claimed| !claimed.insert(base),
);
let duplicate =
PerViewport::<Stamped<IdSet>>::with_pass(&self.ctx, viewport, pass_nr, |claimed, _| claimed.clear(), |claimed| !claimed.insert(base));
debug_assert!(!duplicate, "an id is the base of two open stages in one pass");
}
+5 -6
View File
@@ -12,9 +12,8 @@ use crate::runtime::pointer;
use craft_behavior::OwnerClass;
use craft_behavior::overlay::Side;
use egui::emath::TSTransform;
use egui::{Context, Id, Pos2, Rect, ViewportId};
use egui::{Context, Id, IdMap, IdSet, Pos2, Rect, ViewportId};
use smallvec::SmallVec;
use std::collections::HashMap;
/// A modal's backdrop.
#[derive(Clone, Copy, Debug, PartialEq)]
@@ -235,7 +234,7 @@ pub(crate) struct TopModal {
#[derive(Default)]
pub(crate) struct Persist {
raised: HashMap<Id, u64>,
raised: IdMap<u64>,
counter: u64,
modal: bool,
/// The layers of the last pass, bottom to top, as `end_pass` handed them to egui.
@@ -252,9 +251,9 @@ pub(crate) struct Persist {
/// A popup stands over a modal layer here, as of the last finished pass.
popup_over_modal: bool,
/// The layers that first showed while the primary button was held, until that press ends.
held_open: std::collections::HashSet<Id>,
held_open: IdSet,
/// The root frame and pass each shown layer first ran its body in; gone with the layer's last entry.
appeared: HashMap<Id, (u64, u64)>,
appeared: IdMap<(u64, u64)>,
}
/// The closes queued and not yet taken, each with the root frame that queued it and whether it is carried: a carried
@@ -674,7 +673,7 @@ pub(crate) fn record(ctx: &Context, mut entry: OpenEntry) {
}
/// Groups `entries` into families, each parent first, ordered bottom to top.
fn families(entries: &[OpenEntry], raised: &HashMap<Id, u64>) -> Vec<Vec<OpenEntry>> {
fn families(entries: &[OpenEntry], raised: &IdMap<u64>) -> Vec<Vec<OpenEntry>> {
let root_of = |entry: &OpenEntry| {
let mut at = entry;
while let Some(parent) = at.parent.and_then(|parent| entries.iter().find(|other| other.id == parent)) {
+2 -2
View File
@@ -12,7 +12,7 @@
use crate::runtime::egui::memory::Service;
use crate::runtime::frame::{self, PerViewport, Stamped, Stored};
use egui::Context;
use egui::{Context, IdSet};
use std::cell::RefCell;
use std::sync::Arc;
@@ -137,7 +137,7 @@ pass_state! {
ids: crate::contract::steps::id::IdPass,
pass_pointer: Arc<crate::runtime::pointer::PassPointer>,
overlay_pass: crate::runtime::overlay::Pass,
shown_ids: std::collections::HashSet<egui::Id>,
shown_ids: IdSet,
}
}
+2 -3
View File
@@ -7,9 +7,8 @@ use crate::runtime::frame;
use crate::runtime::memory::{self, MemoryStage};
use craft_host::queue::{Cancel, JobQueue, Priority, QueueOptions};
use craft_host::{Jobs, Wake};
use egui::{Context, Id, ViewportId};
use egui::{Context, Id, IdMap, ViewportId};
use std::any::TypeId;
use std::collections::HashMap;
use std::sync::atomic::{AtomicU32, Ordering};
use std::sync::{Arc, Mutex, PoisonError};
use std::time::Duration;
@@ -199,7 +198,7 @@ type Queue = (Arc<dyn Jobs>, Arc<JobQueue<Id, ()>>);
#[derive(Default)]
struct PendingState {
queue: Option<Queue>,
tracked: HashMap<Id, Tracked>,
tracked: IdMap<Tracked>,
}
fn queue_of(ctx: &Context, jobs: &Arc<dyn Jobs>) -> Arc<JobQueue<Id, ()>> {
+3 -3
View File
@@ -13,7 +13,7 @@ use craft_behavior::{
};
use craft_keymap::Mods;
use craft_theme::HitSizes;
use egui::{Context, Id, Pos2, Rect, Vec2, ViewportId};
use egui::{Context, Id, IdMap, Pos2, Rect, Vec2, ViewportId};
use std::collections::HashMap;
use std::sync::Arc;
@@ -97,7 +97,7 @@ pub(crate) struct Memory {
/// Whether any arena of the viewport holds an open press; sensing registers it, as the layer above.
press_probe: Option<fn(&Context) -> bool>,
/// The arena roots whose members the next pass resolves without (`withhold_members`), with the pass that asked.
withheld: HashMap<Id, u64>,
withheld: IdMap<u64>,
}
/// What one root registered on one layer: its shapes and its egui widgets.
@@ -110,7 +110,7 @@ struct RootRecord {
click: bool,
}
type LayerRecord = HashMap<Layer, HashMap<Id, RootRecord>>;
type LayerRecord = HashMap<Layer, IdMap<RootRecord>>;
#[derive(Default)]
pub(crate) struct Shapes {
+2 -2
View File
@@ -14,7 +14,7 @@ use crate::runtime::focus::{self, Transcript};
use crate::runtime::frame;
use crate::runtime::pass_state;
use crate::runtime::reads::BindKey;
use egui::{Context, Id};
use egui::{Context, Id, IdSet};
use std::collections::HashSet;
use std::sync::Arc;
use std::sync::atomic::{AtomicUsize, Ordering};
@@ -70,7 +70,7 @@ pub(crate) struct Record {
journal: Vec<Entry>,
egui: egui::PassRecords,
/// The egui widgets of the run.
pub(crate) widgets: HashSet<Id>,
pub(crate) widgets: IdSet,
pub(crate) facts: Facts,
}