From a05e3a7fab5f160d52a60e93b1cc9a484a52ec4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20K=C3=A5re=20Alsaker?= Date: Tue, 14 Nov 2023 17:37:22 +0100 Subject: [PATCH 1/2] Add `ViewData` for internal view owned state --- src/view.rs | 32 +++++++++++-- src/views/clip.rs | 21 ++++++--- src/views/container.rs | 17 +++++-- src/views/container_box.rs | 17 +++++-- src/views/drag_resize_window_area.rs | 17 +++++-- src/views/drag_window_area.rs | 14 ++++-- src/views/dyn_container.rs | 16 ++++--- src/views/empty.rs | 19 ++++++-- src/views/img.rs | 23 ++++++--- src/views/label.rs | 20 ++++---- src/views/list.rs | 16 ++++--- src/views/rich_text.rs | 18 ++++--- src/views/scroll.rs | 70 +++++++++++++++------------- src/views/stack.rs | 29 +++++++----- src/views/static_list.rs | 18 +++++-- src/views/svg.rs | 21 ++++++--- src/views/tab.rs | 16 ++++--- src/views/text_input.rs | 34 ++++++++------ src/views/virtual_list.rs | 20 ++++---- src/widgets/slider.rs | 20 ++++---- src/widgets/toggle_button.rs | 22 +++++---- 21 files changed, 309 insertions(+), 171 deletions(-) diff --git a/src/view.rs b/src/view.rs index 674b052c..77e4c51c 100644 --- a/src/view.rs +++ b/src/view.rs @@ -97,7 +97,8 @@ use crate::{ }; pub trait View { - fn id(&self) -> Id; + fn view_data(&self) -> &ViewData; + fn view_data_mut(&mut self) -> &mut ViewData; /// This method walks over children and must be implemented if the view has any children. /// It should return children back to front and should stop if `_for_each` returns `true`. @@ -115,6 +116,10 @@ pub trait View { ) { } + fn id(&self) -> Id { + self.view_data().id() + } + fn view_style(&self) -> Option