Invalidate widget tree from Responsive widget
... by introducing a new `invalidate_widgets` method to `Shell`
This commit is contained in:
parent
90c20ac46b
commit
6ab4611a6e
8 changed files with 85 additions and 33 deletions
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue