From 6b62c3fd5490105c0d94fa9928cbe856e3f83a4d Mon Sep 17 00:00:00 2001 From: Joscha Date: Tue, 5 Mar 2024 00:42:05 +0100 Subject: [PATCH] Tweak Widget naming and docs --- showbits-common/src/widget.rs | 18 ++++++++++-------- showbits-common/src/widgets/background.rs | 4 ++-- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/showbits-common/src/widget.rs b/showbits-common/src/widget.rs index 3430653..bf0ac35 100644 --- a/showbits-common/src/widget.rs +++ b/showbits-common/src/widget.rs @@ -5,15 +5,16 @@ pub trait Widget { /// constraints. fn size(&self, max_width: Option, max_height: Option) -> Vec2; - /// Recalculate the size of all inner widgets given the widget's own size. + /// Recalculate the area (size and position) of all inner widgets given the + /// widget's own area. /// /// # Implement if... /// /// - There are inner widgets - fn resize(&mut self, _area: Rect) {} + fn set_area(&mut self, _area: Rect) {} /// Perform any updates (e.g. fetching map tiles) that require the widget's - /// size and may fail. + /// area and may fail. /// /// # Implement if... /// @@ -45,7 +46,7 @@ where /// approach of `Box`. trait WidgetWrapper { fn size(&self, max_width: Option, max_height: Option) -> Vec2; - fn resize(&mut self, _area: Rect); + fn set_area(&mut self, _area: Rect); fn update(&mut self, _area: Rect) -> anyhow::Result<()>; fn draw(self: Box, view: &mut View<'_, C>); } @@ -59,8 +60,9 @@ impl> WidgetWrapper for W { Widget::size(self, max_width, max_height) } - fn resize(&mut self, area: Rect) { - Widget::resize(self, area); + fn set_area(&mut self, area: Rect) { + // Widget::set_area(self, area); + self.set_area(area); } fn update(&mut self, area: Rect) -> anyhow::Result<()> { @@ -98,9 +100,9 @@ impl BoxedWidget { self.widget.size(max_width, max_height) } - pub fn resize(&mut self, area: Rect) { + pub fn set_area(&mut self, area: Rect) { self.area = area; - self.widget.resize(area); + self.widget.set_area(area); } pub fn update(&mut self) -> anyhow::Result<()> { diff --git a/showbits-common/src/widgets/background.rs b/showbits-common/src/widgets/background.rs index 5351d80..47c48d7 100644 --- a/showbits-common/src/widgets/background.rs +++ b/showbits-common/src/widgets/background.rs @@ -16,8 +16,8 @@ impl Widget for Background { self.inner.size(max_width, max_height) } - fn resize(&mut self, area: crate::Rect) { - self.inner.resize(area); + fn set_area(&mut self, area: crate::Rect) { + self.inner.set_area(area); } fn update(&mut self, _area: crate::Rect) -> anyhow::Result<()> {