diff options
author | 2022-01-11 13:47:43 +0700 | |
---|---|---|
committer | 2022-01-11 13:47:43 +0700 | |
commit | 6ab4611a6eec9c4bb4ca1ff1bb580bb7edf49add (patch) | |
tree | c96d3eb77ffe99a580ed13efecc50d2857f1b8f0 /native/src/shell.rs | |
parent | 90c20ac46b72b6d8f735f7efd283b9d1dfecfb9d (diff) | |
download | iced-6ab4611a6eec9c4bb4ca1ff1bb580bb7edf49add.tar.gz iced-6ab4611a6eec9c4bb4ca1ff1bb580bb7edf49add.tar.bz2 iced-6ab4611a6eec9c4bb4ca1ff1bb580bb7edf49add.zip |
Invalidate widget tree from `Responsive` widget
... by introducing a new `invalidate_widgets` method to `Shell`
Diffstat (limited to 'native/src/shell.rs')
-rw-r--r-- | native/src/shell.rs | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/native/src/shell.rs b/native/src/shell.rs index e916f52d..4a0aa9c6 100644 --- a/native/src/shell.rs +++ b/native/src/shell.rs @@ -8,6 +8,7 @@ pub struct Shell<'a, Message> { messages: &'a mut Vec<Message>, is_layout_invalid: bool, + are_widgets_invalid: bool, } impl<'a, Message> Shell<'a, Message> { @@ -16,12 +17,13 @@ impl<'a, Message> Shell<'a, Message> { Self { messages, is_layout_invalid: false, + are_widgets_invalid: false, } } /// Triggers the given function if the layout is invalid, cleaning it in the /// process. - pub fn with_invalid_layout(&mut self, f: impl FnOnce()) { + pub fn revalidate_layout(&mut self, f: impl FnOnce()) { if self.is_layout_invalid { self.is_layout_invalid = false; @@ -41,6 +43,13 @@ impl<'a, Message> Shell<'a, Message> { self.is_layout_invalid = true; } + /// Invalidates the current application widgets. + /// + /// The shell will rebuild and relayout the widget tree. + pub fn invalidate_widgets(&mut self) { + self.are_widgets_invalid = true; + } + /// Merges the current [`Shell`] with another one by applying the given /// function to the messages of the latter. /// @@ -50,5 +59,14 @@ impl<'a, Message> Shell<'a, Message> { self.is_layout_invalid = self.is_layout_invalid || other.is_layout_invalid; + + self.are_widgets_invalid = + self.are_widgets_invalid || other.are_widgets_invalid; + } + + /// Returns whether the widgets of the current application have been + /// invalidated. + pub fn are_widgets_invalid(&self) -> bool { + self.are_widgets_invalid } } |