diff options
author | 2022-02-09 19:42:15 +0700 | |
---|---|---|
committer | 2022-02-09 19:42:15 +0700 | |
commit | 8f0839e786f8d521f7319dd0e188d43284f526b7 (patch) | |
tree | 6d902f1f28f02842134c0a07139d7aa9dae5eb80 /virtual/src/widget.rs | |
parent | adce9e04213803bd775538efddf6e7908d1c605e (diff) | |
download | iced-8f0839e786f8d521f7319dd0e188d43284f526b7.tar.gz iced-8f0839e786f8d521f7319dd0e188d43284f526b7.tar.bz2 iced-8f0839e786f8d521f7319dd0e188d43284f526b7.zip |
Draft `iced_virtual` subcrate
The idea here is to expose a set of "virtual widgets" that can be used with a
`Virtual` widget and its `virtual::State`.
A virtual widget is a widget that does not contain any state, but instead is a
"virtual" representation of the "real" widget. The real widgets are stored in
the `virtual::State`.
Every time a new virtual widget tree is created during `view`, it is compared to
the previous one and "real" widgets are added / removed to the `virtual::State`.
Effectively, this removes the need to keep track of local widget state in the
application state and allows `view` to take an immutable reference to `self`.
To summarize, using this crate should allow users to remove `State` structs
in their application state.
Eventually, the strategy used here may be adopted generally and, as a result,
all of the widgets in `iced_native` would be replaced!
Diffstat (limited to '')
-rw-r--r-- | virtual/src/widget.rs | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/virtual/src/widget.rs b/virtual/src/widget.rs new file mode 100644 index 00000000..f8697bc0 --- /dev/null +++ b/virtual/src/widget.rs @@ -0,0 +1,52 @@ +mod button; + +pub use button::Button; + +use iced_native::layout::{self, Layout}; +use iced_native::renderer; +use iced_native::{Hasher, Length, Point, Rectangle}; + +pub trait Widget<Message, Renderer> {} + +pub(crate) enum Tree<Message, Renderer> { + Node { + widget: Box<dyn Widget<Message, Renderer>>, + children: Vec<Tree<Message, Renderer>>, + }, + Leaf { + widget: Box<dyn Widget<Message, Renderer>>, + }, +} + +impl<Message, Renderer> Tree<Message, Renderer> { + pub fn width(&self) -> Length { + unimplemented! {} + } + + pub fn height(&self) -> Length { + unimplemented! {} + } + + pub fn hash_layout(&self, state: &mut Hasher) { + unimplemented! {} + } + + pub fn layout( + &self, + renderer: &Renderer, + limits: &layout::Limits, + ) -> layout::Node { + unimplemented! {} + } + + pub fn draw( + &self, + renderer: &mut Renderer, + style: &renderer::Style, + layout: Layout<'_>, + cursor_position: Point, + viewport: &Rectangle, + ) { + unimplemented! {} + } +} |