From 69efc1baa86ded7f1f768ee487b3c110eca1a5fd Mon Sep 17 00:00:00 2001 From: Olivier FAURE Date: Tue, 14 Jan 2025 18:17:06 +0100 Subject: [PATCH 1/2] Document RenderRoot fields Remove duplicate CursorIcon field. --- masonry/src/render_root.rs | 66 ++++++++++++++++++++++++++++++++------ 1 file changed, 56 insertions(+), 10 deletions(-) diff --git a/masonry/src/render_root.rs b/masonry/src/render_root.rs index 82399590d..049da131b 100644 --- a/masonry/src/render_root.rs +++ b/masonry/src/render_root.rs @@ -51,45 +51,92 @@ const INVALID_IME_AREA: Rect = Rect::new(f64::NAN, f64::NAN, f64::NAN, f64::NAN) /// /// This is also the type that owns the widget tree. pub struct RenderRoot { + /// Root of the widget tree. pub(crate) root: WidgetPod>, + + /// Whether the window size should be determined by the content or the user. pub(crate) size_policy: WindowSizePolicy, + + /// Currnet size of the window. pub(crate) size: PhysicalSize, - // TODO - Currently this is always 1.0 - // kurbo coordinates are assumed to be in logical pixels + + /// DPI scale factor. + /// + /// Kurbo coordinates are assumed to be in logical pixels pub(crate) scale_factor: f64, + /// Is `Some` if the most recently displayed frame was an animation frame. pub(crate) last_anim: Option, + + /// Last mouse position. Updated by on_pointer_event pass, used by other passes. pub(crate) last_mouse_pos: Option>, - pub(crate) cursor_icon: CursorIcon, + + /// State passed to context types. pub(crate) global_state: RenderRootState, - // TODO - Add "access_tree_active" to detect when you don't need to update the + + /// Whether the next accessibility pass should rebuild the entire access tree. + /// + /// TODO - Add "access_tree_active" to detect when you don't need to update the // access tree pub(crate) rebuild_access_tree: bool, + + /// The widget tree; stores widgets and their states. pub(crate) widget_arena: WidgetArena, } -// TODO - Document these fields. +/// State shared between passes. pub(crate) struct RenderRootState { + /// Queue of signals to be processed by the event loop. pub(crate) signal_queue: VecDeque, + + /// Currently focused widget. pub(crate) focused_widget: Option, + + /// List of ancestors of the currently focused widget. pub(crate) focused_path: Vec, + + /// Widget that will be focused once the update_focus pass is run. pub(crate) next_focused_widget: Option, + + /// Most recently clicked widget. + /// + /// This is used to pick the focused widget on Tab events. pub(crate) most_recently_clicked_widget: Option, + + /// Widgets that have requested to be scrolled into view. pub(crate) scroll_request_targets: Vec<(WidgetId, Rect)>, + + /// List of ancestors of the currently hovered widget. pub(crate) hovered_path: Vec, + + /// Widget that currently has pointer capture. pub(crate) pointer_capture_target: Option, + + /// Current cursor icon. pub(crate) cursor_icon: CursorIcon, + + /// Cache for Parley font data. pub(crate) font_context: FontContext, + + /// Cache for Parley text layout data. pub(crate) text_layout_context: LayoutContext, + + /// List of callbacks that will run in the next mutate pass. pub(crate) mutate_callbacks: Vec, + + /// Whether an IME session is active. pub(crate) is_ime_active: bool, - /// The IME area last sent to the platform. - /// - /// This allows only sending the area to the platform when the area has changed. + + /// The area in which text is being edited. pub(crate) last_sent_ime_area: Rect, + + /// Scene cache for the widget tree. pub(crate) scenes: HashMap, + /// Whether data set in the pointer pass has been invalidated. pub(crate) needs_pointer_pass: bool, + + /// Pass tracing configuration, used to skip tracing to limit overhead. pub(crate) trace: PassTracing, } @@ -193,7 +240,6 @@ impl RenderRoot { scale_factor, last_anim: None, last_mouse_pos: None, - cursor_icon: CursorIcon::Default, global_state: RenderRootState { signal_queue: VecDeque::new(), focused_widget: None, @@ -404,7 +450,7 @@ impl RenderRoot { /// Get the current icon that the mouse should display. pub fn cursor_icon(&self) -> CursorIcon { - self.cursor_icon + self.global_state.cursor_icon } // --- MARK: ACCESS WIDGETS--- From 616ff7371f8b4d73da98891abc550c5db933c73e Mon Sep 17 00:00:00 2001 From: Olivier FAURE Date: Tue, 14 Jan 2025 18:28:47 +0100 Subject: [PATCH 2/2] Fix clippy lints and typos --- masonry/src/render_root.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/masonry/src/render_root.rs b/masonry/src/render_root.rs index 049da131b..8360d6476 100644 --- a/masonry/src/render_root.rs +++ b/masonry/src/render_root.rs @@ -57,7 +57,7 @@ pub struct RenderRoot { /// Whether the window size should be determined by the content or the user. pub(crate) size_policy: WindowSizePolicy, - /// Currnet size of the window. + /// Current size of the window. pub(crate) size: PhysicalSize, /// DPI scale factor. @@ -68,7 +68,7 @@ pub struct RenderRoot { /// Is `Some` if the most recently displayed frame was an animation frame. pub(crate) last_anim: Option, - /// Last mouse position. Updated by on_pointer_event pass, used by other passes. + /// Last mouse position. Updated by `on_pointer_event` pass, used by other passes. pub(crate) last_mouse_pos: Option>, /// State passed to context types. @@ -76,7 +76,7 @@ pub struct RenderRoot { /// Whether the next accessibility pass should rebuild the entire access tree. /// - /// TODO - Add "access_tree_active" to detect when you don't need to update the + /// TODO - Add `access_tree_active` to detect when you don't need to update the // access tree pub(crate) rebuild_access_tree: bool, @@ -95,7 +95,7 @@ pub(crate) struct RenderRootState { /// List of ancestors of the currently focused widget. pub(crate) focused_path: Vec, - /// Widget that will be focused once the update_focus pass is run. + /// Widget that will be focused once the `update_focus` pass is run. pub(crate) next_focused_widget: Option, /// Most recently clicked widget. @@ -121,7 +121,7 @@ pub(crate) struct RenderRootState { /// Cache for Parley text layout data. pub(crate) text_layout_context: LayoutContext, - /// List of callbacks that will run in the next mutate pass. + /// List of callbacks that will run in the next `mutate` pass. pub(crate) mutate_callbacks: Vec, /// Whether an IME session is active.