summaryrefslogtreecommitdiffstats
path: root/native
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector0193@gmail.com>2023-02-17 12:58:27 +0100
committerLibravatar GitHub <noreply@github.com>2023-02-17 12:58:27 +0100
commit32745f472fe00af492551ef5878fc5f570ae24ab (patch)
tree4e43b48864814a19b1906a11ab50dc5674260283 /native
parente3fbaed12fcb7b2aaa33c42e60cf675d707bc197 (diff)
parent4fb0be179359097db4aaf6d88dff1367201727dd (diff)
downloadiced-32745f472fe00af492551ef5878fc5f570ae24ab.tar.gz
iced-32745f472fe00af492551ef5878fc5f570ae24ab.tar.bz2
iced-32745f472fe00af492551ef5878fc5f570ae24ab.zip
Merge pull request #1707 from casperstorm/feat/checkbox-icon
Added the ability to change `Checkbox` icon
Diffstat (limited to 'native')
-rw-r--r--native/src/widget/checkbox.rs38
1 files changed, 34 insertions, 4 deletions
diff --git a/native/src/widget/checkbox.rs b/native/src/widget/checkbox.rs
index b46433c2..f6298a8c 100644
--- a/native/src/widget/checkbox.rs
+++ b/native/src/widget/checkbox.rs
@@ -14,6 +14,17 @@ use crate::{
pub use iced_style::checkbox::{Appearance, StyleSheet};
+/// The icon in a [`Checkbox`].
+#[derive(Debug, Clone, PartialEq, Eq)]
+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>,
+}
+
/// A box that can be checked.
///
/// # Example
@@ -45,6 +56,7 @@ where
spacing: u16,
text_size: Option<u16>,
font: Renderer::Font,
+ icon: Icon<Renderer::Font>,
style: <Renderer::Theme as StyleSheet>::Style,
}
@@ -80,6 +92,11 @@ where
spacing: Self::DEFAULT_SPACING,
text_size: None,
font: Renderer::Font::default(),
+ icon: Icon {
+ font: Renderer::ICON_FONT,
+ code_point: Renderer::CHECKMARK_ICON,
+ size: None,
+ },
style: Default::default(),
}
}
@@ -116,6 +133,12 @@ where
self
}
+ /// Sets the [`Icon`] of the [`Checkbox`].
+ pub fn icon(mut self, icon: Icon<Renderer::Font>) -> Self {
+ self.icon = icon;
+ self
+ }
+
/// Sets the style of the [`Checkbox`].
pub fn style(
mut self,
@@ -243,17 +266,24 @@ where
custom_style.background,
);
+ let Icon {
+ font,
+ code_point,
+ size,
+ } = &self.icon;
+ let size = size.map(f32::from).unwrap_or(bounds.height * 0.7);
+
if self.is_checked {
renderer.fill_text(text::Text {
- content: &Renderer::CHECKMARK_ICON.to_string(),
- font: Renderer::ICON_FONT,
- size: bounds.height * 0.7,
+ content: &code_point.to_string(),
+ font: font.clone(),
+ size,
bounds: Rectangle {
x: bounds.center_x(),
y: bounds.center_y(),
..bounds
},
- color: custom_style.checkmark_color,
+ color: custom_style.icon_color,
horizontal_alignment: alignment::Horizontal::Center,
vertical_alignment: alignment::Vertical::Center,
});