improv: PreOperation for tracking children in selections

This commit is contained in:
Ashley Wulber 2026-09-04 14:31:46 -04:00 • committed by Ashley Wulber
parent 880f2c7565
commit 2e12eba5cd
5 changed files with 49 additions and 1 deletions

View file

@ -78,6 +78,9 @@ pub trait Operation<T = ()>: Send {
/// Track the active window id being processed if relevant to the operation
fn set_window_id(&mut self, _id: window::Id) {}
/// Used to mark the beginning of operations for a widget and its children
fn pre_operation(&mut self, _id: Option<&Id>) {}
}
impl<T, O> Operation<O> for Box<T>
@ -147,6 +150,10 @@ where
fn set_window_id(&mut self, id: window::Id) {
self.as_mut().set_window_id(id);
}
fn pre_operation(&mut self, id: Option<&Id>) {
self.as_mut().pre_operation(id);
}
}
/// The result of an [`Operation`].
@ -251,6 +258,10 @@ where
Outcome::None
}
fn pre_operation(&mut self, id: Option<&Id>) {
self.operation.pre_operation(id);
}
fn set_window_id(&mut self, id: window::Id) {
self.operation.set_window_id(id);
}
@ -352,6 +363,10 @@ where
) {
self.operation.custom(id, bounds, state);
}
fn pre_operation(&mut self, id: Option<&Id>) {
self.operation.pre_operation(id);
}
}
self.operation.traverse(&mut |operation| {
@ -425,6 +440,10 @@ where
fn set_window_id(&mut self, id: window::Id) {
self.operation.set_window_id(id);
}
fn pre_operation(&mut self, id: Option<&Id>) {
self.operation.pre_operation(id);
}
}
Map {
@ -534,6 +553,10 @@ where
fn set_window_id(&mut self, id: window::Id) {
self.operation.set_window_id(id);
}
fn pre_operation(&mut self, id: Option<&Id>) {
self.operation.pre_operation(id);
}
}
Chain {
@ -586,6 +609,10 @@ pub fn scoped<T: 'static>(
}
}
fn pre_operation(&mut self, id: Option<&Id>) {
self.operation.pre_operation(id);
}
fn set_window_id(&mut self, id: window::Id) {
self.operation.set_window_id(id);
}

View file

@ -285,4 +285,8 @@ where
fn set_window_id(&mut self, id: window::Id) {
self.strategy.set_window_id(id);
}
fn pre_operation(&mut self, id: Option<&Id>) {
self.strategy.feed(Candidate::PreOperation { id });
}
}

View file

@ -193,6 +193,8 @@ pub fn focus() -> impl Selector<Output = (bool, Target, window::Id)> {
))
} else if matches!(candidate, Candidate::Scrollable { .. }) {
Some((false, Target::from(candidate), self.cur_window_id))
} else if matches!(candidate, Candidate::PreOperation { .. }) {
Some((false, Target::from(candidate), self.cur_window_id))
} else {
None
}

View file

@ -42,6 +42,9 @@ pub enum Target {
bounds: Rectangle,
visible_bounds: Option<Rectangle>,
},
PreOperation {
id: Option<Id>,
},
}
impl Target {
@ -54,6 +57,7 @@ impl Target {
| Target::TextInput { bounds, .. }
| Target::Text { bounds, .. }
| Target::Custom { bounds, .. } => *bounds,
Target::PreOperation { .. } => Rectangle::default(),
}
}
@ -66,6 +70,7 @@ impl Target {
| Target::TextInput { visible_bounds, .. }
| Target::Text { visible_bounds, .. }
| Target::Custom { visible_bounds, .. } => *visible_bounds,
Target::PreOperation { .. } => None,
}
}
}
@ -138,6 +143,9 @@ impl From<Candidate<'_>> for Target {
bounds,
visible_bounds,
},
Candidate::PreOperation { id } => {
Self::PreOperation { id: id.cloned() }
}
}
}
}
@ -195,6 +203,8 @@ pub enum Candidate<'a> {
visible_bounds: Option<Rectangle>,
state: &'a dyn Any,
},
/// Used to mark the beginning of operations for a widget and its children
PreOperation { id: Option<&'a Id> },
}
impl<'a> Candidate<'a> {
@ -206,7 +216,8 @@ impl<'a> Candidate<'a> {
| Candidate::Scrollable { id, .. }
| Candidate::TextInput { id, .. }
| Candidate::Text { id, .. }
| Candidate::Custom { id, .. } => *id,
| Candidate::Custom { id, .. }
| Candidate::PreOperation { id } => *id,
}
}
@ -219,6 +230,7 @@ impl<'a> Candidate<'a> {
| Candidate::TextInput { bounds, .. }
| Candidate::Text { bounds, .. }
| Candidate::Custom { bounds, .. } => *bounds,
Candidate::PreOperation { .. } => Rectangle::default(),
}
}
@ -231,6 +243,7 @@ impl<'a> Candidate<'a> {
| Candidate::TextInput { visible_bounds, .. }
| Candidate::Text { visible_bounds, .. }
| Candidate::Custom { visible_bounds, .. } => *visible_bounds,
Candidate::PreOperation { .. } => None,
}
}
}

View file

@ -676,6 +676,8 @@ where
let translation =
state.translation(self.direction, bounds, content_bounds);
operation.pre_operation(Some(&self.id));
operation.traverse(&mut |operation| {
self.content.as_widget_mut().operate(
&mut tree.children[0],