Use Pixels for Text::size

This commit is contained in:
Héctor Ramón Jiménez 2023-02-04 16:41:18 +01:00
parent 7b8b01f560
commit 570600ce51
No known key found for this signature in database
GPG key ID: 140CC052C94F138E
16 changed files with 79 additions and 78 deletions

View file

@ -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,