Skip to content

Commit

Permalink
Add keybinding for toggling debug paint
Browse files Browse the repository at this point in the history
Fix invalidation issues
  • Loading branch information
PoignardAzur committed Jan 14, 2025
1 parent 60cabc0 commit e40d86d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
16 changes: 15 additions & 1 deletion masonry/src/passes/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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
Expand All @@ -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;
}
}
Expand Down
4 changes: 1 addition & 3 deletions masonry/src/passes/paint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;

Expand Down
4 changes: 4 additions & 0 deletions masonry/src/render_root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -199,6 +202,7 @@ impl RenderRoot {
states: TreeArena::new(),
},
rebuild_access_tree: true,
debug_paint,
};

if let Some(test_font_data) = test_font {
Expand Down

0 comments on commit e40d86d

Please sign in to comment.