diff options
author | 2023-02-04 16:41:18 +0100 | |
---|---|---|
committer | 2023-02-17 15:47:51 +0100 | |
commit | 570600ce513e7e02b23c1da8322c68fbb876d1b0 (patch) | |
tree | cf0c03e34469ad9005288e627e37f69d75aad0e7 /native/src/widget | |
parent | 7b8b01f560569ae18d9337a31ba94f6c1c2ba0dd (diff) | |
download | iced-570600ce513e7e02b23c1da8322c68fbb876d1b0.tar.gz iced-570600ce513e7e02b23c1da8322c68fbb876d1b0.tar.bz2 iced-570600ce513e7e02b23c1da8322c68fbb876d1b0.zip |
Use `Pixels` for `Text::size`
Diffstat (limited to 'native/src/widget')
-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 |
6 files changed, 41 insertions, 42 deletions
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 } |