mirror of
https://github.com/emilk/egui.git
synced 2026-08-31 05:40:03 -04:00
Define a fast ViewportMap type
This commit is contained in:
@@ -59,13 +59,13 @@ struct Repaint {
|
||||
/// The current frame number.
|
||||
///
|
||||
/// Incremented at the end of each frame.
|
||||
viewports_frame_nr: HashMap<ViewportId, u64>,
|
||||
viewports_frame_nr: ViewportMap<u64>,
|
||||
|
||||
/// While positive, keep requesting repaints. Decrement at the start of each frame.
|
||||
repaint_request: HashMap<ViewportId, u8>,
|
||||
repaint_request: ViewportMap<u8>,
|
||||
request_repaint_callback: Option<Box<dyn Fn(RequestRepaintInfo) + Send + Sync>>,
|
||||
|
||||
requested_repaint_last_frame: HashMap<ViewportId, bool>,
|
||||
requested_repaint_last_frame: ViewportMap<bool>,
|
||||
}
|
||||
|
||||
impl Repaint {
|
||||
@@ -154,23 +154,23 @@ struct ContextImpl {
|
||||
|
||||
os: OperatingSystem,
|
||||
|
||||
input: HashMap<ViewportId, InputState>,
|
||||
input: ViewportMap<InputState>,
|
||||
|
||||
/// State that is collected during a frame and then cleared
|
||||
frame_state: HashMap<ViewportId, FrameState>,
|
||||
frame_state: ViewportMap<FrameState>,
|
||||
|
||||
/// How deeply nested are we?
|
||||
viewport_stack: Vec<ViewportIdPair>,
|
||||
|
||||
// The output of a frame:
|
||||
graphics: HashMap<ViewportId, GraphicLayers>,
|
||||
output: HashMap<ViewportId, PlatformOutput>,
|
||||
graphics: ViewportMap<GraphicLayers>,
|
||||
output: ViewportMap<PlatformOutput>,
|
||||
|
||||
paint_stats: PaintStats,
|
||||
|
||||
repaint: Repaint,
|
||||
|
||||
viewports: HashMap<ViewportId, Viewport>,
|
||||
viewports: ViewportMap<Viewport>,
|
||||
viewport_commands: Vec<(ViewportId, ViewportCommand)>,
|
||||
|
||||
is_desktop: bool,
|
||||
@@ -178,11 +178,11 @@ struct ContextImpl {
|
||||
|
||||
/// Written to during the frame.
|
||||
layer_rects_this_frame: ahash::HashMap<LayerId, Vec<(Id, Rect)>>,
|
||||
layer_rects_this_viewports: HashMap<ViewportId, HashMap<LayerId, Vec<(Id, Rect)>>>,
|
||||
layer_rects_this_viewports: ViewportMap<HashMap<LayerId, Vec<(Id, Rect)>>>,
|
||||
|
||||
/// Read
|
||||
layer_rects_prev_frame: ahash::HashMap<LayerId, Vec<(Id, Rect)>>,
|
||||
layer_rects_prev_viewports: HashMap<ViewportId, HashMap<LayerId, Vec<(Id, Rect)>>>,
|
||||
layer_rects_prev_viewports: ViewportMap<HashMap<LayerId, Vec<(Id, Rect)>>>,
|
||||
|
||||
#[cfg(feature = "accesskit")]
|
||||
is_accesskit_enabled: bool,
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
#![warn(missing_docs)] // Let's keep this file well-documented.` to memory.rs
|
||||
|
||||
use epaint::{emath::Rangef, vec2, Vec2};
|
||||
|
||||
use crate::{
|
||||
area, window, EventFilter, Id, IdMap, InputState, LayerId, Pos2, Rect, Style, ViewportId,
|
||||
ViewportMap,
|
||||
};
|
||||
use ahash::HashMap;
|
||||
use epaint::{emath::Rangef, vec2, Vec2};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
@@ -77,7 +78,7 @@ pub struct Memory {
|
||||
pub(crate) new_font_definitions: Option<epaint::text::FontDefinitions>,
|
||||
|
||||
#[cfg_attr(feature = "persistence", serde(skip))]
|
||||
pub(crate) interactions: HashMap<ViewportId, Interaction>,
|
||||
pub(crate) interactions: ViewportMap<Interaction>,
|
||||
|
||||
#[cfg_attr(feature = "persistence", serde(skip))]
|
||||
pub(crate) interaction: Interaction,
|
||||
@@ -90,7 +91,7 @@ pub struct Memory {
|
||||
pub(crate) window_interaction: Option<window::WindowInteraction>,
|
||||
|
||||
#[cfg_attr(feature = "persistence", serde(skip))]
|
||||
pub(crate) window_interactions: HashMap<ViewportId, window::WindowInteraction>,
|
||||
pub(crate) window_interactions: ViewportMap<window::WindowInteraction>,
|
||||
|
||||
#[cfg_attr(feature = "persistence", serde(skip))]
|
||||
pub(crate) drag_value: crate::widgets::drag_value::MonoState,
|
||||
@@ -99,7 +100,7 @@ pub struct Memory {
|
||||
pub(crate) areas: Areas,
|
||||
|
||||
#[cfg_attr(feature = "persistence", serde(skip))]
|
||||
pub(crate) viewports_areas: HashMap<ViewportId, Areas>,
|
||||
pub(crate) viewports_areas: ViewportMap<Areas>,
|
||||
|
||||
/// Which popup-window is open (if any)?
|
||||
/// Could be a combo box, color picker, menu etc.
|
||||
|
||||
@@ -49,6 +49,11 @@ impl From<ViewportId> for Id {
|
||||
}
|
||||
}
|
||||
|
||||
impl nohash_hasher::IsEnabled for ViewportId {}
|
||||
|
||||
/// A fast hash map from [`ViewportId`] to `T`.
|
||||
pub type ViewportMap<T> = nohash_hasher::IntMap<ViewportId, T>;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
/// This will deref to [`Self::this`].
|
||||
|
||||
Reference in New Issue
Block a user