From e89628b3cfd90e30bdca74013d0557c6dc0aac52 Mon Sep 17 00:00:00 2001 From: Daniel McNab <36049421+DJMcNab@users.noreply.github.com> Date: Tue, 21 Nov 2023 10:24:56 +0100 Subject: [PATCH 1/2] Correctly pass the `HAS_ACTIVE` state up Previously, this was being overwritten by each widget as the event went up the tree, so only the root widget could be active This aligns this code with the druid version (see https://github.com/linebender/druid/blob/e53a5ab72c40191b3f92edef9ebf4da07da254f3/druid/src/core.rs#L812) --- src/widget/core.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/widget/core.rs b/src/widget/core.rs index 872a53486..7421651a2 100644 --- a/src/widget/core.rs +++ b/src/widget/core.rs @@ -285,6 +285,14 @@ impl Pod { } }; if recurse { + // This clears the has_active state. Pod needs to clear this state since merge up can + // only set flags. + // This needs to happen before the `event` call, as that will also set our `HAS_ACTIVE` + // flag if any of our children were active + self.state.flags.set( + PodFlags::HAS_ACTIVE, + self.state.flags.contains(PodFlags::IS_ACTIVE), + ); let mut inner_cx = EventCx { cx_state: cx.cx_state, widget_state: &mut self.state, @@ -294,12 +302,6 @@ impl Pod { .event(&mut inner_cx, modified_event.as_ref().unwrap_or(event)); cx.is_handled |= inner_cx.is_handled; - // This clears the has_active state. Pod needs to clear this state since merge up can - // only set flags. - self.state.flags.set( - PodFlags::HAS_ACTIVE, - self.state.flags.contains(PodFlags::IS_ACTIVE), - ); cx.widget_state.merge_up(&mut self.state); } } From 0085ae5caba910d1ef4fae04b17e818ea0996e37 Mon Sep 17 00:00:00 2001 From: Daniel McNab <36049421+DJMcNab@users.noreply.github.com> Date: Tue, 21 Nov 2023 10:30:54 +0100 Subject: [PATCH 2/2] Add a comment on suspect is_active --- src/widget/core.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/widget/core.rs b/src/widget/core.rs index 7421651a2..8491fddcc 100644 --- a/src/widget/core.rs +++ b/src/widget/core.rs @@ -547,6 +547,7 @@ impl Pod { /// is dragged away. /// /// [`set_active`]: EventCx::set_active + // TODO: Determine why this is the same as [Self::has_active] pub fn is_active(&self) -> bool { self.state.flags.contains(PodFlags::HAS_ACTIVE) }