summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2023-02-04 16:41:18 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2023-02-17 15:47:51 +0100
commit570600ce513e7e02b23c1da8322c68fbb876d1b0 (patch)
treecf0c03e34469ad9005288e627e37f69d75aad0e7
parent7b8b01f560569ae18d9337a31ba94f6c1c2ba0dd (diff)
downloadiced-570600ce513e7e02b23c1da8322c68fbb876d1b0.tar.gz
iced-570600ce513e7e02b23c1da8322c68fbb876d1b0.tar.bz2
iced-570600ce513e7e02b23c1da8322c68fbb876d1b0.zip
Use `Pixels` for `Text::size`
-rw-r--r--glow/src/backend.rs4
-rw-r--r--glow/src/settings.rs8
-rw-r--r--graphics/src/backend.rs2
-rw-r--r--graphics/src/renderer.rs4
-rw-r--r--native/src/overlay/menu.rs26
-rw-r--r--native/src/renderer/null.rs6
-rw-r--r--native/src/text.rs6
-rw-r--r--native/src/widget/checkbox.rs6
-rw-r--r--native/src/widget/pick_list.rs25
-rw-r--r--native/src/widget/radio.rs10
-rw-r--r--native/src/widget/text.rs12
-rw-r--r--native/src/widget/text_input.rs20
-rw-r--r--native/src/widget/toggler.rs10
-rw-r--r--src/settings.rs6
-rw-r--r--wgpu/src/backend.rs4
-rw-r--r--wgpu/src/settings.rs8
16 files changed, 79 insertions, 78 deletions
diff --git a/glow/src/backend.rs b/glow/src/backend.rs
index 416c3b94..36a34eda 100644
--- a/glow/src/backend.rs
+++ b/glow/src/backend.rs
@@ -22,7 +22,7 @@ pub struct Backend {
quad_pipeline: quad::Pipeline,
text_pipeline: text::Pipeline,
triangle_pipeline: triangle::Pipeline,
- default_text_size: u16,
+ default_text_size: f32,
}
impl Backend {
@@ -228,7 +228,7 @@ impl backend::Text for Backend {
const CHECKMARK_ICON: char = font::CHECKMARK_ICON;
const ARROW_DOWN_ICON: char = font::ARROW_DOWN_ICON;
- fn default_size(&self) -> u16 {
+ fn default_size(&self) -> f32 {
self.default_text_size
}
diff --git a/glow/src/settings.rs b/glow/src/settings.rs
index 3691747b..8ccffbad 100644
--- a/glow/src/settings.rs
+++ b/glow/src/settings.rs
@@ -4,7 +4,7 @@ pub use iced_graphics::Antialiasing;
/// The settings of a [`Backend`].
///
/// [`Backend`]: crate::Backend
-#[derive(Clone, Copy, PartialEq, Eq)]
+#[derive(Clone, Copy, PartialEq)]
pub struct Settings {
/// The bytes of the font that will be used by default.
///
@@ -13,8 +13,8 @@ pub struct Settings {
/// The default size of text.
///
- /// By default, it will be set to 20.
- pub default_text_size: u16,
+ /// By default, it will be set to `20.0`.
+ pub default_text_size: f32,
/// If enabled, spread text workload in multiple threads when multiple cores
/// are available.
@@ -32,7 +32,7 @@ impl Default for Settings {
fn default() -> Settings {
Settings {
default_font: None,
- default_text_size: 20,
+ default_text_size: 20.0,
text_multithreading: false,
antialiasing: None,
}
diff --git a/graphics/src/backend.rs b/graphics/src/backend.rs
index 2f8e9fc3..256b7ab5 100644
--- a/graphics/src/backend.rs
+++ b/graphics/src/backend.rs
@@ -32,7 +32,7 @@ pub trait Text {
const ARROW_DOWN_ICON: char;
/// Returns the default size of text.
- fn default_size(&self) -> u16;
+ fn default_size(&self) -> f32;
/// Measures the text contents with the given size and font,
/// returning the size of a laid out paragraph that fits in the provided
diff --git a/graphics/src/renderer.rs b/graphics/src/renderer.rs
index 298cf4a1..e07e7206 100644
--- a/graphics/src/renderer.rs
+++ b/graphics/src/renderer.rs
@@ -130,14 +130,14 @@ where
const CHECKMARK_ICON: char = B::CHECKMARK_ICON;
const ARROW_DOWN_ICON: char = B::ARROW_DOWN_ICON;
- fn default_size(&self) -> u16 {
+ fn default_size(&self) -> f32 {
self.backend().default_size()
}
fn measure(
&self,
content: &str,
- size: u16,
+ size: f32,
font: Font,
bounds: Size,
) -> (f32, f32) {
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
}
diff --git a/src/settings.rs b/src/settings.rs
index d31448fb..0eb3e62d 100644
--- a/src/settings.rs
+++ b/src/settings.rs
@@ -28,8 +28,8 @@ pub struct Settings<Flags> {
/// The text size that will be used by default.
///
- /// The default value is 20.
- pub default_text_size: u16,
+ /// The default value is `20.0`.
+ pub default_text_size: f32,
/// If enabled, spread text workload in multiple threads when multiple cores
/// are available.
@@ -97,7 +97,7 @@ where
window: Default::default(),
flags: Default::default(),
default_font: Default::default(),
- default_text_size: 20,
+ default_text_size: 20.0,
text_multithreading: false,
antialiasing: false,
exit_on_close_request: true,
diff --git a/wgpu/src/backend.rs b/wgpu/src/backend.rs
index 9ab12ce0..6a299425 100644
--- a/wgpu/src/backend.rs
+++ b/wgpu/src/backend.rs
@@ -29,7 +29,7 @@ pub struct Backend {
#[cfg(any(feature = "image", feature = "svg"))]
image_pipeline: image::Pipeline,
- default_text_size: u16,
+ default_text_size: f32,
}
impl Backend {
@@ -265,7 +265,7 @@ impl backend::Text for Backend {
const CHECKMARK_ICON: char = font::CHECKMARK_ICON;
const ARROW_DOWN_ICON: char = font::ARROW_DOWN_ICON;
- fn default_size(&self) -> u16 {
+ fn default_size(&self) -> f32 {
self.default_text_size
}
diff --git a/wgpu/src/settings.rs b/wgpu/src/settings.rs
index 21c2427d..fd3b990a 100644
--- a/wgpu/src/settings.rs
+++ b/wgpu/src/settings.rs
@@ -4,7 +4,7 @@ pub use crate::Antialiasing;
/// The settings of a [`Backend`].
///
/// [`Backend`]: crate::Backend
-#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Settings {
/// The present mode of the [`Backend`].
///
@@ -21,8 +21,8 @@ pub struct Settings {
/// The default size of text.
///
- /// By default, it will be set to 20.
- pub default_text_size: u16,
+ /// By default, it will be set to `16.0`.
+ pub default_text_size: f32,
/// If enabled, spread text workload in multiple threads when multiple cores
/// are available.
@@ -66,7 +66,7 @@ impl Default for Settings {
present_mode: wgpu::PresentMode::AutoVsync,
internal_backend: wgpu::Backends::all(),
default_font: None,
- default_text_size: 20,
+ default_text_size: 20.0,
text_multithreading: false,
antialiasing: None,
}