From 335df2028d2c15b81b3d7a4c6e49984152ea1963 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 9 Nov 2022 23:53:26 +0100 Subject: Introduce `scoped` in `widget::operation` --- native/src/widget/operation.rs | 43 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'native/src/widget/operation.rs') diff --git a/native/src/widget/operation.rs b/native/src/widget/operation.rs index ef636aa2..dd6b3c54 100644 --- a/native/src/widget/operation.rs +++ b/native/src/widget/operation.rs @@ -58,3 +58,46 @@ where } } } + +/// Produces an [`Operation`] that applies the given [`Operation`] to the +/// children of a container with the given [`Id`]. +pub fn scoped( + target: Id, + operation: impl Operation + 'static, +) -> impl Operation { + struct ScopedOperation { + target: Id, + operation: Box>, + } + + impl Operation for ScopedOperation { + fn container( + &mut self, + id: Option<&Id>, + operate_on_children: &mut dyn FnMut(&mut dyn Operation), + ) { + if id == Some(&self.target) { + operate_on_children(self.operation.as_mut()); + } else { + operate_on_children(self); + } + } + + fn finish(&self) -> Outcome { + match self.operation.finish() { + Outcome::Chain(next) => { + Outcome::Chain(Box::new(ScopedOperation { + target: self.target.clone(), + operation: next, + })) + } + outcome => outcome, + } + } + } + + ScopedOperation { + target: target.into(), + operation: Box::new(operation), + } +} -- cgit From bec1f5bbe0e0fec0d57b66ee227c41f15165057e Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 10 Nov 2022 00:17:27 +0100 Subject: Remove unnecessary `into` call in `operation::scoped` --- native/src/widget/operation.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'native/src/widget/operation.rs') diff --git a/native/src/widget/operation.rs b/native/src/widget/operation.rs index dd6b3c54..2b1179f1 100644 --- a/native/src/widget/operation.rs +++ b/native/src/widget/operation.rs @@ -97,7 +97,7 @@ pub fn scoped( } ScopedOperation { - target: target.into(), + target, operation: Box::new(operation), } } -- cgit From c4bca3f2af7ae9b2c8dfc3af48ab73dad852ed34 Mon Sep 17 00:00:00 2001 From: Cory Forsstrom Date: Fri, 11 Nov 2022 08:43:36 -0800 Subject: Add text input operations --- native/src/widget/operation.rs | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'native/src/widget/operation.rs') diff --git a/native/src/widget/operation.rs b/native/src/widget/operation.rs index 2b1179f1..a0aa4117 100644 --- a/native/src/widget/operation.rs +++ b/native/src/widget/operation.rs @@ -1,9 +1,11 @@ //! Query or update internal widget state. pub mod focusable; pub mod scrollable; +pub mod text_input; pub use focusable::Focusable; pub use scrollable::Scrollable; +pub use text_input::TextInput; use crate::widget::Id; @@ -28,6 +30,9 @@ pub trait Operation { /// Operates on a widget that can be scrolled. fn scrollable(&mut self, _state: &mut dyn Scrollable, _id: Option<&Id>) {} + /// Operates on a widget that has text input. + fn text_input(&mut self, _state: &mut dyn TextInput, _id: Option<&Id>) {} + /// Finishes the [`Operation`] and returns its [`Outcome`]. fn finish(&self) -> Outcome { Outcome::None -- cgit