From 33b5a900197e2798a393d6d9a0834039666eddbb Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 19 Apr 2023 01:19:56 +0200 Subject: Make basic text shaping the default shaping strategy --- widget/src/pick_list.rs | 3 +++ 1 file changed, 3 insertions(+) (limited to 'widget/src/pick_list.rs') diff --git a/widget/src/pick_list.rs b/widget/src/pick_list.rs index cd23cdd2..d44f4cae 100644 --- a/widget/src/pick_list.rs +++ b/widget/src/pick_list.rs @@ -366,6 +366,7 @@ where text_size, font.unwrap_or_else(|| renderer.default_font()), Size::new(f32::INFINITY, f32::INFINITY), + false, ); width.round() @@ -628,6 +629,7 @@ pub fn draw<'a, T, Renderer>( }, horizontal_alignment: alignment::Horizontal::Right, vertical_alignment: alignment::Vertical::Center, + advanced_shape: false, }); } @@ -653,6 +655,7 @@ pub fn draw<'a, T, Renderer>( }, horizontal_alignment: alignment::Horizontal::Left, vertical_alignment: alignment::Vertical::Center, + advanced_shape: false, }); } } -- cgit From 4bd290afe7d81d9aaf7467b3ce91491f6600261a Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 19 Apr 2023 02:00:45 +0200 Subject: Introduce `text::Shaping` enum and replace magic boolean --- widget/src/pick_list.rs | 46 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 10 deletions(-) (limited to 'widget/src/pick_list.rs') diff --git a/widget/src/pick_list.rs b/widget/src/pick_list.rs index d44f4cae..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, + text_shaping: text::Shaping, font: Option, handle: Handle, style: ::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) -> 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 { pub code_point: char, /// Font size of the content. pub size: Option, + /// The shaping strategy of the icon. + pub shaping: text::Shaping, } /// Computes the layout of a [`PickList`]. @@ -345,6 +358,7 @@ pub fn layout( width: Length, padding: Padding, text_size: Option, + text_shaping: text::Shaping, font: Option, placeholder: Option<&str>, options: &[T], @@ -366,7 +380,7 @@ where text_size, font.unwrap_or_else(|| renderer.default_font()), Size::new(f32::INFINITY, f32::INFINITY), - false, + text_shaping, ); width.round() @@ -516,6 +530,7 @@ pub fn overlay<'a, T, Message, Renderer>( state: &'a mut State, padding: Padding, text_size: Option, + text_shaping: text::Shaping, font: Renderer::Font, options: &'a [T], style: ::Style, @@ -543,6 +558,7 @@ where .width(bounds.width) .padding(padding) .font(font) + .text_shaping(text_shaping) .style(style); if let Some(text_size) = text_size { @@ -563,6 +579,7 @@ pub fn draw<'a, T, Renderer>( cursor_position: Point, padding: Padding, text_size: Option, + text_shaping: text::Shaping, font: Renderer::Font, placeholder: Option<&str>, selected: Option<&T>, @@ -595,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 { @@ -629,7 +655,7 @@ pub fn draw<'a, T, Renderer>( }, horizontal_alignment: alignment::Horizontal::Right, vertical_alignment: alignment::Vertical::Center, - advanced_shape: false, + shaping, }); } @@ -655,7 +681,7 @@ pub fn draw<'a, T, Renderer>( }, horizontal_alignment: alignment::Horizontal::Left, vertical_alignment: alignment::Vertical::Center, - advanced_shape: false, + shaping: text_shaping, }); } } -- cgit