From a0e54ca238d58accd4aba2fb3e75e541dc302067 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20K=C3=A5re=20Alsaker?= Date: Sun, 5 Nov 2023 14:17:49 +0100 Subject: [PATCH] Add default for `View` trait methods --- src/view.rs | 99 ++++++++++++++++++++++++---- src/views/clip.rs | 46 ++----------- src/views/container.rs | 60 ++--------------- src/views/container_box.rs | 24 ++----- src/views/drag_resize_window_area.rs | 60 ++--------------- src/views/drag_window_area.rs | 57 ++-------------- src/views/dyn_container.rs | 46 ++----------- src/views/empty.rs | 48 +------------- src/views/img.rs | 25 ------- src/views/label.rs | 32 ++------- src/views/list.rs | 92 ++++---------------------- src/views/rich_text.rs | 23 +------ src/views/scroll.rs | 24 ++----- src/views/stack.rs | 84 ++++------------------- src/views/static_list.rs | 93 ++++---------------------- src/views/svg.rs | 29 -------- src/views/tab.rs | 62 +++++------------ src/views/text_input.rs | 16 ----- src/views/virtual_list.rs | 68 +++---------------- 19 files changed, 188 insertions(+), 800 deletions(-) diff --git a/src/view.rs b/src/view.rs index bcb26ff0..066a519a 100644 --- a/src/view.rs +++ b/src/view.rs @@ -111,6 +111,14 @@ bitflags! { pub trait View { fn id(&self) -> Id; + /// This method walk 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`. + fn for_each_child<'a>(&'a self, _for_each: &mut dyn FnMut(&'a dyn View) -> bool) {} + + /// This method walk 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`. + fn for_each_child_mut<'a>(&'a mut self, _for_each: &mut dyn FnMut(&'a mut dyn View) -> bool) {} + fn view_style(&self) -> Option