Use f32 for Icon::size and remove unnecessary conversions

This commit is contained in:
Héctor Ramón Jiménez 2023-04-11 05:13:56 +02:00
parent 898307e9ac
commit 0e2fc99eb8
No known key found for this signature in database
GPG key ID: 140CC052C94F138E
2 changed files with 7 additions and 7 deletions

View file

@ -583,7 +583,7 @@ impl<'a> Step {
text_input = text_input.icon(text_input::Icon { text_input = text_input.icon(text_input::Icon {
font: ICON_FONT, font: ICON_FONT,
code_point: '\u{e900}', code_point: '\u{e900}',
size: Some(35), size: Some(35.0),
position: text_input::IconPosition::Right, position: text_input::IconPosition::Right,
}); });
} }

View file

@ -51,7 +51,7 @@ pub struct Icon<Font> {
/// The unicode code point that will be used as the icon. /// The unicode code point that will be used as the icon.
pub code_point: char, pub code_point: char,
/// Font size of the content. /// Font size of the content.
pub size: Option<u16>, pub size: Option<f32>,
/// Position of the icon. /// Position of the icon.
pub position: IconPosition, pub position: IconPosition,
} }
@ -886,7 +886,7 @@ pub fn draw<Renderer>(
position, position,
} = icon; } = icon;
let padding = f32::from(padding.horizontal()); let padding = padding.horizontal();
let size = size.unwrap_or_else(|| renderer.default_size()); let size = size.unwrap_or_else(|| renderer.default_size());
let width = renderer.measure_width( let width = renderer.measure_width(
&code_point.to_string(), &code_point.to_string(),
@ -939,14 +939,14 @@ pub fn draw<Renderer>(
position, position,
} = icon; } = icon;
let padding = f32::from(padding.horizontal()); let padding = padding.horizontal();
let size = size.unwrap_or_else(|| renderer.default_size()); let size = size.unwrap_or_else(|| renderer.default_size());
let width = let width =
renderer.measure_width(&code_point.to_string(), size, font.clone()); renderer.measure_width(&code_point.to_string(), size, font.clone());
renderer.fill_text(Text { renderer.fill_text(Text {
content: &code_point.to_string(), content: &code_point.to_string(),
size: f32::from(size), size,
font: font.clone(), font: font.clone(),
color: appearance.icon_color, color: appearance.icon_color,
bounds: Rectangle { bounds: Rectangle {
@ -954,8 +954,8 @@ pub fn draw<Renderer>(
IconPosition::Left => bounds.x + width + padding, IconPosition::Left => bounds.x + width + padding,
IconPosition::Right => bounds.x + bounds.width - padding, IconPosition::Right => bounds.x + bounds.width - padding,
}, },
y: bounds.center_y() - f32::from(size) / 2.0, y: bounds.center_y() - size / 2.0,
height: f32::from(size), height: size,
..bounds ..bounds
}, },
horizontal_alignment: alignment::Horizontal::Right, horizontal_alignment: alignment::Horizontal::Right,