diff options
author | 2023-02-04 16:41:18 +0100 | |
---|---|---|
committer | 2023-02-17 15:47:51 +0100 | |
commit | 570600ce513e7e02b23c1da8322c68fbb876d1b0 (patch) | |
tree | cf0c03e34469ad9005288e627e37f69d75aad0e7 /native | |
parent | 7b8b01f560569ae18d9337a31ba94f6c1c2ba0dd (diff) | |
download | iced-570600ce513e7e02b23c1da8322c68fbb876d1b0.tar.gz iced-570600ce513e7e02b23c1da8322c68fbb876d1b0.tar.bz2 iced-570600ce513e7e02b23c1da8322c68fbb876d1b0.zip |
Use `Pixels` for `Text::size`
Diffstat (limited to 'native')
-rw-r--r-- | native/src/overlay/menu.rs | 26 | ||||
-rw-r--r-- | native/src/renderer/null.rs | 6 | ||||
-rw-r--r-- | native/src/text.rs | 6 | ||||
-rw-r--r-- | native/src/widget/checkbox.rs | 6 | ||||
-rw-r--r-- | native/src/widget/pick_list.rs | 25 | ||||
-rw-r--r-- | native/src/widget/radio.rs | 10 | ||||
-rw-r--r-- | native/src/widget/text.rs | 12 | ||||
-rw-r--r-- | native/src/widget/text_input.rs | 20 | ||||
-rw-r--r-- | native/src/widget/toggler.rs | 10 |
9 files changed, 61 insertions, 60 deletions
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<T>, width: f32, padding: Padding, - text_size: Option<u16>, + text_size: Option<f32>, font: Renderer::Font, style: <Renderer::Theme as StyleSheet>::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<Pixels>) -> Self { + self.text_size = Some(text_size.into().0); self } @@ -310,7 +310,7 @@ where hovered_option: &'a mut Option<usize>, last_selection: &'a mut Option<T>, padding: Padding, - text_size: Option<u16>, + text_size: Option<f32>, font: Renderer::Font, style: <Renderer::Theme as StyleSheet>::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 { diff --git a/native/src/renderer/null.rs b/native/src/renderer/null.rs index b1743dbf..9376d540 100644 --- a/native/src/renderer/null.rs +++ b/native/src/renderer/null.rs @@ -44,14 +44,14 @@ impl text::Renderer for Null { const CHECKMARK_ICON: char = '0'; const ARROW_DOWN_ICON: char = '0'; - fn default_size(&self) -> u16 { - 20 + fn default_size(&self) -> f32 { + 20.0 } fn measure( &self, _content: &str, - _size: u16, + _size: f32, _font: Font, _bounds: Size, ) -> (f32, f32) { diff --git a/native/src/text.rs b/native/src/text.rs index 6e28681d..55c3cfd3 100644 --- a/native/src/text.rs +++ b/native/src/text.rs @@ -73,20 +73,20 @@ pub trait Renderer: crate::Renderer { const ARROW_DOWN_ICON: char; /// Returns the default size of [`Text`]. - fn default_size(&self) -> u16; + fn default_size(&self) -> f32; /// Measures the text in the given bounds and returns the minimum boundaries /// that can fit the contents. fn measure( &self, content: &str, - size: u16, + size: f32, font: Self::Font, bounds: Size, ) -> (f32, f32); /// Measures the width of the text as if it were laid out in a single line. - fn measure_width(&self, content: &str, size: u16, font: Self::Font) -> f32 { + fn measure_width(&self, content: &str, size: f32, font: Self::Font) -> f32 { let (width, _) = self.measure(content, size, font, Size::INFINITY); width diff --git a/native/src/widget/checkbox.rs b/native/src/widget/checkbox.rs index d2b5157a..835a0651 100644 --- a/native/src/widget/checkbox.rs +++ b/native/src/widget/checkbox.rs @@ -54,7 +54,7 @@ where width: Length, size: f32, spacing: u16, - text_size: Option<u16>, + text_size: Option<f32>, font: Renderer::Font, icon: Icon<Renderer::Font>, style: <Renderer::Theme as StyleSheet>::Style, @@ -120,8 +120,8 @@ where } /// Sets the text size of the [`Checkbox`]. - 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<Pixels>) -> Self { + self.text_size = Some(text_size.into().0); self } diff --git a/native/src/widget/pick_list.rs b/native/src/widget/pick_list.rs index 1c0886f2..7a61d560 100644 --- a/native/src/widget/pick_list.rs +++ b/native/src/widget/pick_list.rs @@ -13,8 +13,8 @@ use crate::widget::container; use crate::widget::scrollable; use crate::widget::tree::{self, Tree}; use crate::{ - Clipboard, Element, Layout, Length, Padding, Point, Rectangle, Shell, Size, - Widget, + Clipboard, Element, Layout, Length, Padding, Pixels, Point, Rectangle, + Shell, Size, Widget, }; use std::borrow::Cow; @@ -34,7 +34,7 @@ where selected: Option<T>, width: Length, padding: Padding, - text_size: Option<u16>, + text_size: Option<f32>, font: Renderer::Font, handle: Handle<Renderer::Font>, style: <Renderer::Theme as StyleSheet>::Style, @@ -95,8 +95,8 @@ where } /// Sets the text size of the [`PickList`]. - pub fn text_size(mut self, size: u16) -> Self { - self.text_size = Some(size); + pub fn text_size(mut self, size: impl Into<Pixels>) -> Self { + self.text_size = Some(size.into().0); self } @@ -297,14 +297,14 @@ impl<T> Default for State<T> { } /// The handle to the right side of the [`PickList`]. -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq)] pub enum Handle<Font> { /// Displays an arrow icon (▼). /// /// This is the default. Arrow { /// Font size of the content. - size: Option<u16>, + size: Option<f32>, }, /// A custom static handle. Static(Icon<Font>), @@ -326,14 +326,14 @@ impl<Font> Default for Handle<Font> { } /// The icon of a [`Handle`]. -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq)] pub struct Icon<Font> { /// Font that will be used to display the `code_point`, pub font: Font, /// The unicode code point that will be used as the icon. pub code_point: char, /// Font size of the content. - pub size: Option<u16>, + pub size: Option<f32>, } /// Computes the layout of a [`PickList`]. @@ -342,7 +342,7 @@ pub fn layout<Renderer, T>( limits: &layout::Limits, width: Length, padding: Padding, - text_size: Option<u16>, + text_size: Option<f32>, font: &Renderer::Font, placeholder: Option<&str>, options: &[T], @@ -354,7 +354,6 @@ where use std::f32; let limits = limits.width(width).height(Length::Shrink).pad(padding); - let text_size = text_size.unwrap_or_else(|| renderer.default_size()); let max_width = match width { @@ -514,7 +513,7 @@ pub fn overlay<'a, T, Message, Renderer>( layout: Layout<'_>, state: &'a mut State<T>, padding: Padding, - text_size: Option<u16>, + text_size: Option<f32>, font: Renderer::Font, options: &'a [T], style: <Renderer::Theme as StyleSheet>::Style, @@ -561,7 +560,7 @@ pub fn draw<'a, T, Renderer>( layout: Layout<'_>, cursor_position: Point, padding: Padding, - text_size: Option<u16>, + text_size: Option<f32>, font: &Renderer::Font, placeholder: Option<&str>, selected: Option<&T>, diff --git a/native/src/widget/radio.rs b/native/src/widget/radio.rs index 22aeb4ce..62bc2447 100644 --- a/native/src/widget/radio.rs +++ b/native/src/widget/radio.rs @@ -8,8 +8,8 @@ use crate::text; use crate::touch; use crate::widget::{self, Row, Text, Tree}; use crate::{ - Alignment, Clipboard, Color, Element, Layout, Length, Point, Rectangle, - Shell, Widget, + Alignment, Clipboard, Color, Element, Layout, Length, Pixels, Point, + Rectangle, Shell, Widget, }; pub use iced_style::radio::{Appearance, StyleSheet}; @@ -52,7 +52,7 @@ where width: Length, size: f32, spacing: u16, - text_size: Option<u16>, + text_size: Option<f32>, font: Renderer::Font, style: <Renderer::Theme as StyleSheet>::Style, } @@ -119,8 +119,8 @@ where } /// Sets the text size of the [`Radio`] button. - 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<Pixels>) -> Self { + self.text_size = Some(text_size.into().0); self } diff --git a/native/src/widget/text.rs b/native/src/widget/text.rs index bac1adcf..3fee48f2 100644 --- a/native/src/widget/text.rs +++ b/native/src/widget/text.rs @@ -4,7 +4,7 @@ use crate::layout; use crate::renderer; use crate::text; use crate::widget::Tree; -use crate::{Element, Layout, Length, Point, Rectangle, Size, Widget}; +use crate::{Element, Layout, Length, Pixels, Point, Rectangle, Size, Widget}; use std::borrow::Cow; @@ -32,7 +32,7 @@ where Renderer::Theme: StyleSheet, { content: Cow<'a, str>, - size: Option<u16>, + size: Option<f32>, width: Length, height: Length, horizontal_alignment: alignment::Horizontal, @@ -61,8 +61,8 @@ where } /// Sets the size of the [`Text`]. - pub fn size(mut self, size: u16) -> Self { - self.size = Some(size); + pub fn size(mut self, size: impl Into<Pixels>) -> Self { + self.size = Some(size.into().0); self } @@ -185,7 +185,7 @@ pub fn draw<Renderer>( style: &renderer::Style, layout: Layout<'_>, content: &str, - size: Option<u16>, + size: Option<f32>, font: Renderer::Font, appearance: Appearance, horizontal_alignment: alignment::Horizontal, @@ -209,7 +209,7 @@ pub fn draw<Renderer>( renderer.fill_text(crate::text::Text { content, - size: f32::from(size.unwrap_or_else(|| renderer.default_size())), + size: size.unwrap_or_else(|| renderer.default_size()), bounds: Rectangle { x, y, ..bounds }, color: appearance.color.unwrap_or(style.text_color), font, diff --git a/native/src/widget/text_input.rs b/native/src/widget/text_input.rs index d4ab3d8d..02304cae 100644 --- a/native/src/widget/text_input.rs +++ b/native/src/widget/text_input.rs @@ -25,7 +25,7 @@ use crate::widget::operation::{self, Operation}; use crate::widget::tree::{self, Tree}; use crate::window; use crate::{ - Clipboard, Color, Command, Element, Layout, Length, Padding, Point, + Clipboard, Color, Command, Element, Layout, Length, Padding, Pixels, Point, Rectangle, Shell, Size, Vector, Widget, }; @@ -64,7 +64,7 @@ where font: Renderer::Font, width: Length, padding: Padding, - size: Option<u16>, + size: Option<f32>, on_change: Box<dyn Fn(String) -> Message + 'a>, on_paste: Option<Box<dyn Fn(String) -> Message + 'a>>, on_submit: Option<Message>, @@ -145,8 +145,8 @@ where } /// Sets the text size of the [`TextInput`]. - pub fn size(mut self, size: u16) -> Self { - self.size = Some(size); + pub fn size(mut self, size: impl Into<Pixels>) -> Self { + self.size = Some(size.into().0); self } @@ -379,7 +379,7 @@ pub fn layout<Renderer>( limits: &layout::Limits, width: Length, padding: Padding, - size: Option<u16>, + size: Option<f32>, ) -> layout::Node where Renderer: text::Renderer, @@ -405,7 +405,7 @@ pub fn update<'a, Message, Renderer>( clipboard: &mut dyn Clipboard, shell: &mut Shell<'_, Message>, value: &mut Value, - size: Option<u16>, + size: Option<f32>, font: &Renderer::Font, is_secure: bool, on_change: &dyn Fn(String) -> Message, @@ -811,7 +811,7 @@ pub fn draw<Renderer>( state: &State, value: &Value, placeholder: &str, - size: Option<u16>, + size: Option<f32>, font: &Renderer::Font, is_secure: bool, style: &<Renderer::Theme as StyleSheet>::Style, @@ -1124,7 +1124,7 @@ fn offset<Renderer>( renderer: &Renderer, text_bounds: Rectangle, font: Renderer::Font, - size: u16, + size: f32, value: &Value, state: &State, ) -> f32 @@ -1158,7 +1158,7 @@ fn measure_cursor_and_scroll_offset<Renderer>( renderer: &Renderer, text_bounds: Rectangle, value: &Value, - size: u16, + size: f32, cursor_index: usize, font: Renderer::Font, ) -> (f32, f32) @@ -1181,7 +1181,7 @@ fn find_cursor_position<Renderer>( renderer: &Renderer, text_bounds: Rectangle, font: Renderer::Font, - size: Option<u16>, + size: Option<f32>, value: &Value, state: &State, x: f32, diff --git a/native/src/widget/toggler.rs b/native/src/widget/toggler.rs index 13d0124d..eda8f85f 100644 --- a/native/src/widget/toggler.rs +++ b/native/src/widget/toggler.rs @@ -7,8 +7,8 @@ use crate::renderer; use crate::text; use crate::widget::{self, Row, Text, Tree}; use crate::{ - Alignment, Clipboard, Element, Event, Layout, Length, Point, Rectangle, - Shell, Widget, + Alignment, Clipboard, Element, Event, Layout, Length, Pixels, Point, + Rectangle, Shell, Widget, }; pub use iced_style::toggler::{Appearance, StyleSheet}; @@ -39,7 +39,7 @@ where label: Option<String>, width: Length, size: f32, - text_size: Option<u16>, + text_size: Option<f32>, text_alignment: alignment::Horizontal, spacing: u16, font: Renderer::Font, @@ -97,8 +97,8 @@ where } /// Sets the text size o the [`Toggler`]. - 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<Pixels>) -> Self { + self.text_size = Some(text_size.into().0); self } |