summaryrefslogtreecommitdiffstats
path: root/native/src/widget/operation.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2022-07-28 02:46:51 +0200
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2022-07-28 02:46:51 +0200
commit80688689aa4b15bc23824df899974a9094a77b07 (patch)
treebbfce1c91b9ee22990503a55d31d04cadf4093b7 /native/src/widget/operation.rs
parenta003e797e8a1bb5d365c1db5de6af88e61a47329 (diff)
downloadiced-80688689aa4b15bc23824df899974a9094a77b07.tar.gz
iced-80688689aa4b15bc23824df899974a9094a77b07.tar.bz2
iced-80688689aa4b15bc23824df899974a9094a77b07.zip
Draft widget operations
Diffstat (limited to '')
-rw-r--r--native/src/widget/operation.rs62
1 files changed, 62 insertions, 0 deletions
diff --git a/native/src/widget/operation.rs b/native/src/widget/operation.rs
new file mode 100644
index 00000000..b6c108e0
--- /dev/null
+++ b/native/src/widget/operation.rs
@@ -0,0 +1,62 @@
+use crate::widget::state;
+use crate::widget::Id;
+
+pub trait Operation<T> {
+ fn container(
+ &mut self,
+ id: Option<&Id>,
+ operate_on_children: &dyn Fn(&mut dyn Operation<T>),
+ );
+
+ fn focusable(
+ &mut self,
+ _state: &mut dyn state::Focusable,
+ _id: Option<&Id>,
+ ) {
+ }
+
+ fn finish(&self) -> Outcome<T> {
+ Outcome::None
+ }
+}
+
+pub enum Outcome<T> {
+ None,
+ Some(T),
+ Chain(Box<dyn Operation<T>>),
+}
+
+pub fn focus<T>(target: Id) -> impl Operation<T> {
+ struct Focus {
+ target: Id,
+ }
+
+ impl<T> Operation<T> for Focus {
+ fn focusable(
+ &mut self,
+ state: &mut dyn state::Focusable,
+ id: Option<&Id>,
+ ) {
+ if state.is_focused() {
+ match id {
+ Some(id) if id == &self.target => {
+ state.focus();
+ }
+ _ => {
+ state.unfocus();
+ }
+ }
+ }
+ }
+
+ fn container(
+ &mut self,
+ _id: Option<&Id>,
+ operate_on_children: &dyn Fn(&mut dyn Operation<T>),
+ ) {
+ operate_on_children(self)
+ }
+ }
+
+ Focus { target }
+}