diff --git a/crates/ui-patterns/src/patterns/form_dialogs/export/path_row.rs b/crates/ui-patterns/src/patterns/form_dialogs/export/path_row.rs index 0b03caf8b..3de925cd8 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/export/path_row.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/export/path_row.rs @@ -1,7 +1,7 @@ //! `OutputPathRow`: where a render or an export goes, as a template list and the resulting file name as a link. use crate::buttons::Link; -use crate::contract::{Bind, EditResponse, Entry, NoValue, Outcome, Props as _, Remember as _, Show as _, ShowContainer as _, clicked}; +use crate::contract::{Bind, EditResponse, Entry, NoValue, Outcome, Props as _, Remember as _, Show as _, ShowContainer as _, Sizing, clicked}; use crate::form::Field; use crate::layout_components::Row; use crate::pickers::Select; @@ -105,7 +105,7 @@ impl<'a> OutputPathRow<'a> { Row::new().show(ui, |ui, _| { if !entries.is_empty() { let picked: EditResponse = - Select::new(words.templates.clone(), value.reborrowed(), &entries).id_salt("templates").show(ui); + Select::new(words.templates.clone(), value.reborrowed(), &entries).id_salt("templates").sizing(Sizing::Content).show(ui); edit.extend(picked.events); } editing = match std::mem::take(&mut editing) { diff --git a/crates/ui-patterns/src/patterns/presets/picker.rs b/crates/ui-patterns/src/patterns/presets/picker.rs index cbdf9a22d..9119eab45 100644 --- a/crates/ui-patterns/src/patterns/presets/picker.rs +++ b/crates/ui-patterns/src/patterns/presets/picker.rs @@ -51,7 +51,8 @@ impl<'a> PickerHead<'a> { #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] #[non_exhaustive] pub enum PickerField { - /// The thumbnail alone; the name when the preset has none. + /// The thumbnail alone; the name when the preset has no thumbnail, and an empty thumbnail + /// with no preset or a mixed value. #[default] Thumbnail, /// The name alone. @@ -281,25 +282,35 @@ impl<'a, K: Value + Eq + Hash + 'static> PresetPicker<'a, K> { } } + /// `face` with an empty thumbnail of the cell shape, and the name unless the field shows the thumbnail alone. + fn empty_thumb<'f>(&self, face: SelectFace<'f>) -> SelectFace<'f> { + self.captioned(face.thumb(self.cell_shape.aspect(), |_, _| {}).name(self.field != PickerField::Thumbnail)) + } + /// The face of a field showing `text`: with a `row`, its thumbnail and name as `field` says; without, the muted - /// look of a mixed value or a placeholder. The measured candidates and the painted face are both built here. + /// look of a mixed value or a placeholder, which a thumbnail-only field shows as an empty thumbnail. The measured + /// candidates and the painted face are both built here. fn face_of(&self, text: Label, row: Option<&PresetRow>, paint: bool) -> SelectFace<'static> { - let Some(row) = row else { return SelectFace::new(text).placeholder() }; let face = SelectFace::new(text); - match (&row.preview, self.field) { - (_, PickerField::Name) | (None, _) => face, - (Some(preview), field) => { - let draw = paint.then(|| preview.paint.clone()); - let face = face - .thumb(preview.aspect, move |cx, rect| { - if let Some(draw) = &draw { - draw(cx, rect); - } - }) - .name(field == PickerField::ThumbnailAndName); - self.captioned(face) - } - } + let face = match (row, self.field) { + (None, PickerField::Thumbnail) => self.empty_thumb(face.placeholder()), + (None, _) => face.placeholder(), + (Some(row), field) => match (&row.preview, field) { + (_, PickerField::Name) | (None, _) => face, + (Some(preview), field) => { + let draw = paint.then(|| preview.paint.clone()); + let face = face + .thumb(preview.aspect, move |cx, rect| { + if let Some(draw) = &draw { + draw(cx, rect); + } + }) + .name(field == PickerField::ThumbnailAndName); + self.captioned(face) + } + }, + }; + face } } @@ -320,13 +331,8 @@ impl Component for PresetPicker<'_, K> { /// preset, the mixed word and the placeholder, and an empty thumbnail face for the height. fn measure(&mut self, cx: &MeasureCx<'_, Self>) -> Vec2 { let words = cx.words::(); - let aspect = self.cell_shape.aspect(); let empty = SelectFace::new(Label::Empty); - let empty = if self.field == PickerField::Name { - empty - } else { - self.captioned(empty.thumb(aspect, |_, _| {}).name(self.field != PickerField::Thumbnail)) - }; + let empty = if self.field == PickerField::Name { empty } else { self.empty_thumb(empty) }; let rows = self.rows.iter().filter(|row| !row.is_group()); let faces = rows.map(|row| { let (text, _) = self.shown(Some(&Some(row.key.clone())), &words, &cx.env); diff --git a/crates/ui-widgets/src/pickers/face.rs b/crates/ui-widgets/src/pickers/face.rs index 8d3393d7f..5a36c477e 100644 --- a/crates/ui-widgets/src/pickers/face.rs +++ b/crates/ui-widgets/src/pickers/face.rs @@ -39,7 +39,7 @@ pub struct SelectFaceStyle { } /// The closed box of a picker: `text` elided to the room left of a trailing chevron. The box is as wide as the text -/// and the chevron need, at least a field wide. A host shows it as the look of one of its parts with +/// and the chevron need, at least a field wide; a thumbnail alone takes only its own width. A host shows it as the look of one of its parts with /// `ui.face(part, SelectFace::new(text))` over the field well it paints itself, and gives the box the width of its /// widest text so the width does not change with the pick. A thumbnail goes before the text, or alone. #[derive(crate::contract::Component, crate::contract::Props)] @@ -57,8 +57,9 @@ pub struct SelectFace<'a> { /// A short line centred under the thumbnail (a brush's size); it shows only with a thumbnail. #[prop(into)] thumb_caption: Option