From 28b0f7abf46ba6f6250e883104a6100e3e647172 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 13 Apr 2023 06:28:33 +0200 Subject: Delegate `layout` directly to `content` in `MouseListener` --- native/src/widget/mouse_listener.rs | 59 +++++++------------------------------ 1 file changed, 11 insertions(+), 48 deletions(-) (limited to 'native') diff --git a/native/src/widget/mouse_listener.rs b/native/src/widget/mouse_listener.rs index 0add7c71..c4e91cba 100644 --- a/native/src/widget/mouse_listener.rs +++ b/native/src/widget/mouse_listener.rs @@ -11,8 +11,6 @@ use crate::{ Clipboard, Element, Layout, Length, Point, Rectangle, Shell, Widget, }; -use std::u32; - /// Emit messages on mouse events. #[allow(missing_debug_implementations)] pub struct MouseListener<'a, Message, Renderer> { @@ -151,17 +149,7 @@ where renderer: &Renderer, limits: &layout::Limits, ) -> layout::Node { - layout( - renderer, - limits, - Widget::::width(self), - Widget::::height(self), - u32::MAX, - u32::MAX, - |renderer, limits| { - self.content.as_widget().layout(renderer, limits) - }, - ) + self.content.as_widget().layout(renderer, limits) } fn operate( @@ -171,14 +159,12 @@ where renderer: &Renderer, operation: &mut dyn Operation, ) { - operation.container(None, &mut |operation| { - self.content.as_widget().operate( - &mut tree.children[0], - layout.children().next().unwrap(), - renderer, - operation, - ); - }); + self.content.as_widget().operate( + &mut tree.children[0], + layout, + renderer, + operation, + ); } fn on_event( @@ -194,7 +180,7 @@ where if let event::Status::Captured = self.content.as_widget_mut().on_event( &mut tree.children[0], event.clone(), - layout.children().next().unwrap(), + layout, cursor_position, renderer, clipboard, @@ -223,7 +209,7 @@ where ) -> mouse::Interaction { self.content.as_widget().mouse_interaction( &tree.children[0], - layout.children().next().unwrap(), + layout, cursor_position, viewport, renderer, @@ -245,7 +231,7 @@ where renderer, theme, renderer_style, - layout.children().next().unwrap(), + layout, cursor_position, viewport, ); @@ -259,7 +245,7 @@ where ) -> Option> { self.content.as_widget_mut().overlay( &mut tree.children[0], - layout.children().next().unwrap(), + layout, renderer, ) } @@ -378,26 +364,3 @@ fn update( event::Status::Ignored } - -/// Computes the layout of a [`MouseListener`]. -pub fn layout( - renderer: &Renderer, - limits: &layout::Limits, - width: Length, - height: Length, - max_height: u32, - max_width: u32, - layout_content: impl FnOnce(&Renderer, &layout::Limits) -> layout::Node, -) -> layout::Node { - let limits = limits - .loose() - .max_height(max_height) - .max_width(max_width) - .width(width) - .height(height); - - let content = layout_content(renderer, &limits); - let size = limits.resolve(content.size()); - - layout::Node::with_children(size, vec![content]) -} -- cgit