perf: reduce memory allocations

This also changes `widget::column::with_children` and
`widget::row::with_children` to take an `impl IntoIterator` instead
of a `Vec`, like the `iced` variants of these functions do.

This shouldn't be a breaking change since passing in a `Vec` will still
compile and function exactly as before.

(Using `iced::widget::Column::from_vec` or
`iced::widget::Row::from_vec` isn't possible, since the elements of the
`Vec` aren't checked, so the size of the resulting `Column` or `Row`
won't adapt to the size of its children. Perhaps a new function could
be added to mirror `iced`'s?)
This commit is contained in:
Cheong Lau 2025-10-11 13:36:35 +10:00 committed by Michael Murphy
parent 840ef21e4d
commit bd438a8581
20 changed files with 83 additions and 88 deletions

View file

@ -455,21 +455,16 @@ where
// TODO get global colors from some cache?
// TODO how to handle overflow? should this use a grid widget for the list or a horizontal scroll and a limit for the max?
crate::widget::scrollable(
Row::with_children(
self.recent_colors
.iter()
.map(|c| {
let initial_srgb = palette::Srgb::from(*c);
let hsv = palette::Hsv::from_color(initial_srgb);
color_button(
Some(on_update(ColorPickerUpdate::ActiveColor(hsv))),
Some(*c),
Length::FillPortion(12),
)
.into()
})
.collect::<Vec<_>>(),
)
Row::with_children(self.recent_colors.iter().map(|c| {
let initial_srgb = palette::Srgb::from(*c);
let hsv = palette::Hsv::from_color(initial_srgb);
color_button(
Some(on_update(ColorPickerUpdate::ActiveColor(hsv))),
Some(*c),
Length::FillPortion(12),
)
.into()
}))
.padding([0.0, 0.0, f32::from(spacing.space_m), 0.0])
.spacing(spacing.space_xxs),
)