summaryrefslogtreecommitdiffstats
path: root/core/src/widget
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-07-12 15:11:30 +0200
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-07-12 15:14:43 +0200
commitf9dd5cbb099bbe44a57b6369be54a442363b7a8d (patch)
treefe16084bc47faadc32d698aa446ea202f7949a4c /core/src/widget
parentbe06060117da061ad8cad94ab0830c06def6b147 (diff)
downloadiced-f9dd5cbb099bbe44a57b6369be54a442363b7a8d.tar.gz
iced-f9dd5cbb099bbe44a57b6369be54a442363b7a8d.tar.bz2
iced-f9dd5cbb099bbe44a57b6369be54a442363b7a8d.zip
Introduce helper methods for alignment for all widgets
Diffstat (limited to 'core/src/widget')
-rw-r--r--core/src/widget/text.rs47
1 files changed, 41 insertions, 6 deletions
diff --git a/core/src/widget/text.rs b/core/src/widget/text.rs
index 081407e5..6ae95c8b 100644
--- a/core/src/widget/text.rs
+++ b/core/src/widget/text.rs
@@ -86,21 +86,56 @@ where
self
}
+ /// Centers the [`Text`], both horizontally and vertically.
+ pub fn center(self) -> Self {
+ self.center_x().center_y()
+ }
+
+ /// Centers the [`Text`] horizontally.
+ pub fn center_x(self) -> Self {
+ self.align_x(alignment::center())
+ }
+
+ /// Aligns the [`Text`] to the left, the default.
+ pub fn align_left(self) -> Self {
+ self.align_x(alignment::left())
+ }
+
+ /// Aligns the [`Text`] to the right.
+ pub fn align_right(self) -> Self {
+ self.align_x(alignment::right())
+ }
+
+ /// Centers the [`Text`] vertically.
+ pub fn center_y(self) -> Self {
+ self.align_y(alignment::center())
+ }
+
+ /// Aligns the [`Text`] to the top, the default.
+ pub fn align_top(self) -> Self {
+ self.align_y(alignment::top())
+ }
+
+ /// Aligns the [`Text`] to the bottom.
+ pub fn align_bottom(self) -> Self {
+ self.align_y(alignment::bottom())
+ }
+
/// Sets the [`alignment::Horizontal`] of the [`Text`].
- pub fn horizontal_alignment(
+ pub fn align_x(
mut self,
- alignment: alignment::Horizontal,
+ alignment: impl Into<alignment::Horizontal>,
) -> Self {
- self.horizontal_alignment = alignment;
+ self.horizontal_alignment = alignment.into();
self
}
/// Sets the [`alignment::Vertical`] of the [`Text`].
- pub fn vertical_alignment(
+ pub fn align_y(
mut self,
- alignment: alignment::Vertical,
+ alignment: impl Into<alignment::Vertical>,
) -> Self {
- self.vertical_alignment = alignment;
+ self.vertical_alignment = alignment.into();
self
}