diff options
author | 2023-02-17 16:09:49 +0100 | |
---|---|---|
committer | 2023-02-17 16:09:49 +0100 | |
commit | 3320ac1126750ed1c462d4f1ff81a59c74d1e9fb (patch) | |
tree | 1bc13717cc9ea27cfdae3912745d2b52ec0c6330 /native | |
parent | 0872d078e2e3200e2aa2f5ee0005c34fff9effb7 (diff) | |
download | iced-3320ac1126750ed1c462d4f1ff81a59c74d1e9fb.tar.gz iced-3320ac1126750ed1c462d4f1ff81a59c74d1e9fb.tar.bz2 iced-3320ac1126750ed1c462d4f1ff81a59c74d1e9fb.zip |
Use `f32` for `Padding`
Diffstat (limited to 'native')
-rw-r--r-- | native/src/layout/flex.rs | 2 | ||||
-rw-r--r-- | native/src/layout/limits.rs | 5 | ||||
-rw-r--r-- | native/src/overlay/menu.rs | 17 | ||||
-rw-r--r-- | native/src/widget/button.rs | 4 | ||||
-rw-r--r-- | native/src/widget/container.rs | 2 | ||||
-rw-r--r-- | native/src/widget/pane_grid/title_bar.rs | 5 | ||||
-rw-r--r-- | native/src/widget/pick_list.rs | 32 | ||||
-rw-r--r-- | native/src/widget/text_input.rs | 8 | ||||
-rw-r--r-- | native/src/widget/tooltip.rs | 22 |
9 files changed, 42 insertions, 55 deletions
diff --git a/native/src/layout/flex.rs b/native/src/layout/flex.rs index 94121d76..5d70c2fc 100644 --- a/native/src/layout/flex.rs +++ b/native/src/layout/flex.rs @@ -191,7 +191,7 @@ where } } - let pad = axis.pack(padding.left as f32, padding.top as f32); + let pad = axis.pack(padding.left, padding.top); let mut main = pad.0; for (i, node) in nodes.iter_mut().enumerate() { diff --git a/native/src/layout/limits.rs b/native/src/layout/limits.rs index 137a054c..5d3c1556 100644 --- a/native/src/layout/limits.rs +++ b/native/src/layout/limits.rs @@ -114,10 +114,7 @@ impl Limits { /// Shrinks the current [`Limits`] to account for the given padding. pub fn pad(&self, padding: Padding) -> Limits { - self.shrink(Size::new( - padding.horizontal() as f32, - padding.vertical() as f32, - )) + self.shrink(Size::new(padding.horizontal(), padding.vertical())) } /// Shrinks the current [`Limits`] by the given [`Size`]. diff --git a/native/src/overlay/menu.rs b/native/src/overlay/menu.rs index fac3028e..efee14d4 100644 --- a/native/src/overlay/menu.rs +++ b/native/src/overlay/menu.rs @@ -344,9 +344,7 @@ where let size = { let intrinsic = Size::new( 0.0, - text_size - + f32::from(self.padding.vertical()) - * self.options.len() as f32, + text_size + self.padding.vertical() * self.options.len() as f32, ); limits.resolve(intrinsic) @@ -387,7 +385,7 @@ where *self.hovered_option = Some( ((cursor_position.y - bounds.y) - / (text_size + f32::from(self.padding.vertical()))) + / (text_size + self.padding.vertical())) as usize, ); } @@ -402,7 +400,7 @@ where *self.hovered_option = Some( ((cursor_position.y - bounds.y) - / (text_size + f32::from(self.padding.vertical()))) + / (text_size + self.padding.vertical())) as usize, ); @@ -451,8 +449,7 @@ where let text_size = self.text_size.unwrap_or_else(|| renderer.default_size()); - let option_height = - (text_size + f32::from(self.padding.vertical())) as usize; + let option_height = (text_size + self.padding.vertical()) as usize; let offset = viewport.y - bounds.y; let start = (offset / option_height as f32) as usize; @@ -469,7 +466,7 @@ where x: bounds.x, y: bounds.y + (option_height * i) as f32, width: bounds.width, - height: text_size + f32::from(self.padding.vertical()), + height: text_size + self.padding.vertical(), }; if is_selected { @@ -487,12 +484,12 @@ where renderer.fill_text(Text { content: &option.to_string(), bounds: Rectangle { - x: bounds.x + self.padding.left as f32, + x: bounds.x + self.padding.left, y: bounds.center_y(), width: f32::INFINITY, ..bounds }, - size: f32::from(text_size), + size: text_size, font: self.font.clone(), color: if is_selected { appearance.selected_text_color diff --git a/native/src/widget/button.rs b/native/src/widget/button.rs index 3d96dfe1..39387173 100644 --- a/native/src/widget/button.rs +++ b/native/src/widget/button.rs @@ -76,7 +76,7 @@ where on_press: None, width: Length::Shrink, height: Length::Shrink, - padding: Padding::new(5), + padding: Padding::new(5.0), style: <Renderer::Theme as StyleSheet>::Style::default(), } } @@ -434,7 +434,7 @@ pub fn layout<Renderer>( let padding = padding.fit(content.size(), limits.max()); let size = limits.pad(padding).resolve(content.size()).pad(padding); - content.move_to(Point::new(padding.left.into(), padding.top.into())); + content.move_to(Point::new(padding.left, padding.top)); layout::Node::with_children(size, vec![content]) } diff --git a/native/src/widget/container.rs b/native/src/widget/container.rs index 1621cf6e..b77bf50d 100644 --- a/native/src/widget/container.rs +++ b/native/src/widget/container.rs @@ -310,7 +310,7 @@ pub fn layout<Renderer>( let padding = padding.fit(content.size(), limits.max()); let size = limits.pad(padding).resolve(content.size()); - content.move_to(Point::new(padding.left.into(), padding.top.into())); + content.move_to(Point::new(padding.left, padding.top)); content.align( Alignment::from(horizontal_alignment), Alignment::from(vertical_alignment), diff --git a/native/src/widget/pane_grid/title_bar.rs b/native/src/widget/pane_grid/title_bar.rs index ea0969aa..107078ef 100644 --- a/native/src/widget/pane_grid/title_bar.rs +++ b/native/src/widget/pane_grid/title_bar.rs @@ -249,10 +249,7 @@ where ) }; - node.move_to(Point::new( - self.padding.left.into(), - self.padding.top.into(), - )); + node.move_to(Point::new(self.padding.left, self.padding.top)); layout::Node::with_children(node.size().pad(self.padding), vec![node]) } diff --git a/native/src/widget/pick_list.rs b/native/src/widget/pick_list.rs index 7a61d560..17528db4 100644 --- a/native/src/widget/pick_list.rs +++ b/native/src/widget/pick_list.rs @@ -53,7 +53,7 @@ where From<<Renderer::Theme as StyleSheet>::Style>, { /// The default padding of a [`PickList`]. - pub const DEFAULT_PADDING: Padding = Padding::new(5); + pub const DEFAULT_PADDING: Padding = Padding::new(5.0); /// Creates a new [`PickList`] with the given list of options, the current /// selected value, and the message to produce when an option is selected. @@ -358,7 +358,7 @@ where let max_width = match width { Length::Shrink => { - let measure = |label: &str| -> u32 { + let measure = |label: &str| -> f32 { let (width, _) = renderer.measure( label, text_size, @@ -366,26 +366,25 @@ where Size::new(f32::INFINITY, f32::INFINITY), ); - width.round() as u32 + width.round() }; let labels = options.iter().map(ToString::to_string); - let labels_width = - labels.map(|label| measure(&label)).max().unwrap_or(100); + let labels_width = labels + .map(|label| measure(&label)) + .fold(100.0, |candidate, current| current.max(candidate)); - let placeholder_width = placeholder.map(measure).unwrap_or(100); + let placeholder_width = placeholder.map(measure).unwrap_or(100.0); labels_width.max(placeholder_width) } - _ => 0, + _ => 0.0, }; let size = { - let intrinsic = Size::new( - max_width as f32 + f32::from(text_size) + f32::from(padding.left), - f32::from(text_size), - ); + let intrinsic = + Size::new(max_width + text_size + padding.left, text_size); limits.resolve(intrinsic).pad(padding) }; @@ -612,7 +611,7 @@ pub fn draw<'a, T, Renderer>( }; if let Some((font, code_point, size)) = handle { - let size = f32::from(size.unwrap_or_else(|| renderer.default_size())); + let size = size.unwrap_or_else(|| renderer.default_size()); renderer.fill_text(Text { content: &code_point.to_string(), @@ -620,7 +619,7 @@ pub fn draw<'a, T, Renderer>( font, color: style.handle_color, bounds: Rectangle { - x: bounds.x + bounds.width - f32::from(padding.horizontal()), + x: bounds.x + bounds.width - padding.horizontal(), y: bounds.center_y() - size / 2.0, height: size, ..bounds @@ -633,8 +632,7 @@ pub fn draw<'a, T, Renderer>( let label = selected.map(ToString::to_string); if let Some(label) = label.as_deref().or(placeholder) { - let text_size = - f32::from(text_size.unwrap_or_else(|| renderer.default_size())); + let text_size = text_size.unwrap_or_else(|| renderer.default_size()); renderer.fill_text(Text { content: label, @@ -646,9 +644,9 @@ pub fn draw<'a, T, Renderer>( style.placeholder_color }, bounds: Rectangle { - x: bounds.x + f32::from(padding.left), + x: bounds.x + padding.left, y: bounds.center_y() - text_size / 2.0, - width: bounds.width - f32::from(padding.horizontal()), + width: bounds.width - padding.horizontal(), height: text_size, }, horizontal_alignment: alignment::Horizontal::Left, diff --git a/native/src/widget/text_input.rs b/native/src/widget/text_input.rs index 02304cae..ee0473ea 100644 --- a/native/src/widget/text_input.rs +++ b/native/src/widget/text_input.rs @@ -94,7 +94,7 @@ where is_secure: false, font: Default::default(), width: Length::Fill, - padding: Padding::new(5), + padding: Padding::new(5.0), size: None, on_change: Box::new(on_change), on_paste: None, @@ -390,7 +390,7 @@ where let limits = limits.width(width).pad(padding).height(text_size); let mut text = layout::Node::new(limits.resolve(Size::ZERO)); - text.move_to(Point::new(padding.left.into(), padding.top.into())); + text.move_to(Point::new(padding.left, padding.top)); layout::Node::with_children(text.size().pad(padding), vec![text]) } @@ -965,7 +965,7 @@ pub fn draw<Renderer>( width: f32::INFINITY, ..text_bounds }, - size: f32::from(size), + size, horizontal_alignment: alignment::Horizontal::Left, vertical_alignment: alignment::Vertical::Center, }); @@ -1197,7 +1197,7 @@ where renderer .hit_test( &value.to_string(), - size.into(), + size, font, Size::INFINITY, Point::new(x + offset, text_bounds.height / 2.0), 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: <Renderer::Theme as container::StyleSheet>::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<Pixels>) -> 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<Pixels>) -> Self { + self.padding = padding.into().0; self } @@ -272,8 +272,8 @@ pub fn draw<Renderer>( cursor_position: Point, viewport: &Rectangle, position: Position, - gap: u16, - padding: u16, + gap: f32, + padding: f32, snap_within_viewport: bool, style: &<Renderer::Theme as container::StyleSheet>::Style, layout_text: impl FnOnce(&Renderer, &layout::Limits) -> layout::Node, @@ -293,7 +293,6 @@ pub fn draw<Renderer>( 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<Renderer>( .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; |