improv: PreOperation for tracking children in selections
This commit is contained in:
parent
880f2c7565
commit
2e12eba5cd
5 changed files with 49 additions and 1 deletions
|
|
@ -78,6 +78,9 @@ pub trait Operation<T = ()>: Send {
|
||||||
|
|
||||||
/// Track the active window id being processed if relevant to the operation
|
/// Track the active window id being processed if relevant to the operation
|
||||||
fn set_window_id(&mut self, _id: window::Id) {}
|
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>
|
impl<T, O> Operation<O> for Box<T>
|
||||||
|
|
@ -147,6 +150,10 @@ where
|
||||||
fn set_window_id(&mut self, id: window::Id) {
|
fn set_window_id(&mut self, id: window::Id) {
|
||||||
self.as_mut().set_window_id(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`].
|
/// The result of an [`Operation`].
|
||||||
|
|
@ -251,6 +258,10 @@ where
|
||||||
Outcome::None
|
Outcome::None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn pre_operation(&mut self, id: Option<&Id>) {
|
||||||
|
self.operation.pre_operation(id);
|
||||||
|
}
|
||||||
|
|
||||||
fn set_window_id(&mut self, id: window::Id) {
|
fn set_window_id(&mut self, id: window::Id) {
|
||||||
self.operation.set_window_id(id);
|
self.operation.set_window_id(id);
|
||||||
}
|
}
|
||||||
|
|
@ -352,6 +363,10 @@ where
|
||||||
) {
|
) {
|
||||||
self.operation.custom(id, bounds, state);
|
self.operation.custom(id, bounds, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn pre_operation(&mut self, id: Option<&Id>) {
|
||||||
|
self.operation.pre_operation(id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.operation.traverse(&mut |operation| {
|
self.operation.traverse(&mut |operation| {
|
||||||
|
|
@ -425,6 +440,10 @@ where
|
||||||
fn set_window_id(&mut self, id: window::Id) {
|
fn set_window_id(&mut self, id: window::Id) {
|
||||||
self.operation.set_window_id(id);
|
self.operation.set_window_id(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn pre_operation(&mut self, id: Option<&Id>) {
|
||||||
|
self.operation.pre_operation(id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Map {
|
Map {
|
||||||
|
|
@ -534,6 +553,10 @@ where
|
||||||
fn set_window_id(&mut self, id: window::Id) {
|
fn set_window_id(&mut self, id: window::Id) {
|
||||||
self.operation.set_window_id(id);
|
self.operation.set_window_id(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn pre_operation(&mut self, id: Option<&Id>) {
|
||||||
|
self.operation.pre_operation(id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Chain {
|
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) {
|
fn set_window_id(&mut self, id: window::Id) {
|
||||||
self.operation.set_window_id(id);
|
self.operation.set_window_id(id);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -285,4 +285,8 @@ where
|
||||||
fn set_window_id(&mut self, id: window::Id) {
|
fn set_window_id(&mut self, id: window::Id) {
|
||||||
self.strategy.set_window_id(id);
|
self.strategy.set_window_id(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn pre_operation(&mut self, id: Option<&Id>) {
|
||||||
|
self.strategy.feed(Candidate::PreOperation { id });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -193,6 +193,8 @@ pub fn focus() -> impl Selector<Output = (bool, Target, window::Id)> {
|
||||||
))
|
))
|
||||||
} else if matches!(candidate, Candidate::Scrollable { .. }) {
|
} else if matches!(candidate, Candidate::Scrollable { .. }) {
|
||||||
Some((false, Target::from(candidate), self.cur_window_id))
|
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 {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,9 @@ pub enum Target {
|
||||||
bounds: Rectangle,
|
bounds: Rectangle,
|
||||||
visible_bounds: Option<Rectangle>,
|
visible_bounds: Option<Rectangle>,
|
||||||
},
|
},
|
||||||
|
PreOperation {
|
||||||
|
id: Option<Id>,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Target {
|
impl Target {
|
||||||
|
|
@ -54,6 +57,7 @@ impl Target {
|
||||||
| Target::TextInput { bounds, .. }
|
| Target::TextInput { bounds, .. }
|
||||||
| Target::Text { bounds, .. }
|
| Target::Text { bounds, .. }
|
||||||
| Target::Custom { bounds, .. } => *bounds,
|
| Target::Custom { bounds, .. } => *bounds,
|
||||||
|
Target::PreOperation { .. } => Rectangle::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -66,6 +70,7 @@ impl Target {
|
||||||
| Target::TextInput { visible_bounds, .. }
|
| Target::TextInput { visible_bounds, .. }
|
||||||
| Target::Text { visible_bounds, .. }
|
| Target::Text { visible_bounds, .. }
|
||||||
| Target::Custom { visible_bounds, .. } => *visible_bounds,
|
| Target::Custom { visible_bounds, .. } => *visible_bounds,
|
||||||
|
Target::PreOperation { .. } => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -138,6 +143,9 @@ impl From<Candidate<'_>> for Target {
|
||||||
bounds,
|
bounds,
|
||||||
visible_bounds,
|
visible_bounds,
|
||||||
},
|
},
|
||||||
|
Candidate::PreOperation { id } => {
|
||||||
|
Self::PreOperation { id: id.cloned() }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -195,6 +203,8 @@ pub enum Candidate<'a> {
|
||||||
visible_bounds: Option<Rectangle>,
|
visible_bounds: Option<Rectangle>,
|
||||||
state: &'a dyn Any,
|
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> {
|
impl<'a> Candidate<'a> {
|
||||||
|
|
@ -206,7 +216,8 @@ impl<'a> Candidate<'a> {
|
||||||
| Candidate::Scrollable { id, .. }
|
| Candidate::Scrollable { id, .. }
|
||||||
| Candidate::TextInput { id, .. }
|
| Candidate::TextInput { id, .. }
|
||||||
| Candidate::Text { 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::TextInput { bounds, .. }
|
||||||
| Candidate::Text { bounds, .. }
|
| Candidate::Text { bounds, .. }
|
||||||
| Candidate::Custom { bounds, .. } => *bounds,
|
| Candidate::Custom { bounds, .. } => *bounds,
|
||||||
|
Candidate::PreOperation { .. } => Rectangle::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -231,6 +243,7 @@ impl<'a> Candidate<'a> {
|
||||||
| Candidate::TextInput { visible_bounds, .. }
|
| Candidate::TextInput { visible_bounds, .. }
|
||||||
| Candidate::Text { visible_bounds, .. }
|
| Candidate::Text { visible_bounds, .. }
|
||||||
| Candidate::Custom { visible_bounds, .. } => *visible_bounds,
|
| Candidate::Custom { visible_bounds, .. } => *visible_bounds,
|
||||||
|
Candidate::PreOperation { .. } => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -676,6 +676,8 @@ where
|
||||||
let translation =
|
let translation =
|
||||||
state.translation(self.direction, bounds, content_bounds);
|
state.translation(self.direction, bounds, content_bounds);
|
||||||
|
|
||||||
|
operation.pre_operation(Some(&self.id));
|
||||||
|
|
||||||
operation.traverse(&mut |operation| {
|
operation.traverse(&mut |operation| {
|
||||||
self.content.as_widget_mut().operate(
|
self.content.as_widget_mut().operate(
|
||||||
&mut tree.children[0],
|
&mut tree.children[0],
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue