Skip to content

Commit

Permalink
Correctly pass the HAS_ACTIVE state up (#148)
Browse files Browse the repository at this point in the history
* 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)

* Add a comment on suspect is_active
  • Loading branch information
DJMcNab authored Nov 21, 2023
1 parent 21d6579 commit cd2f129
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/widget/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
}
}
Expand Down Expand Up @@ -545,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)
}
Expand Down

0 comments on commit cd2f129

Please sign in to comment.