summaryrefslogtreecommitdiffstats
path: root/pure/src/widget/tree.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2022-02-12 15:17:44 +0700
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2022-02-12 15:18:31 +0700
commitb2670e8752eb96a4018f93b9cb8945da81a7ebff (patch)
treeb7bf46a5e3b2363444500f5801763b2562d48af1 /pure/src/widget/tree.rs
parent178914ec23a107cb7fa38c39be30a35d235248ab (diff)
downloadiced-b2670e8752eb96a4018f93b9cb8945da81a7ebff.tar.gz
iced-b2670e8752eb96a4018f93b9cb8945da81a7ebff.tar.bz2
iced-b2670e8752eb96a4018f93b9cb8945da81a7ebff.zip
Implement `Scrollable` in `iced_pure`
Diffstat (limited to 'pure/src/widget/tree.rs')
-rw-r--r--pure/src/widget/tree.rs18
1 files changed, 11 insertions, 7 deletions
diff --git a/pure/src/widget/tree.rs b/pure/src/widget/tree.rs
index 1ab6d80b..98e976ad 100644
--- a/pure/src/widget/tree.rs
+++ b/pure/src/widget/tree.rs
@@ -4,7 +4,7 @@ use std::any::{self, Any};
pub struct Tree {
pub tag: any::TypeId,
- pub state: Box<dyn Any>,
+ pub state: State,
pub children: Vec<Tree>,
}
@@ -12,7 +12,7 @@ impl Tree {
pub fn empty() -> Self {
Self {
tag: any::TypeId::of::<()>(),
- state: Box::new(()),
+ state: State(Box::new(())),
children: Vec::new(),
}
}
@@ -22,7 +22,7 @@ impl Tree {
) -> Self {
Self {
tag: element.as_widget().tag(),
- state: element.as_widget().state(),
+ state: State(element.as_widget().state()),
children: element
.as_widget()
.children()
@@ -58,18 +58,22 @@ impl Tree {
*self = Self::new(new);
}
}
+}
+
+pub struct State(Box<dyn Any>);
- pub fn state<T>(&self) -> &T
+impl State {
+ pub fn downcast_ref<T>(&self) -> &T
where
T: 'static,
{
- self.state.downcast_ref().expect("Downcast widget state")
+ self.0.downcast_ref().expect("Downcast widget state")
}
- pub fn state_mut<T>(&mut self) -> &mut T
+ pub fn downcast_mut<T>(&mut self) -> &mut T
where
T: 'static,
{
- self.state.downcast_mut().expect("Downcast widget state")
+ self.0.downcast_mut().expect("Downcast widget state")
}
}