From 3320ac1126750ed1c462d4f1ff81a59c74d1e9fb Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 17 Feb 2023 16:09:49 +0100 Subject: Use `f32` for `Padding` --- native/src/widget/tooltip.rs | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'native/src/widget/tooltip.rs') diff --git a/native/src/widget/tooltip.rs b/native/src/widget/tooltip.rs index 955586aa..2a24c055 100644 --- a/native/src/widget/tooltip.rs +++ b/native/src/widget/tooltip.rs @@ -25,8 +25,8 @@ where content: Element<'a, Message, Renderer>, tooltip: Text<'a, Renderer>, position: Position, - gap: u16, - padding: u16, + gap: f32, + padding: f32, snap_within_viewport: bool, style: ::Style, } @@ -37,7 +37,7 @@ where Renderer::Theme: container::StyleSheet + widget::text::StyleSheet, { /// The default padding of a [`Tooltip`] drawn by this renderer. - const DEFAULT_PADDING: u16 = 5; + const DEFAULT_PADDING: f32 = 5.0; /// Creates a new [`Tooltip`]. /// @@ -51,7 +51,7 @@ where content: content.into(), tooltip: Text::new(tooltip), position, - gap: 0, + gap: 0.0, padding: Self::DEFAULT_PADDING, snap_within_viewport: true, style: Default::default(), @@ -73,14 +73,14 @@ where } /// Sets the gap between the content and its [`Tooltip`]. - pub fn gap(mut self, gap: u16) -> Self { - self.gap = gap; + pub fn gap(mut self, gap: impl Into) -> Self { + self.gap = gap.into().0; self } /// Sets the padding of the [`Tooltip`]. - pub fn padding(mut self, padding: u16) -> Self { - self.padding = padding; + pub fn padding(mut self, padding: impl Into) -> Self { + self.padding = padding.into().0; self } @@ -272,8 +272,8 @@ pub fn draw( cursor_position: Point, viewport: &Rectangle, position: Position, - gap: u16, - padding: u16, + gap: f32, + padding: f32, snap_within_viewport: bool, style: &::Style, layout_text: impl FnOnce(&Renderer, &layout::Limits) -> layout::Node, @@ -293,7 +293,6 @@ pub fn draw( let bounds = layout.bounds(); if bounds.contains(cursor_position) { - let gap = f32::from(gap); let style = theme.appearance(style); let defaults = renderer::Style { @@ -311,7 +310,6 @@ pub fn draw( .pad(Padding::new(padding)), ); - let padding = f32::from(padding); let text_bounds = text_layout.bounds(); let x_center = bounds.x + (bounds.width - text_bounds.width) / 2.0; let y_center = bounds.y + (bounds.height - text_bounds.height) / 2.0; -- cgit