From 3fe2e14a423b9b568815b870318fa8d98eb90af2 Mon Sep 17 00:00:00 2001 From: Cory Forsstrom Date: Tue, 9 Aug 2022 11:12:31 -0700 Subject: [PATCH 1/2] Don't clip tooltip --- native/src/widget/tooltip.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native/src/widget/tooltip.rs b/native/src/widget/tooltip.rs index d8198004db..879bb69c65 100644 --- a/native/src/widget/tooltip.rs +++ b/native/src/widget/tooltip.rs @@ -349,7 +349,7 @@ pub fn draw( viewport.y + viewport.height - tooltip_bounds.height; } - renderer.with_layer(*viewport, |renderer| { + renderer.with_layer(Rectangle::with_size(Size::INFINITY), |renderer| { container::draw_background(renderer, &style, tooltip_bounds); draw_text( From 1ae3a94de2f0a3c41de0af1cfe190016c7de60fd Mon Sep 17 00:00:00 2001 From: Cory Forsstrom Date: Tue, 9 Aug 2022 11:23:56 -0700 Subject: [PATCH 2/2] Add snap within viewport builder --- native/src/widget/tooltip.rs | 42 +++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/native/src/widget/tooltip.rs b/native/src/widget/tooltip.rs index 879bb69c65..ff10ca56c3 100644 --- a/native/src/widget/tooltip.rs +++ b/native/src/widget/tooltip.rs @@ -25,6 +25,7 @@ where position: Position, gap: u16, padding: u16, + snap_within_viewport: bool, style: ::Style, } @@ -50,6 +51,7 @@ where position, gap: 0, padding: Self::DEFAULT_PADDING, + snap_within_viewport: true, style: Default::default(), } } @@ -80,6 +82,12 @@ where self } + /// Sets whether the [`Tooltip`] is snapped within the viewport. + pub fn snap_within_viewport(mut self, snap: bool) -> Self { + self.snap_within_viewport = snap; + self + } + /// Sets the style of the [`Tooltip`]. pub fn style( mut self, @@ -190,6 +198,7 @@ where self.position, self.gap, self.padding, + self.snap_within_viewport, self.style, |renderer, limits| { Widget::<(), Renderer>::layout(tooltip, renderer, limits) @@ -263,6 +272,7 @@ pub fn draw( position: Position, gap: u16, padding: u16, + snap_within_viewport: bool, style: ::Style, layout_text: impl FnOnce(&Renderer, &layout::Limits) -> layout::Node, draw_text: impl FnOnce( @@ -331,22 +341,24 @@ pub fn draw( } }; - if tooltip_bounds.x < viewport.x { - tooltip_bounds.x = viewport.x; - } else if viewport.x + viewport.width - < tooltip_bounds.x + tooltip_bounds.width - { - tooltip_bounds.x = - viewport.x + viewport.width - tooltip_bounds.width; - } + if snap_within_viewport { + if tooltip_bounds.x < viewport.x { + tooltip_bounds.x = viewport.x; + } else if viewport.x + viewport.width + < tooltip_bounds.x + tooltip_bounds.width + { + tooltip_bounds.x = + viewport.x + viewport.width - tooltip_bounds.width; + } - if tooltip_bounds.y < viewport.y { - tooltip_bounds.y = viewport.y; - } else if viewport.y + viewport.height - < tooltip_bounds.y + tooltip_bounds.height - { - tooltip_bounds.y = - viewport.y + viewport.height - tooltip_bounds.height; + if tooltip_bounds.y < viewport.y { + tooltip_bounds.y = viewport.y; + } else if viewport.y + viewport.height + < tooltip_bounds.y + tooltip_bounds.height + { + tooltip_bounds.y = + viewport.y + viewport.height - tooltip_bounds.height; + } } renderer.with_layer(Rectangle::with_size(Size::INFINITY), |renderer| {