From e40d86d03608ea658e58222a7795f49f929cdd5c Mon Sep 17 00:00:00 2001 From: Olivier FAURE Date: Tue, 14 Jan 2025 11:19:14 +0100 Subject: [PATCH] Add keybinding for toggling debug paint Fix invalidation issues --- masonry/src/passes/event.rs | 16 +++++++++++++++- masonry/src/passes/paint.rs | 4 +--- masonry/src/render_root.rs | 4 ++++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/masonry/src/passes/event.rs b/masonry/src/passes/event.rs index 3cd073348..06f8f8d4a 100644 --- a/masonry/src/passes/event.rs +++ b/masonry/src/passes/event.rs @@ -126,6 +126,8 @@ pub(crate) fn run_on_pointer_event_pass(root: &mut RenderRoot, event: &PointerEv } root.global_state.inspector_state.is_picking_widget = false; root.global_state.inspector_state.hovered_widget = None; + root.global_state.needs_pointer_pass = true; + root.root_state_mut().needs_paint = true; return Handled::Yes; } @@ -194,8 +196,8 @@ pub(crate) fn run_on_text_event_pass(root: &mut RenderRoot, event: &TextEvent) - !event.is_high_density(), ); - // Handle Tab focus if let TextEvent::KeyboardKey(key, mods) = event { + // Handle Tab focus if key.physical_key == PhysicalKey::Code(KeyCode::Tab) && key.state == ElementState::Pressed && handled == Handled::No @@ -214,6 +216,18 @@ pub(crate) fn run_on_text_event_pass(root: &mut RenderRoot, event: &TextEvent) - { root.global_state.inspector_state.is_picking_widget = !root.global_state.inspector_state.is_picking_widget; + root.global_state.inspector_state.hovered_widget = None; + root.global_state.needs_pointer_pass = true; + root.root_state_mut().needs_paint = true; + handled = Handled::Yes; + } + + if key.physical_key == PhysicalKey::Code(KeyCode::F12) + && key.state == ElementState::Pressed + && handled == Handled::No + { + root.debug_paint = !root.debug_paint; + root.root_state_mut().needs_paint = true; handled = Handled::Yes; } } diff --git a/masonry/src/passes/paint.rs b/masonry/src/passes/paint.rs index 2484c7502..82aef0174 100644 --- a/masonry/src/passes/paint.rs +++ b/masonry/src/passes/paint.rs @@ -109,8 +109,6 @@ fn paint_widget( pub(crate) fn run_paint_pass(root: &mut RenderRoot) -> Scene { let _span = info_span!("paint").entered(); - let debug_paint = std::env::var("MASONRY_DEBUG_PAINT").is_ok_and(|it| !it.is_empty()); - // TODO - Reserve scene // https://github.com/linebender/xilem/issues/524 let mut complete_scene = Scene::new(); @@ -140,7 +138,7 @@ pub(crate) fn run_paint_pass(root: &mut RenderRoot) -> Scene { &mut scenes, root_widget, root_state, - debug_paint, + root.debug_paint, ); root.global_state.scenes = scenes; diff --git a/masonry/src/render_root.rs b/masonry/src/render_root.rs index fb7d08a32..e8f27ce50 100644 --- a/masonry/src/render_root.rs +++ b/masonry/src/render_root.rs @@ -60,6 +60,7 @@ pub struct RenderRoot { // access tree pub(crate) rebuild_access_tree: bool, pub(crate) widget_arena: WidgetArena, + pub(crate) debug_paint: bool, } // TODO - Document these fields. @@ -158,6 +159,8 @@ impl RenderRoot { test_font, }: RenderRootOptions, ) -> Self { + let debug_paint = std::env::var("MASONRY_DEBUG_PAINT").is_ok_and(|it| !it.is_empty()); + let mut root = Self { root: WidgetPod::new(root_widget).boxed(), size_policy, @@ -199,6 +202,7 @@ impl RenderRoot { states: TreeArena::new(), }, rebuild_access_tree: true, + debug_paint, }; if let Some(test_font_data) = test_font {