From 32d6fffd3b0ae01befbcc82bc495a135c0b53493 Mon Sep 17 00:00:00 2001 From: Jonathan Johnson Date: Fri, 29 Dec 2023 13:59:28 -0800 Subject: [PATCH] WidgetRef::unmount_in This should be all the locations that WidgetRef::unmount_in should be called. --- src/widgets/button.rs | 4 ++++ src/widgets/container.rs | 4 ++++ src/widgets/custom.rs | 2 ++ src/widgets/disclose.rs | 31 +++++++++++++++++-------------- src/widgets/label.rs | 5 +---- src/widgets/scroll.rs | 4 ++++ 6 files changed, 32 insertions(+), 18 deletions(-) diff --git a/src/widgets/button.rs b/src/widgets/button.rs index 936266c..aaa1506 100644 --- a/src/widgets/button.rs +++ b/src/widgets/button.rs @@ -541,6 +541,10 @@ impl Widget for Button { fn deactivate(&mut self, context: &mut EventContext<'_, '_>) { self.update_colors(context, false); } + + fn unmounted(&mut self, context: &mut EventContext<'_, '_>) { + self.content.unmount_in(context); + } } define_components! { diff --git a/src/widgets/container.rs b/src/widgets/container.rs index 5c814ac..2e7555f 100644 --- a/src/widgets/container.rs +++ b/src/widgets/container.rs @@ -206,6 +206,10 @@ impl Widget for Container { .finish() } + fn unmounted(&mut self, context: &mut EventContext<'_, '_>) { + self.child.unmount_in(context); + } + fn full_control_redraw(&self) -> bool { true } diff --git a/src/widgets/custom.rs b/src/widgets/custom.rs index f25aa84..2b16eba 100644 --- a/src/widgets/custom.rs +++ b/src/widgets/custom.rs @@ -527,6 +527,8 @@ impl WrapperWidget for Custom { fn unmounted(&mut self, context: &mut EventContext<'_, '_>) { if let Some(unmounted) = &mut self.unmounted { unmounted.invoke(context); + } else { + self.child_mut().unmount_in(context); } } diff --git a/src/widgets/disclose.rs b/src/widgets/disclose.rs index 3f31839..0e8204a 100644 --- a/src/widgets/disclose.rs +++ b/src/widgets/disclose.rs @@ -10,7 +10,7 @@ use kludgine::{Color, DrawableExt}; use super::button::{ButtonActiveBackground, ButtonBackground, ButtonHoverBackground}; use crate::animation::{AnimationHandle, AnimationTarget, Spawn}; -use crate::context::LayoutContext; +use crate::context::{EventContext, LayoutContext}; use crate::styles::components::{HighlightColor, IntrinsicPadding, LineHeight, OutlineColor}; use crate::styles::Dimension; use crate::value::{Dynamic, IntoDynamic, IntoValue, Value}; @@ -161,6 +161,13 @@ impl DiscloseIndicator { } impl Widget for DiscloseIndicator { + fn unmounted(&mut self, context: &mut EventContext<'_, '_>) { + if let Some(label) = &mut self.label { + label.unmount_in(context); + } + self.contents.unmount_in(context); + } + fn redraw(&mut self, context: &mut crate::context::GraphicsContext<'_, '_, '_, '_, '_>) { let angle = self.angle.get_tracking_redraw(context); let (color, stroke_color) = self.effective_colors(context); @@ -263,23 +270,19 @@ impl Widget for DiscloseIndicator { ) } - fn accept_focus(&mut self, _context: &mut crate::context::EventContext<'_, '_>) -> bool { + fn accept_focus(&mut self, _context: &mut EventContext<'_, '_>) -> bool { true } - fn focus(&mut self, context: &mut crate::context::EventContext<'_, '_>) { + fn focus(&mut self, context: &mut EventContext<'_, '_>) { context.set_needs_redraw(); } - fn blur(&mut self, context: &mut crate::context::EventContext<'_, '_>) { + fn blur(&mut self, context: &mut EventContext<'_, '_>) { context.set_needs_redraw(); } - fn hit_test( - &mut self, - location: Point, - context: &mut crate::context::EventContext<'_, '_>, - ) -> bool { + fn hit_test(&mut self, location: Point, context: &mut EventContext<'_, '_>) -> bool { let size = context .get(&IndicatorSize) .into_px(context.kludgine.scale()) @@ -296,7 +299,7 @@ impl Widget for DiscloseIndicator { fn hover( &mut self, location: Point, - context: &mut crate::context::EventContext<'_, '_>, + context: &mut EventContext<'_, '_>, ) -> Option { let hovering = self.hit_test(location, context); if self.hovering_indicator != hovering { @@ -307,7 +310,7 @@ impl Widget for DiscloseIndicator { hovering.then_some(CursorIcon::Pointer) } - fn unhover(&mut self, context: &mut crate::context::EventContext<'_, '_>) { + fn unhover(&mut self, context: &mut EventContext<'_, '_>) { if self.hovering_indicator { self.hovering_indicator = false; context.set_needs_redraw(); @@ -319,7 +322,7 @@ impl Widget for DiscloseIndicator { location: Point, _device_id: kludgine::app::winit::event::DeviceId, _button: kludgine::app::winit::event::MouseButton, - context: &mut crate::context::EventContext<'_, '_>, + context: &mut EventContext<'_, '_>, ) -> EventHandling { if self.hit_test(location, context) { self.mouse_buttons_pressed += 1; @@ -336,7 +339,7 @@ impl Widget for DiscloseIndicator { _location: Option>, _device_id: kludgine::app::winit::event::DeviceId, _button: kludgine::app::winit::event::MouseButton, - context: &mut crate::context::EventContext<'_, '_>, + context: &mut EventContext<'_, '_>, ) { self.mouse_buttons_pressed -= 1; if self.mouse_buttons_pressed == 0 { @@ -345,7 +348,7 @@ impl Widget for DiscloseIndicator { } } - fn activate(&mut self, _context: &mut crate::context::EventContext<'_, '_>) { + fn activate(&mut self, _context: &mut EventContext<'_, '_>) { if self.mouse_buttons_pressed == 0 { self.collapsed.toggle(); } diff --git a/src/widgets/label.rs b/src/widgets/label.rs index 1331f91..b05833e 100644 --- a/src/widgets/label.rs +++ b/src/widgets/label.rs @@ -41,10 +41,7 @@ impl Label { if prepared.can_render_to(&context.gfx) && *prepared_generation == check_generation && *prepared_color == color - && (*prepared_width == width - || (*prepared_width < width - || (prepared.size.width <= width - && prepared.line_height == prepared.size.height))) => {} + && *prepared_width == width => {} _ => { context.apply_current_font_settings(); let measured = self.text.map(|text| { diff --git a/src/widgets/scroll.rs b/src/widgets/scroll.rs index f3638d9..9c316fa 100644 --- a/src/widgets/scroll.rs +++ b/src/widgets/scroll.rs @@ -144,6 +144,10 @@ impl Scroll { } impl Widget for Scroll { + fn unmounted(&mut self, context: &mut EventContext<'_, '_>) { + self.contents.unmount_in(context); + } + fn hit_test(&mut self, _location: Point, _context: &mut EventContext<'_, '_>) -> bool { true }