From 346af3f8b0baa418fd37b878bc2930ff0bd57cc0 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Mon, 11 Sep 2023 02:47:24 +0200 Subject: Make `FontSystem` global and simplify `Paragraph` API --- widget/src/pick_list.rs | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) (limited to 'widget/src/pick_list.rs') diff --git a/widget/src/pick_list.rs b/widget/src/pick_list.rs index 056a5e65..4b89d6ff 100644 --- a/widget/src/pick_list.rs +++ b/widget/src/pick_list.rs @@ -415,23 +415,17 @@ where for (option, paragraph) in options.iter().zip(state.options.iter_mut()) { let label = option.to_string(); - renderer.update_paragraph( - paragraph, - Text { - content: &label, - ..option_text - }, - ); + paragraph.update(Text { + content: &label, + ..option_text + }); } if let Some(placeholder) = placeholder { - renderer.update_paragraph( - &mut state.placeholder, - Text { - content: placeholder, - ..option_text - }, - ); + state.placeholder.update(Text { + content: placeholder, + ..option_text + }); } let max_width = match width { -- cgit From 936d480267578d7e80675e78ec1880aaaaab72d6 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 1 Dec 2023 16:04:27 +0100 Subject: Clip text to `viewport` bounds instead of layout bounds --- widget/src/pick_list.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'widget/src/pick_list.rs') diff --git a/widget/src/pick_list.rs b/widget/src/pick_list.rs index 00c1a7ff..022ca8d9 100644 --- a/widget/src/pick_list.rs +++ b/widget/src/pick_list.rs @@ -235,7 +235,7 @@ where _style: &renderer::Style, layout: Layout<'_>, cursor: mouse::Cursor, - _viewport: &Rectangle, + viewport: &Rectangle, ) { let font = self.font.unwrap_or_else(|| renderer.default_font()); draw( @@ -253,6 +253,7 @@ where &self.handle, &self.style, || tree.state.downcast_ref::>(), + viewport, ); } @@ -631,6 +632,7 @@ pub fn draw<'a, T, Renderer>( handle: &Handle, style: &::Style, state: impl FnOnce() -> &'a State, + viewport: &Rectangle, ) where Renderer: text::Renderer, Renderer::Theme: StyleSheet, @@ -715,6 +717,7 @@ pub fn draw<'a, T, Renderer>( bounds.center_y(), ), style.handle_color, + *viewport, ); } @@ -743,6 +746,7 @@ pub fn draw<'a, T, Renderer>( } else { style.placeholder_color }, + *viewport, ); } } -- cgit From 0655a20ad119e2e9790afcc45039fd4ac0e7d432 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 16 Mar 2023 20:23:25 +0100 Subject: Make `Shrink` have priority over `Fill` in layout --- widget/src/pick_list.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'widget/src/pick_list.rs') diff --git a/widget/src/pick_list.rs b/widget/src/pick_list.rs index 022ca8d9..13110725 100644 --- a/widget/src/pick_list.rs +++ b/widget/src/pick_list.rs @@ -393,7 +393,7 @@ where { use std::f32; - let limits = limits.width(width).height(Length::Shrink).pad(padding); + let limits = limits.width(width).height(Length::Shrink); let font = font.unwrap_or_else(|| renderer.default_font()); let text_size = text_size.unwrap_or_else(|| renderer.default_size()); @@ -451,7 +451,10 @@ where f32::from(text_line_height.to_absolute(text_size)), ); - limits.resolve(intrinsic).pad(padding) + limits + .shrink(padding) + .resolve(intrinsic, width, Length::Shrink) + .expand(padding) }; layout::Node::new(size) -- cgit From d278bfd21d0399009e652560afb9a4d185e92637 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 5 Jan 2024 17:46:33 +0100 Subject: Replace `width` and `height` with `Widget::size` --- widget/src/pick_list.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'widget/src/pick_list.rs') diff --git a/widget/src/pick_list.rs b/widget/src/pick_list.rs index 13110725..d83b0624 100644 --- a/widget/src/pick_list.rs +++ b/widget/src/pick_list.rs @@ -164,12 +164,11 @@ where tree::State::new(State::::new()) } - fn width(&self) -> Length { - self.width - } - - fn height(&self) -> Length { - Length::Shrink + fn size(&self) -> Size { + Size { + width: self.width, + height: Length::Shrink, + } } fn layout( -- cgit From d62bb8193c1c43f565fcc5c52293d564c91e215d Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 9 Jan 2024 06:35:33 +0100 Subject: Introduce useful helpers in `layout` module --- widget/src/pick_list.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'widget/src/pick_list.rs') diff --git a/widget/src/pick_list.rs b/widget/src/pick_list.rs index d83b0624..2576a1e8 100644 --- a/widget/src/pick_list.rs +++ b/widget/src/pick_list.rs @@ -392,7 +392,6 @@ where { use std::f32; - let limits = limits.width(width).height(Length::Shrink); let font = font.unwrap_or_else(|| renderer.default_font()); let text_size = text_size.unwrap_or_else(|| renderer.default_size()); @@ -451,8 +450,10 @@ where ); limits + .width(width) + .height(Length::Shrink) .shrink(padding) - .resolve(intrinsic, width, Length::Shrink) + .resolve(width, Length::Shrink, intrinsic) .expand(padding) }; -- cgit From 88f8c343fa7d69203ab98bb7abc85fe002014422 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 9 Jan 2024 07:15:57 +0100 Subject: Fix `cross` calculation in `layout::flex` --- widget/src/pick_list.rs | 1 - 1 file changed, 1 deletion(-) (limited to 'widget/src/pick_list.rs') diff --git a/widget/src/pick_list.rs b/widget/src/pick_list.rs index 2576a1e8..9f6a371a 100644 --- a/widget/src/pick_list.rs +++ b/widget/src/pick_list.rs @@ -451,7 +451,6 @@ where limits .width(width) - .height(Length::Shrink) .shrink(padding) .resolve(width, Length::Shrink, intrinsic) .expand(padding) -- cgit From 3850a46db6e13f2948f5731f4ceec42764391f5d Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 10 Jan 2024 08:15:05 +0100 Subject: Add `Theme` selector to `layout` example --- widget/src/pick_list.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'widget/src/pick_list.rs') diff --git a/widget/src/pick_list.rs b/widget/src/pick_list.rs index 9f6a371a..2e3aab6f 100644 --- a/widget/src/pick_list.rs +++ b/widget/src/pick_list.rs @@ -45,7 +45,7 @@ where impl<'a, T: 'a, Message, Renderer> PickList<'a, T, Message, Renderer> where - T: ToString + Eq, + T: ToString + PartialEq, [T]: ToOwned>, Renderer: text::Renderer, Renderer::Theme: StyleSheet @@ -145,7 +145,7 @@ where impl<'a, T: 'a, Message, Renderer> Widget for PickList<'a, T, Message, Renderer> where - T: Clone + ToString + Eq + 'static, + T: Clone + ToString + PartialEq + 'static, [T]: ToOwned>, Message: 'a, Renderer: text::Renderer + 'a, @@ -281,7 +281,7 @@ where impl<'a, T: 'a, Message, Renderer> From> for Element<'a, Message, Renderer> where - T: Clone + ToString + Eq + 'static, + T: Clone + ToString + PartialEq + 'static, [T]: ToOwned>, Message: 'a, Renderer: text::Renderer + 'a, -- cgit