Introduce text::Shaping enum and replace magic boolean

This commit is contained in:
Héctor Ramón Jiménez 2023-04-19 02:00:45 +02:00
parent 33b5a90019
commit 4bd290afe7
No known key found for this signature in database
GPG key ID: 140CC052C94F138E
25 changed files with 203 additions and 132 deletions

View file

@ -46,6 +46,7 @@ where
size: f32,
spacing: f32,
text_size: Option<f32>,
text_shaping: text::Shaping,
font: Option<Renderer::Font>,
icon: Icon<Renderer::Font>,
style: <Renderer::Theme as StyleSheet>::Style,
@ -82,11 +83,13 @@ where
size: Self::DEFAULT_SIZE,
spacing: Self::DEFAULT_SPACING,
text_size: None,
text_shaping: text::Shaping::Basic,
font: None,
icon: Icon {
font: Renderer::ICON_FONT,
code_point: Renderer::CHECKMARK_ICON,
size: None,
shaping: text::Shaping::Basic,
},
style: Default::default(),
}
@ -116,6 +119,12 @@ where
self
}
/// Sets the [`text::Shaping`] strategy of the [`Checkbox`].
pub fn text_shaping(mut self, shaping: text::Shaping) -> Self {
self.text_shaping = shaping;
self
}
/// Sets the [`Font`] of the text of the [`Checkbox`].
///
/// [`Font`]: crate::text::Renderer::Font
@ -171,7 +180,8 @@ where
.size(
self.text_size
.unwrap_or_else(|| renderer.default_size()),
),
)
.shaping(self.text_shaping),
)
.layout(renderer, limits)
}
@ -257,6 +267,7 @@ where
font,
code_point,
size,
shaping,
} = &self.icon;
let size = size.unwrap_or(bounds.height * 0.7);
@ -273,7 +284,7 @@ where
color: custom_style.icon_color,
horizontal_alignment: alignment::Horizontal::Center,
vertical_alignment: alignment::Vertical::Center,
advanced_shape: true,
shaping: *shaping,
});
}
}
@ -293,7 +304,7 @@ where
},
alignment::Horizontal::Left,
alignment::Vertical::Center,
false,
self.text_shaping,
);
}
}
@ -322,4 +333,6 @@ pub struct Icon<Font> {
pub code_point: char,
/// Font size of the content.
pub size: Option<f32>,
/// The shaping strategy of the icon.
pub shaping: text::Shaping,
}