From 7b8b01f560569ae18d9337a31ba94f6c1c2ba0dd Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 4 Feb 2023 12:24:13 +0100 Subject: Use `f32` in `Length::Units` and rename it to `Fixed` --- native/src/overlay/menu.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'native/src/overlay/menu.rs') diff --git a/native/src/overlay/menu.rs b/native/src/overlay/menu.rs index 9e37380f..bd1f309e 100644 --- a/native/src/overlay/menu.rs +++ b/native/src/overlay/menu.rs @@ -28,7 +28,7 @@ where options: &'a [T], hovered_option: &'a mut Option, last_selection: &'a mut Option, - width: u16, + width: f32, padding: Padding, text_size: Option, font: Renderer::Font, @@ -55,7 +55,7 @@ where options, hovered_option, last_selection, - width: 0, + width: 0.0, padding: Padding::ZERO, text_size: None, font: Default::default(), @@ -64,7 +64,7 @@ where } /// Sets the width of the [`Menu`]. - pub fn width(mut self, width: u16) -> Self { + pub fn width(mut self, width: f32) -> Self { self.width = width; self } @@ -142,7 +142,7 @@ where { state: &'a mut Tree, container: Container<'a, Message, Renderer>, - width: u16, + width: f32, target_height: f32, style: ::Style, } @@ -219,7 +219,7 @@ where }, ), ) - .width(Length::Units(self.width)); + .width(self.width); let mut node = self.container.layout(renderer, &limits); -- cgit From 570600ce513e7e02b23c1da8322c68fbb876d1b0 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 4 Feb 2023 16:41:18 +0100 Subject: Use `Pixels` for `Text::size` --- native/src/overlay/menu.rs | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'native/src/overlay/menu.rs') diff --git a/native/src/overlay/menu.rs b/native/src/overlay/menu.rs index bd1f309e..fac3028e 100644 --- a/native/src/overlay/menu.rs +++ b/native/src/overlay/menu.rs @@ -11,8 +11,8 @@ use crate::widget::container::{self, Container}; use crate::widget::scrollable::{self, Scrollable}; use crate::widget::Tree; use crate::{ - Clipboard, Color, Element, Layout, Length, Padding, Point, Rectangle, - Shell, Size, Vector, Widget, + Clipboard, Color, Element, Layout, Length, Padding, Pixels, Point, + Rectangle, Shell, Size, Vector, Widget, }; pub use iced_style::menu::{Appearance, StyleSheet}; @@ -30,7 +30,7 @@ where last_selection: &'a mut Option, width: f32, padding: Padding, - text_size: Option, + text_size: Option, font: Renderer::Font, style: ::Style, } @@ -76,8 +76,8 @@ where } /// Sets the text size of the [`Menu`]. - pub fn text_size(mut self, text_size: u16) -> Self { - self.text_size = Some(text_size); + pub fn text_size(mut self, text_size: impl Into) -> Self { + self.text_size = Some(text_size.into().0); self } @@ -310,7 +310,7 @@ where hovered_option: &'a mut Option, last_selection: &'a mut Option, padding: Padding, - text_size: Option, + text_size: Option, font: Renderer::Font, style: ::Style, } @@ -344,8 +344,9 @@ where let size = { let intrinsic = Size::new( 0.0, - f32::from(text_size + self.padding.vertical()) - * self.options.len() as f32, + text_size + + f32::from(self.padding.vertical()) + * self.options.len() as f32, ); limits.resolve(intrinsic) @@ -386,7 +387,7 @@ where *self.hovered_option = Some( ((cursor_position.y - bounds.y) - / f32::from(text_size + self.padding.vertical())) + / (text_size + f32::from(self.padding.vertical()))) as usize, ); } @@ -401,7 +402,7 @@ where *self.hovered_option = Some( ((cursor_position.y - bounds.y) - / f32::from(text_size + self.padding.vertical())) + / (text_size + f32::from(self.padding.vertical()))) as usize, ); @@ -450,7 +451,8 @@ where let text_size = self.text_size.unwrap_or_else(|| renderer.default_size()); - let option_height = (text_size + self.padding.vertical()) as usize; + let option_height = + (text_size + f32::from(self.padding.vertical())) as usize; let offset = viewport.y - bounds.y; let start = (offset / option_height as f32) as usize; @@ -467,7 +469,7 @@ where x: bounds.x, y: bounds.y + (option_height * i) as f32, width: bounds.width, - height: f32::from(text_size + self.padding.vertical()), + height: text_size + f32::from(self.padding.vertical()), }; if is_selected { -- cgit 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/overlay/menu.rs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'native/src/overlay/menu.rs') 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 -- cgit