From b29de28d1f0f608f8029c93d154cfd1b0f8b8cbb Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 4 Feb 2023 07:33:33 +0100 Subject: Overhaul `Font` type to allow font family selection --- native/src/widget/checkbox.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'native/src/widget/checkbox.rs') diff --git a/native/src/widget/checkbox.rs b/native/src/widget/checkbox.rs index 9b69e574..138c458c 100644 --- a/native/src/widget/checkbox.rs +++ b/native/src/widget/checkbox.rs @@ -55,7 +55,7 @@ where size: f32, spacing: f32, text_size: Option, - font: Renderer::Font, + font: Option, icon: Icon, style: ::Style, } @@ -91,7 +91,7 @@ where size: Self::DEFAULT_SIZE, spacing: Self::DEFAULT_SPACING, text_size: None, - font: Renderer::Font::default(), + font: None, icon: Icon { font: Renderer::ICON_FONT, code_point: Renderer::CHECKMARK_ICON, @@ -128,8 +128,8 @@ where /// Sets the [`Font`] of the text of the [`Checkbox`]. /// /// [`Font`]: crate::text::Renderer::Font - pub fn font(mut self, font: Renderer::Font) -> Self { - self.font = font; + pub fn font(mut self, font: impl Into) -> Self { + self.font = Some(font.into()); self } @@ -175,7 +175,7 @@ where .push(Row::new().width(self.size).height(self.size)) .push( Text::new(&self.label) - .font(self.font.clone()) + .font(self.font.unwrap_or_else(|| renderer.default_font())) .width(self.width) .size( self.text_size @@ -288,6 +288,7 @@ where { let label_layout = children.next().unwrap(); + let font = self.font.unwrap_or_else(|| renderer.default_font()); widget::text::draw( renderer, @@ -295,7 +296,7 @@ where label_layout, &self.label, self.text_size, - self.font.clone(), + font, widget::text::Appearance { color: custom_style.text_color, }, -- cgit From a2ab9e939502ff36fd51115d9828fcdcd7bc104d Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 4 Feb 2023 16:41:18 +0100 Subject: Use `Pixels` for `Text::size` --- native/src/widget/checkbox.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'native/src/widget/checkbox.rs') diff --git a/native/src/widget/checkbox.rs b/native/src/widget/checkbox.rs index 138c458c..0e21e995 100644 --- a/native/src/widget/checkbox.rs +++ b/native/src/widget/checkbox.rs @@ -288,7 +288,6 @@ where { let label_layout = children.next().unwrap(); - let font = self.font.unwrap_or_else(|| renderer.default_font()); widget::text::draw( renderer, @@ -296,7 +295,7 @@ where label_layout, &self.label, self.text_size, - font, + self.font, widget::text::Appearance { color: custom_style.text_color, }, -- cgit From 700262e05c76e003158acfeb8edd9f6b026d78cf Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 24 Feb 2023 13:56:37 +0100 Subject: Fix `checkbox` example --- native/src/widget/checkbox.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'native/src/widget/checkbox.rs') diff --git a/native/src/widget/checkbox.rs b/native/src/widget/checkbox.rs index 0e21e995..6ba06d3b 100644 --- a/native/src/widget/checkbox.rs +++ b/native/src/widget/checkbox.rs @@ -267,7 +267,7 @@ where code_point, size, } = &self.icon; - let size = size.map(f32::from).unwrap_or(bounds.height * 0.7); + let size = size.unwrap_or(bounds.height * 0.7); if self.is_checked { renderer.fill_text(text::Text { -- cgit From 8059c40142d601588e01c152ce1bb72a1295dde8 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 24 Feb 2023 13:58:17 +0100 Subject: Fix `clippy` lints --- native/src/widget/checkbox.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'native/src/widget/checkbox.rs') diff --git a/native/src/widget/checkbox.rs b/native/src/widget/checkbox.rs index 6ba06d3b..cd8b9c6b 100644 --- a/native/src/widget/checkbox.rs +++ b/native/src/widget/checkbox.rs @@ -272,7 +272,7 @@ where if self.is_checked { renderer.fill_text(text::Text { content: &code_point.to_string(), - font: font.clone(), + font: *font, size, bounds: Rectangle { x: bounds.center_x(), -- cgit