mirror of
https://github.com/danbulant/cushy
synced 2026-06-24 09:02:31 +00:00
WidgetRef::unmount_in
This should be all the locations that WidgetRef::unmount_in should be called.
This commit is contained in:
parent
9e4e079bf5
commit
32d6fffd3b
6 changed files with 32 additions and 18 deletions
|
|
@ -541,6 +541,10 @@ impl Widget for Button {
|
||||||
fn deactivate(&mut self, context: &mut EventContext<'_, '_>) {
|
fn deactivate(&mut self, context: &mut EventContext<'_, '_>) {
|
||||||
self.update_colors(context, false);
|
self.update_colors(context, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn unmounted(&mut self, context: &mut EventContext<'_, '_>) {
|
||||||
|
self.content.unmount_in(context);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
define_components! {
|
define_components! {
|
||||||
|
|
|
||||||
|
|
@ -206,6 +206,10 @@ impl Widget for Container {
|
||||||
.finish()
|
.finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn unmounted(&mut self, context: &mut EventContext<'_, '_>) {
|
||||||
|
self.child.unmount_in(context);
|
||||||
|
}
|
||||||
|
|
||||||
fn full_control_redraw(&self) -> bool {
|
fn full_control_redraw(&self) -> bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -527,6 +527,8 @@ impl WrapperWidget for Custom {
|
||||||
fn unmounted(&mut self, context: &mut EventContext<'_, '_>) {
|
fn unmounted(&mut self, context: &mut EventContext<'_, '_>) {
|
||||||
if let Some(unmounted) = &mut self.unmounted {
|
if let Some(unmounted) = &mut self.unmounted {
|
||||||
unmounted.invoke(context);
|
unmounted.invoke(context);
|
||||||
|
} else {
|
||||||
|
self.child_mut().unmount_in(context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ use kludgine::{Color, DrawableExt};
|
||||||
|
|
||||||
use super::button::{ButtonActiveBackground, ButtonBackground, ButtonHoverBackground};
|
use super::button::{ButtonActiveBackground, ButtonBackground, ButtonHoverBackground};
|
||||||
use crate::animation::{AnimationHandle, AnimationTarget, Spawn};
|
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::components::{HighlightColor, IntrinsicPadding, LineHeight, OutlineColor};
|
||||||
use crate::styles::Dimension;
|
use crate::styles::Dimension;
|
||||||
use crate::value::{Dynamic, IntoDynamic, IntoValue, Value};
|
use crate::value::{Dynamic, IntoDynamic, IntoValue, Value};
|
||||||
|
|
@ -161,6 +161,13 @@ impl DiscloseIndicator {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Widget for 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<'_, '_, '_, '_, '_>) {
|
fn redraw(&mut self, context: &mut crate::context::GraphicsContext<'_, '_, '_, '_, '_>) {
|
||||||
let angle = self.angle.get_tracking_redraw(context);
|
let angle = self.angle.get_tracking_redraw(context);
|
||||||
let (color, stroke_color) = self.effective_colors(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
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
fn focus(&mut self, context: &mut crate::context::EventContext<'_, '_>) {
|
fn focus(&mut self, context: &mut EventContext<'_, '_>) {
|
||||||
context.set_needs_redraw();
|
context.set_needs_redraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn blur(&mut self, context: &mut crate::context::EventContext<'_, '_>) {
|
fn blur(&mut self, context: &mut EventContext<'_, '_>) {
|
||||||
context.set_needs_redraw();
|
context.set_needs_redraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn hit_test(
|
fn hit_test(&mut self, location: Point<Px>, context: &mut EventContext<'_, '_>) -> bool {
|
||||||
&mut self,
|
|
||||||
location: Point<Px>,
|
|
||||||
context: &mut crate::context::EventContext<'_, '_>,
|
|
||||||
) -> bool {
|
|
||||||
let size = context
|
let size = context
|
||||||
.get(&IndicatorSize)
|
.get(&IndicatorSize)
|
||||||
.into_px(context.kludgine.scale())
|
.into_px(context.kludgine.scale())
|
||||||
|
|
@ -296,7 +299,7 @@ impl Widget for DiscloseIndicator {
|
||||||
fn hover(
|
fn hover(
|
||||||
&mut self,
|
&mut self,
|
||||||
location: Point<Px>,
|
location: Point<Px>,
|
||||||
context: &mut crate::context::EventContext<'_, '_>,
|
context: &mut EventContext<'_, '_>,
|
||||||
) -> Option<CursorIcon> {
|
) -> Option<CursorIcon> {
|
||||||
let hovering = self.hit_test(location, context);
|
let hovering = self.hit_test(location, context);
|
||||||
if self.hovering_indicator != hovering {
|
if self.hovering_indicator != hovering {
|
||||||
|
|
@ -307,7 +310,7 @@ impl Widget for DiscloseIndicator {
|
||||||
hovering.then_some(CursorIcon::Pointer)
|
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 {
|
if self.hovering_indicator {
|
||||||
self.hovering_indicator = false;
|
self.hovering_indicator = false;
|
||||||
context.set_needs_redraw();
|
context.set_needs_redraw();
|
||||||
|
|
@ -319,7 +322,7 @@ impl Widget for DiscloseIndicator {
|
||||||
location: Point<Px>,
|
location: Point<Px>,
|
||||||
_device_id: kludgine::app::winit::event::DeviceId,
|
_device_id: kludgine::app::winit::event::DeviceId,
|
||||||
_button: kludgine::app::winit::event::MouseButton,
|
_button: kludgine::app::winit::event::MouseButton,
|
||||||
context: &mut crate::context::EventContext<'_, '_>,
|
context: &mut EventContext<'_, '_>,
|
||||||
) -> EventHandling {
|
) -> EventHandling {
|
||||||
if self.hit_test(location, context) {
|
if self.hit_test(location, context) {
|
||||||
self.mouse_buttons_pressed += 1;
|
self.mouse_buttons_pressed += 1;
|
||||||
|
|
@ -336,7 +339,7 @@ impl Widget for DiscloseIndicator {
|
||||||
_location: Option<Point<Px>>,
|
_location: Option<Point<Px>>,
|
||||||
_device_id: kludgine::app::winit::event::DeviceId,
|
_device_id: kludgine::app::winit::event::DeviceId,
|
||||||
_button: kludgine::app::winit::event::MouseButton,
|
_button: kludgine::app::winit::event::MouseButton,
|
||||||
context: &mut crate::context::EventContext<'_, '_>,
|
context: &mut EventContext<'_, '_>,
|
||||||
) {
|
) {
|
||||||
self.mouse_buttons_pressed -= 1;
|
self.mouse_buttons_pressed -= 1;
|
||||||
if self.mouse_buttons_pressed == 0 {
|
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 {
|
if self.mouse_buttons_pressed == 0 {
|
||||||
self.collapsed.toggle();
|
self.collapsed.toggle();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -41,10 +41,7 @@ impl Label {
|
||||||
if prepared.can_render_to(&context.gfx)
|
if prepared.can_render_to(&context.gfx)
|
||||||
&& *prepared_generation == check_generation
|
&& *prepared_generation == check_generation
|
||||||
&& *prepared_color == color
|
&& *prepared_color == color
|
||||||
&& (*prepared_width == width
|
&& *prepared_width == width => {}
|
||||||
|| (*prepared_width < width
|
|
||||||
|| (prepared.size.width <= width
|
|
||||||
&& prepared.line_height == prepared.size.height))) => {}
|
|
||||||
_ => {
|
_ => {
|
||||||
context.apply_current_font_settings();
|
context.apply_current_font_settings();
|
||||||
let measured = self.text.map(|text| {
|
let measured = self.text.map(|text| {
|
||||||
|
|
|
||||||
|
|
@ -144,6 +144,10 @@ impl Scroll {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Widget for Scroll {
|
impl Widget for Scroll {
|
||||||
|
fn unmounted(&mut self, context: &mut EventContext<'_, '_>) {
|
||||||
|
self.contents.unmount_in(context);
|
||||||
|
}
|
||||||
|
|
||||||
fn hit_test(&mut self, _location: Point<Px>, _context: &mut EventContext<'_, '_>) -> bool {
|
fn hit_test(&mut self, _location: Point<Px>, _context: &mut EventContext<'_, '_>) -> bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue