From 4b4253728fce7654887e70d63d4e33f73731669b Mon Sep 17 00:00:00 2001 From: Olivier FAURE Date: Mon, 21 Oct 2024 14:02:16 +0200 Subject: [PATCH 1/4] Replace WidgetMut methods with free functions. --- masonry/examples/calc_masonry.rs | 19 +- masonry/examples/grid_masonry.rs | 6 +- masonry/examples/to_do_list.rs | 12 +- masonry/src/widget/button.rs | 16 +- masonry/src/widget/checkbox.rs | 31 +-- masonry/src/widget/flex.rs | 253 +++++++++++++----------- masonry/src/widget/grid.rs | 135 ++++++++----- masonry/src/widget/image.rs | 16 +- masonry/src/widget/label.rs | 73 ++++--- masonry/src/widget/portal.rs | 76 +++---- masonry/src/widget/progress_bar.rs | 16 +- masonry/src/widget/prose.rs | 54 +++-- masonry/src/widget/root_widget.rs | 6 +- masonry/src/widget/scroll_bar.rs | 16 +- masonry/src/widget/sized_box.rs | 90 +++++---- masonry/src/widget/spinner.rs | 15 +- masonry/src/widget/split.rs | 48 ++--- masonry/src/widget/tests/widget_tree.rs | 2 +- masonry/src/widget/textbox.rs | 56 +++--- masonry/src/widget/variable_label.rs | 70 +++---- xilem/src/driver.rs | 2 +- xilem/src/view/button.rs | 2 +- xilem/src/view/checkbox.rs | 4 +- xilem/src/view/flex.rs | 91 +++++---- xilem/src/view/grid.rs | 44 +++-- xilem/src/view/image.rs | 4 +- xilem/src/view/label.rs | 10 +- xilem/src/view/portal.rs | 4 +- xilem/src/view/progress_bar.rs | 2 +- xilem/src/view/prose.rs | 8 +- xilem/src/view/sized_box.rs | 28 +-- xilem/src/view/spinner.rs | 4 +- xilem/src/view/textbox.rs | 8 +- xilem/src/view/variable_label.rs | 16 +- 34 files changed, 666 insertions(+), 571 deletions(-) diff --git a/masonry/examples/calc_masonry.rs b/masonry/examples/calc_masonry.rs index e0fce9565..92b2c57b0 100644 --- a/masonry/examples/calc_masonry.rs +++ b/masonry/examples/calc_masonry.rs @@ -147,7 +147,7 @@ impl Widget for CalcButton { let color = self.active_color; // See on_status_change for why we use `mutate_later` here. ctx.mutate_later(&mut self.inner, move |mut inner| { - inner.set_background(color); + SizedBox::set_background(&mut inner, color); }); ctx.capture_pointer(); trace!("CalcButton {:?} pressed", ctx.widget_id()); @@ -158,7 +158,7 @@ impl Widget for CalcButton { let color = self.base_color; // See on_status_change for why we use `mutate_later` here. ctx.mutate_later(&mut self.inner, move |mut inner| { - inner.set_background(color); + SizedBox::set_background(&mut inner, color); }); ctx.submit_action(Action::Other(Box::new(self.action))); trace!("CalcButton {:?} released", ctx.widget_id()); @@ -190,7 +190,7 @@ impl Widget for CalcButton { match event { Update::HoveredChanged(true) => { ctx.mutate_later(&mut self.inner, move |mut inner| { - inner.set_border(Color::WHITE, 3.0); + SizedBox::set_border(&mut inner, Color::WHITE, 3.0); }); // FIXME - This is a monkey-patch for a problem where the mutate pass isn't run after this. // Should be fixed once the pass spec RFC is implemented. @@ -198,7 +198,7 @@ impl Widget for CalcButton { } Update::HoveredChanged(false) => { ctx.mutate_later(&mut self.inner, move |mut inner| { - inner.set_border(Color::TRANSPARENT, 3.0); + SizedBox::set_border(&mut inner, Color::TRANSPARENT, 3.0); }); // FIXME - This is a monkey-patch for a problem where the mutate pass isn't run after this. // Should be fixed once the pass spec RFC is implemented. @@ -254,12 +254,11 @@ impl AppDriver for CalcState { _ => unreachable!(), } - ctx.get_root::>() - .child_mut() - .child_mut(1) - .unwrap() - .downcast::