summaryrefslogtreecommitdiffstats
path: root/widget/src
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector0193@gmail.com>2023-05-02 03:30:06 +0200
committerLibravatar GitHub <noreply@github.com>2023-05-02 03:30:06 +0200
commit2d7d9a130ece3fb6fa4cd52f9b32b4abd7887cf5 (patch)
tree6acba55171f28af1a3c9c4e65a99ad10abc11c65 /widget/src
parent57a276e16539d6aeca0619e0c5e36d0b1c1b5ef9 (diff)
parentedf3432bf5176be13437b9fd5d25b890ec9dbe69 (diff)
downloadiced-2d7d9a130ece3fb6fa4cd52f9b32b4abd7887cf5.tar.gz
iced-2d7d9a130ece3fb6fa4cd52f9b32b4abd7887cf5.tar.bz2
iced-2d7d9a130ece3fb6fa4cd52f9b32b4abd7887cf5.zip
Merge pull request #1822 from iced-rs/basic-shaping
`text::Shaping` strategy selection
Diffstat (limited to 'widget/src')
-rw-r--r--widget/src/checkbox.rs17
-rw-r--r--widget/src/overlay/menu.rs12
-rw-r--r--widget/src/pick_list.rs43
-rw-r--r--widget/src/radio.rs21
-rw-r--r--widget/src/text.rs1
-rw-r--r--widget/src/text_input.rs13
-rw-r--r--widget/src/toggler.rs12
7 files changed, 105 insertions, 14 deletions
diff --git a/widget/src/checkbox.rs b/widget/src/checkbox.rs
index 6505cfdd..2a09b8fd 100644
--- a/widget/src/checkbox.rs
+++ b/widget/src/checkbox.rs
@@ -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,6 +284,7 @@ where
color: custom_style.icon_color,
horizontal_alignment: alignment::Horizontal::Center,
vertical_alignment: alignment::Vertical::Center,
+ shaping: *shaping,
});
}
}
@@ -292,6 +304,7 @@ where
},
alignment::Horizontal::Left,
alignment::Vertical::Center,
+ self.text_shaping,
);
}
}
@@ -320,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,
}
diff --git a/widget/src/overlay/menu.rs b/widget/src/overlay/menu.rs
index c322c8ba..7de3cbae 100644
--- a/widget/src/overlay/menu.rs
+++ b/widget/src/overlay/menu.rs
@@ -31,6 +31,7 @@ where
width: f32,
padding: Padding,
text_size: Option<f32>,
+ text_shaping: text::Shaping,
font: Option<Renderer::Font>,
style: <Renderer::Theme as StyleSheet>::Style,
}
@@ -58,6 +59,7 @@ where
width: 0.0,
padding: Padding::ZERO,
text_size: None,
+ text_shaping: text::Shaping::Basic,
font: None,
style: Default::default(),
}
@@ -81,6 +83,12 @@ where
self
}
+ /// Sets the [`text::Shaping`] strategy of the [`Menu`].
+ pub fn text_shaping(mut self, shaping: text::Shaping) -> Self {
+ self.text_shaping = shaping;
+ self
+ }
+
/// Sets the font of the [`Menu`].
pub fn font(mut self, font: impl Into<Renderer::Font>) -> Self {
self.font = Some(font.into());
@@ -168,6 +176,7 @@ where
padding,
font,
text_size,
+ text_shaping,
style,
} = menu;
@@ -177,6 +186,7 @@ where
last_selection,
font,
text_size,
+ text_shaping,
padding,
style: style.clone(),
}));
@@ -311,6 +321,7 @@ where
last_selection: &'a mut Option<T>,
padding: Padding,
text_size: Option<f32>,
+ text_shaping: text::Shaping,
font: Option<Renderer::Font>,
style: <Renderer::Theme as StyleSheet>::Style,
}
@@ -500,6 +511,7 @@ where
},
horizontal_alignment: alignment::Horizontal::Left,
vertical_alignment: alignment::Vertical::Center,
+ shaping: self.text_shaping,
});
}
}
diff --git a/widget/src/pick_list.rs b/widget/src/pick_list.rs
index cd23cdd2..c0cb2946 100644
--- a/widget/src/pick_list.rs
+++ b/widget/src/pick_list.rs
@@ -36,6 +36,7 @@ where
width: Length,
padding: Padding,
text_size: Option<f32>,
+ text_shaping: text::Shaping,
font: Option<Renderer::Font>,
handle: Handle<Renderer::Font>,
style: <Renderer::Theme as StyleSheet>::Style,
@@ -71,6 +72,7 @@ where
width: Length::Shrink,
padding: Self::DEFAULT_PADDING,
text_size: None,
+ text_shaping: text::Shaping::Basic,
font: None,
handle: Default::default(),
style: Default::default(),
@@ -101,6 +103,12 @@ where
self
}
+ /// Sets the [`text::Shaping`] strategy of the [`PickList`].
+ pub fn text_shaping(mut self, shaping: text::Shaping) -> Self {
+ self.text_shaping = shaping;
+ self
+ }
+
/// Sets the font of the [`PickList`].
pub fn font(mut self, font: impl Into<Renderer::Font>) -> Self {
self.font = Some(font.into());
@@ -164,6 +172,7 @@ where
self.width,
self.padding,
self.text_size,
+ self.text_shaping,
self.font,
self.placeholder.as_deref(),
&self.options,
@@ -221,6 +230,7 @@ where
cursor_position,
self.padding,
self.text_size,
+ self.text_shaping,
font,
self.placeholder.as_deref(),
self.selected.as_ref(),
@@ -243,6 +253,7 @@ where
state,
self.padding,
self.text_size,
+ self.text_shaping,
self.font.unwrap_or_else(|| renderer.default_font()),
&self.options,
self.style.clone(),
@@ -336,6 +347,8 @@ 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,
}
/// Computes the layout of a [`PickList`].
@@ -345,6 +358,7 @@ pub fn layout<Renderer, T>(
width: Length,
padding: Padding,
text_size: Option<f32>,
+ text_shaping: text::Shaping,
font: Option<Renderer::Font>,
placeholder: Option<&str>,
options: &[T],
@@ -366,6 +380,7 @@ where
text_size,
font.unwrap_or_else(|| renderer.default_font()),
Size::new(f32::INFINITY, f32::INFINITY),
+ text_shaping,
);
width.round()
@@ -515,6 +530,7 @@ pub fn overlay<'a, T, Message, Renderer>(
state: &'a mut State<T>,
padding: Padding,
text_size: Option<f32>,
+ text_shaping: text::Shaping,
font: Renderer::Font,
options: &'a [T],
style: <Renderer::Theme as StyleSheet>::Style,
@@ -542,6 +558,7 @@ where
.width(bounds.width)
.padding(padding)
.font(font)
+ .text_shaping(text_shaping)
.style(style);
if let Some(text_size) = text_size {
@@ -562,6 +579,7 @@ pub fn draw<'a, T, Renderer>(
cursor_position: Point,
padding: Padding,
text_size: Option<f32>,
+ text_shaping: text::Shaping,
font: Renderer::Font,
placeholder: Option<&str>,
selected: Option<&T>,
@@ -594,25 +612,34 @@ pub fn draw<'a, T, Renderer>(
);
let handle = match handle {
- Handle::Arrow { size } => {
- Some((Renderer::ICON_FONT, Renderer::ARROW_DOWN_ICON, *size))
- }
+ Handle::Arrow { size } => Some((
+ Renderer::ICON_FONT,
+ Renderer::ARROW_DOWN_ICON,
+ *size,
+ text::Shaping::Basic,
+ )),
Handle::Static(Icon {
font,
code_point,
size,
- }) => Some((*font, *code_point, *size)),
+ shaping,
+ }) => Some((*font, *code_point, *size, *shaping)),
Handle::Dynamic { open, closed } => {
if state().is_open {
- Some((open.font, open.code_point, open.size))
+ Some((open.font, open.code_point, open.size, open.shaping))
} else {
- Some((closed.font, closed.code_point, closed.size))
+ Some((
+ closed.font,
+ closed.code_point,
+ closed.size,
+ closed.shaping,
+ ))
}
}
Handle::None => None,
};
- if let Some((font, code_point, size)) = handle {
+ if let Some((font, code_point, size, shaping)) = handle {
let size = size.unwrap_or_else(|| renderer.default_size());
renderer.fill_text(Text {
@@ -628,6 +655,7 @@ pub fn draw<'a, T, Renderer>(
},
horizontal_alignment: alignment::Horizontal::Right,
vertical_alignment: alignment::Vertical::Center,
+ shaping,
});
}
@@ -653,6 +681,7 @@ pub fn draw<'a, T, Renderer>(
},
horizontal_alignment: alignment::Horizontal::Left,
vertical_alignment: alignment::Vertical::Center,
+ shaping: text_shaping,
});
}
}
diff --git a/widget/src/radio.rs b/widget/src/radio.rs
index c3229aed..f62f4703 100644
--- a/widget/src/radio.rs
+++ b/widget/src/radio.rs
@@ -81,6 +81,7 @@ where
size: f32,
spacing: f32,
text_size: Option<f32>,
+ text_shaping: text::Shaping,
font: Option<Renderer::Font>,
style: <Renderer::Theme as StyleSheet>::Style,
}
@@ -123,6 +124,7 @@ where
size: Self::DEFAULT_SIZE,
spacing: Self::DEFAULT_SPACING, //15
text_size: None,
+ text_shaping: text::Shaping::Basic,
font: None,
style: Default::default(),
}
@@ -152,6 +154,12 @@ where
self
}
+ /// Sets the [`text::Shaping`] strategy of the [`Radio`] button.
+ pub fn text_shaping(mut self, shaping: text::Shaping) -> Self {
+ self.text_shaping = shaping;
+ self
+ }
+
/// Sets the text font of the [`Radio`] button.
pub fn font(mut self, font: impl Into<Renderer::Font>) -> Self {
self.font = Some(font.into());
@@ -192,9 +200,15 @@ where
.spacing(self.spacing)
.align_items(Alignment::Center)
.push(Row::new().width(self.size).height(self.size))
- .push(Text::new(&self.label).width(self.width).size(
- self.text_size.unwrap_or_else(|| renderer.default_size()),
- ))
+ .push(
+ Text::new(&self.label)
+ .width(self.width)
+ .size(
+ self.text_size
+ .unwrap_or_else(|| renderer.default_size()),
+ )
+ .shaping(self.text_shaping),
+ )
.layout(renderer, limits)
}
@@ -309,6 +323,7 @@ where
},
alignment::Horizontal::Left,
alignment::Vertical::Center,
+ self.text_shaping,
);
}
}
diff --git a/widget/src/text.rs b/widget/src/text.rs
index 04c31edc..50aa1370 100644
--- a/widget/src/text.rs
+++ b/widget/src/text.rs
@@ -1,3 +1,4 @@
+pub use crate::core::text::Shaping;
pub use crate::core::widget::text::*;
pub type Text<'a, Renderer = crate::Renderer> =
diff --git a/widget/src/text_input.rs b/widget/src/text_input.rs
index 9db382f7..32d0b1f8 100644
--- a/widget/src/text_input.rs
+++ b/widget/src/text_input.rs
@@ -463,6 +463,7 @@ where
&icon.code_point.to_string(),
icon.size.unwrap_or_else(|| renderer.default_size()),
icon.font,
+ text::Shaping::Advanced,
);
let mut text_node = layout::Node::new(
@@ -975,6 +976,7 @@ pub fn draw<Renderer>(
bounds: icon_layout.bounds(),
horizontal_alignment: alignment::Horizontal::Left,
vertical_alignment: alignment::Vertical::Top,
+ shaping: text::Shaping::Advanced,
});
}
@@ -1079,6 +1081,7 @@ pub fn draw<Renderer>(
if text.is_empty() { placeholder } else { &text },
size,
font,
+ text::Shaping::Advanced,
);
let render = |renderer: &mut Renderer| {
@@ -1106,6 +1109,7 @@ pub fn draw<Renderer>(
size,
horizontal_alignment: alignment::Horizontal::Left,
vertical_alignment: alignment::Vertical::Center,
+ shaping: text::Shaping::Advanced,
});
};
@@ -1310,8 +1314,12 @@ where
{
let text_before_cursor = value.until(cursor_index).to_string();
- let text_value_width =
- renderer.measure_width(&text_before_cursor, size, font);
+ let text_value_width = renderer.measure_width(
+ &text_before_cursor,
+ size,
+ font,
+ text::Shaping::Advanced,
+ );
let offset = ((text_value_width + 5.0) - text_bounds.width).max(0.0);
@@ -1344,6 +1352,7 @@ where
size,
font,
Size::INFINITY,
+ text::Shaping::Advanced,
Point::new(x + offset, text_bounds.height / 2.0),
true,
)
diff --git a/widget/src/toggler.rs b/widget/src/toggler.rs
index 713a9c30..639bbb3b 100644
--- a/widget/src/toggler.rs
+++ b/widget/src/toggler.rs
@@ -43,6 +43,7 @@ where
size: f32,
text_size: Option<f32>,
text_alignment: alignment::Horizontal,
+ text_shaping: text::Shaping,
spacing: f32,
font: Option<Renderer::Font>,
style: <Renderer::Theme as StyleSheet>::Style,
@@ -80,6 +81,7 @@ where
size: Self::DEFAULT_SIZE,
text_size: None,
text_alignment: alignment::Horizontal::Left,
+ text_shaping: text::Shaping::Basic,
spacing: 0.0,
font: None,
style: Default::default(),
@@ -110,6 +112,12 @@ where
self
}
+ /// Sets the [`text::Shaping`] strategy of the [`Toggler`].
+ pub fn text_shaping(mut self, shaping: text::Shaping) -> Self {
+ self.text_shaping = shaping;
+ self
+ }
+
/// Sets the spacing between the [`Toggler`] and the text.
pub fn spacing(mut self, spacing: impl Into<Pixels>) -> Self {
self.spacing = spacing.into().0;
@@ -167,7 +175,8 @@ where
.size(
self.text_size
.unwrap_or_else(|| renderer.default_size()),
- ),
+ )
+ .shaping(self.text_shaping),
);
}
@@ -249,6 +258,7 @@ where
Default::default(),
self.text_alignment,
alignment::Vertical::Center,
+ self.text_shaping,
);
}