diff --git a/crates/ui-contract/src/contract/overlay/popups.rs b/crates/ui-contract/src/contract/overlay/popups.rs index b51774de66..4b3f4dbfe5 100644 --- a/crates/ui-contract/src/contract/overlay/popups.rs +++ b/crates/ui-contract/src/contract/overlay/popups.rs @@ -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, + 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, } @@ -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 { +pub(crate) fn open_map(stage: &mut MemoryStage, owner: Id) -> IdMap { let ctx = stage.ctx().clone(); let popups: Vec = with_popups(&ctx, |popups| popups.registered.iter().filter(|(registered, _)| *registered == owner).map(|(_, popup)| *popup).collect()); diff --git a/crates/ui-contract/src/contract/overlay/ui.rs b/crates/ui-contract/src/contract/overlay/ui.rs index 341f36f60e..3618fbf7b9 100644 --- a/crates/ui-contract/src/contract/overlay/ui.rs +++ b/crates/ui-contract/src/contract/overlay/ui.rs @@ -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, + pub(crate) open: IdMap, /// 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) -> Self { + pub(crate) fn new(ctx: &'a Context, owner: OverlayOwner, ui: &'a mut Ui, resolved: &'a Resolved<'a>, env: Env, open: IdMap) -> 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 } diff --git a/crates/ui-contract/src/contract/run.rs b/crates/ui-contract/src/contract/run.rs index 7e0acd15b2..9d0ee03d78 100644 --- a/crates/ui-contract/src/contract/run.rs +++ b/crates/ui-contract/src/contract/run.rs @@ -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>); +pub(crate) struct BarRules(IdMap>); /// A rule's paint: `shapes` of the paint list of `layer`, in the pass `pass`. struct HeldRule { diff --git a/crates/ui-contract/src/contract/steps/id.rs b/crates/ui-contract/src/contract/steps/id.rs index 7b107e3649..b1f65f7e5c 100644 --- a/crates/ui-contract/src/contract/steps/id.rs +++ b/crates/ui-contract/src/contract/steps/id.rs @@ -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, + /// Under the scope's id joined with the component type's. + next: IdMap, + 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(ctx: &Context, run: impl FnOnce() -> R, keep: impl FnOnce pub(crate) fn keeping_ids(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>| { + let ordinals = |take: Option>| { PerViewport::>::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; diff --git a/crates/ui-contract/src/layout/body.rs b/crates/ui-contract/src/layout/body.rs index 0c506491e7..38d4a0256b 100644 --- a/crates/ui-contract/src/layout/body.rs +++ b/crates/ui-contract/src/layout/body.rs @@ -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); +pub(crate) struct Cursors(IdMap); /// 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); +pub(crate) struct FillCounts(IdMap); /// 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); +pub(crate) struct HeldWidths(IdMap); /// 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>); +pub(crate) struct FirstLines(IdMap>); /// 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); +pub(crate) struct RowLines(IdMap); /// 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>); +pub(crate) struct ShrinkReports(IdMap>); /// 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>); +pub(crate) struct LeastReports(IdMap>); /// 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(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::(&ctx, |reports| reports.0.insert(id, HashMap::new())); + pass_state::with::(&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)); diff --git a/crates/ui-contract/src/primitives/sensing.rs b/crates/ui-contract/src/primitives/sensing.rs index f5a341de59..bc7bc63cc6 100644 --- a/crates/ui-contract/src/primitives/sensing.rs +++ b/crates/ui-contract/src/primitives/sensing.rs @@ -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, + by_root: IdMap, swept: u64, /// The end sweep is registered; the runtime layer below cannot register it at install. sweep_registered: bool, diff --git a/crates/ui-contract/src/runtime/access/text.rs b/crates/ui-contract/src/runtime/access/text.rs index b25a575f6b..87d4fe4493 100644 --- a/crates/ui-contract/src/runtime/access/text.rs +++ b/crates/ui-contract/src/runtime/access/text.rs @@ -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>); +struct Tables(IdMap>); pub(crate) fn run_id(owner: Id, line: usize, run: usize) -> Id { sub(owner, ("text_run", line, run)) diff --git a/crates/ui-contract/src/runtime/egui/access.rs b/crates/ui-contract/src/runtime/egui/access.rs index 3d231e9b93..a5fd553eea 100644 --- a/crates/ui-contract/src/runtime/egui/access.rs +++ b/crates/ui-contract/src/runtime/egui/access.rs @@ -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, - written: HashSet, + written: IdSet, /// Text widgets whose node folds into their owner's node, each with its owner. - folded: HashMap, + folded: IdMap, /// 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) { +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; diff --git a/crates/ui-contract/src/runtime/inspect.rs b/crates/ui-contract/src/runtime/inspect.rs index e328be9df7..18e4138cf6 100644 --- a/crates/ui-contract/src/runtime/inspect.rs +++ b/crates/ui-contract/src/runtime/inspect.rs @@ -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>, + steps: IdMap>, findings: Vec, canvas_controls: Vec<&'static str>, /// The inspected regions open in the running pass, innermost last. open: Vec, /// The latest record of each region, and the element its list points at, by the region's key. - kept: HashMap, + kept: IdMap, } /// 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 = open.elements.iter().map(|(element, _)| element.id).collect(); + let ids: IdSet = open.elements.iter().map(|(element, _)| element.id).collect(); let mut elements: Vec = 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 = elements.iter().enumerate().rev().map(|(index, element)| (element.id, index)).collect(); + let place: IdMap = 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 = elements + let names: IdMap = elements .iter() .filter(|element| element.part.is_none()) .filter_map(|element| Some((element.id, element.facts.as_ref()?.name.clone()?))) diff --git a/crates/ui-contract/src/runtime/keys.rs b/crates/ui-contract/src/runtime/keys.rs index 98a29bc1a3..19e8deca20 100644 --- a/crates/ui-contract/src/runtime/keys.rs +++ b/crates/ui-contract/src/runtime/keys.rs @@ -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, last_nodes: HashMap, - activated: HashMap, + activated: IdMap, alt: AltTrack, /// The keys down now, as the input hook read them before it withheld any press. down: Vec, diff --git a/crates/ui-contract/src/runtime/keys/route.rs b/crates/ui-contract/src/runtime/keys/route.rs index 5fb875e97a..363c1b3464 100644 --- a/crates/ui-contract/src/runtime/keys/route.rs +++ b/crates/ui-contract/src/runtime/keys/route.rs @@ -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, 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, Routed>, - activated: &mut HashMap, + activated: &mut IdMap, ) -> 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, Routed>, activated: &mut HashMap) { +fn route_activate(ctx: &Context, rec: &StopRec, routed: &mut HashMap, Routed>, activated: &mut IdMap) { 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, - routed: &mut HashMap, Routed>, - activated: &mut HashMap, -) { +fn route_access(ctx: &Context, request: &Action, nodes: &HashMap, routed: &mut HashMap, Routed>, activated: &mut IdMap) { let Some(node) = nodes.get(&request.node()).copied() else { return }; let owner = Some(node.owner); if node.focusable { diff --git a/crates/ui-contract/src/runtime/layout_memory.rs b/crates/ui-contract/src/runtime/layout_memory.rs index 4b0d282192..be16b6dd55 100644 --- a/crates/ui-contract/src/runtime/layout_memory.rs +++ b/crates/ui-contract/src/runtime/layout_memory.rs @@ -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; +pub(crate) type Inputs = IdMap; /// 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, items: Vec, - leaves: HashMap, + leaves: IdMap, /// 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>>, + real: Mutex>>, } /// 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, - leaves: HashMap, + leaves: IdMap, inputs: Inputs, }, Boundary, @@ -223,19 +223,19 @@ struct Scope { /// this pass left (whose `real` this run fills). served: Option>, fresh: Option>, - visited: HashSet, - fills: HashSet, + visited: IdSet, + fills: IdSet, /// What the real run contributed in this scope. reported: Vec<(Id, f32)>, } #[derive(Default)] pub(crate) struct Entries { - entries: HashMap, - measured: HashMap, - kept: HashMap, + entries: IdMap, + measured: IdMap, + kept: IdMap, /// The bodies whose records a kept transcript gave in this pass, with that transcript. - served: HashMap>, + served: IdMap>, measuring: Vec, scopes: Vec, /// 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) { log::debug!(target: sizing::RERUN_LOG, "the content of {body:?} changed from its kept transcript"); - let invalidate = |kept: &mut HashMap, body: Id| { + let invalidate = |kept: &mut IdMap, 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(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. diff --git a/crates/ui-contract/src/runtime/lazy.rs b/crates/ui-contract/src/runtime/lazy.rs index ff10aca5ec..4f897ea442 100644 --- a/crates/ui-contract/src/runtime/lazy.rs +++ b/crates/ui-contract/src/runtime/lazy.rs @@ -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, + entries: IdMap, changes: Changes, /// The last frame each scroll area reached one of its children in. - reached: HashMap, + reached: IdMap, /// What the real run that lays a scroll area's content out found, by area, from `begin` to `placed`. - placed: HashMap, + placed: IdMap, /// The frame the entries were last pruned in. pruned: u64, } @@ -196,7 +196,7 @@ fn with(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 = 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) diff --git a/crates/ui-contract/src/runtime/memory.rs b/crates/ui-contract/src/runtime/memory.rs index d9fc95f82c..641a9a3b31 100644 --- a/crates/ui-contract/src/runtime/memory.rs +++ b/crates/ui-contract/src/runtime/memory.rs @@ -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::(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 = 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::>>::with_pass( - &self.ctx, - viewport, - pass_nr, - |claimed, _| claimed.clear(), - |claimed| !claimed.insert(base), - ); + let duplicate = + PerViewport::>::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"); } diff --git a/crates/ui-contract/src/runtime/overlay.rs b/crates/ui-contract/src/runtime/overlay.rs index e365ee9ee5..646d80efd9 100644 --- a/crates/ui-contract/src/runtime/overlay.rs +++ b/crates/ui-contract/src/runtime/overlay.rs @@ -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, + raised: IdMap, 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, + 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, + 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) -> Vec> { +fn families(entries: &[OpenEntry], raised: &IdMap) -> Vec> { 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)) { diff --git a/crates/ui-contract/src/runtime/pass_state.rs b/crates/ui-contract/src/runtime/pass_state.rs index 869d91667e..269ef500bc 100644 --- a/crates/ui-contract/src/runtime/pass_state.rs +++ b/crates/ui-contract/src/runtime/pass_state.rs @@ -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, overlay_pass: crate::runtime::overlay::Pass, - shown_ids: std::collections::HashSet, + shown_ids: IdSet, } } diff --git a/crates/ui-contract/src/runtime/pending.rs b/crates/ui-contract/src/runtime/pending.rs index 43f343e0a0..bb2165f550 100644 --- a/crates/ui-contract/src/runtime/pending.rs +++ b/crates/ui-contract/src/runtime/pending.rs @@ -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, Arc>); #[derive(Default)] struct PendingState { queue: Option, - tracked: HashMap, + tracked: IdMap, } fn queue_of(ctx: &Context, jobs: &Arc) -> Arc> { diff --git a/crates/ui-contract/src/runtime/pointer.rs b/crates/ui-contract/src/runtime/pointer.rs index 577bce824a..25ac0814a0 100644 --- a/crates/ui-contract/src/runtime/pointer.rs +++ b/crates/ui-contract/src/runtime/pointer.rs @@ -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 bool>, /// The arena roots whose members the next pass resolves without (`withhold_members`), with the pass that asked. - withheld: HashMap, + withheld: IdMap, } /// What one root registered on one layer: its shapes and its egui widgets. @@ -110,7 +110,7 @@ struct RootRecord { click: bool, } -type LayerRecord = HashMap>; +type LayerRecord = HashMap>; #[derive(Default)] pub(crate) struct Shapes { diff --git a/crates/ui-contract/src/runtime/replay.rs b/crates/ui-contract/src/runtime/replay.rs index 30919103b7..d08ead49eb 100644 --- a/crates/ui-contract/src/runtime/replay.rs +++ b/crates/ui-contract/src/runtime/replay.rs @@ -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, egui: egui::PassRecords, /// The egui widgets of the run. - pub(crate) widgets: HashSet, + pub(crate) widgets: IdSet, pub(crate) facts: Facts, }