ui-patterns: closure captures, non-exhaustive match, face paint call

This commit is contained in:
bflatastic
2026-11-21 21:46:23 +07:00
parent 1cfd70c139
commit 37a598bd50
4 changed files with 7 additions and 5 deletions
@@ -54,6 +54,8 @@ impl<'a, P: Clone + Eq + Hash> Prune<'a, P> {
HidePanels::None => true,
HidePanels::All => false,
HidePanels::Except(keep) => keep(panel),
// A way of hiding this code does not know hides nothing.
_ => true,
};
Prune { hide, keep: Some(Box::new(keep)), floating }
}
@@ -467,7 +467,7 @@ fn pick<T: Choice + Copy + PartialEq + Send + Sync>(
) {
let entries: Vec<Entry<T>> = entries::<T>(kind, words).into_iter().map(|(choice, text)| Entry::new(choice, text)).collect();
field(ui, id, label, enabled, |ui| {
let chosen = Select::new(label.clone(), Bind::given(*value), &options).show(ui);
let chosen = Select::new(label.clone(), Bind::given(*value), &entries).show(ui);
if let Some(next) = chosen.value().cloned() {
*value = next;
}
@@ -404,10 +404,10 @@ fn color_table_section(ui: &mut Ui, kit: &Kit<'_>, live: &mut Live, asked: &mut
("trash", &words.delete_color, ColorTableEdit::Delete),
];
Row::new().id_salt("table-tools").show(ui, |ui, _| {
for (icon, label, edit) in tools {
let button = IconButton::new(IconId::new(icon)).label(label.clone()).enabled(!selected.is_empty()).id_salt(icon).show(ui);
for (icon, label, edit) in &tools {
let button = IconButton::new(IconId::new(*icon)).label((*label).clone()).enabled(!selected.is_empty()).id_salt(*icon).show(ui);
if clicked(&button) {
asked.table.push(ColorTableEvent { edit, colors: selected.clone() });
asked.table.push(ColorTableEvent { edit: edit.clone(), colors: selected.clone() });
}
}
let more = IconButton::new(IconId::new("more")).label(words.table_menu.clone()).id_salt("menu").show(ui);
@@ -826,7 +826,7 @@ impl<'a, K: Clone + Eq + Hash + Send + Sync + 'static> PresetBrowser<'a, K> {
let preview = row.preview.clone();
move |cx: &ContentPainterCx, rect: Rect, painter: Option<&ThumbPainter<'_, K>>| match (painter, &preview) {
(Some(painter), _) => (painter.0)(cx, rect, ThumbInfo::new(&key, selected, false)),
(None, Some(preview)) => (preview.paint)(cx, rect),
(None, Some(preview)) => preview.paint.paint(cx, rect),
(None, None) => {}
}
};