diff --git a/crates/color/src/ui/lut_picker.rs b/crates/color/src/ui/lut_picker.rs index f10b06136..8c2609d36 100644 --- a/crates/color/src/ui/lut_picker.rs +++ b/crates/color/src/ui/lut_picker.rs @@ -217,6 +217,17 @@ impl<'a> LutPicker<'a> { entries } + /// The choice the select shows: a held LUT whose name is a scanned folder file's name is that folder row, so the + /// file the layer was loaded from is not listed a second time as a custom row. + fn shown_choice(current: Option<&LutChoice>, files: &FolderFiles) -> Option { + if let Some(LutChoice::Loaded { name, .. }) = current + && let Some((_, path)) = files.iter().find(|(file, _)| file == name) + { + return Some(LutChoice::Folder(path.clone())); + } + current.cloned() + } + fn select<'e>(words: &LutWords, shown: Mixed, entries: &'e [Entry]) -> Select<'e, Row> { Select::new(words.label.clone(), Bind::given(shown), entries) } @@ -315,8 +326,9 @@ impl Component for LutPicker<'_> { fn paint(&mut self, ui: &mut PaintUi<'_>, cx: &Cx<'_, Self>) { let words = cx.words::(); let state = cx.recall::(); - let entries = Self::entries(&words, cx.value(), &state.files); - let shown = cx.value().map_or(Mixed::Mixed, |value| Mixed::Same(Row::Choice(value.clone()))); + let current = Self::shown_choice(cx.value(), &state.files); + let entries = Self::entries(&words, current.as_ref(), &state.files); + let shown = current.map_or(Mixed::Mixed, |value| Mixed::Same(Row::Choice(value))); let out = ui.child("select", cx.rect, Self::select(&words, shown, &entries)); let mut adopted = EditEvents::new(); for event in &out.events { diff --git a/crates/ui-widgets/src/text/linked.rs b/crates/ui-widgets/src/text/linked.rs index d19da5246..d3d2bed2a 100644 --- a/crates/ui-widgets/src/text/linked.rs +++ b/crates/ui-widgets/src/text/linked.rs @@ -11,7 +11,7 @@ use crate::contract::{ Remember as _, Role, SideLabel, WordSetCx as _, }; use crate::primitives::TextRun; -use crate::runtime::env::Label; +use crate::runtime::env::{Label, LengthUnits}; use crate::style::{ComponentStyle, StyleCx}; use craft_behavior::{EditEvents, Flow, IconId, Metrics, Mixed, Proposal, Sense}; use craft_i18n::Format; @@ -154,6 +154,8 @@ pub struct LinkedFields<'a, const N: usize> { /// Each field's own range. #[prop] ranges: Option<[RangeInclusive; N]>, + /// The lengths every field keeps and shows (`LinkedFields::lengths`); plain numbers without it. + lengths: Option, } impl<'a, const N: usize> LinkedFields<'a, N> { @@ -169,10 +171,19 @@ impl<'a, const N: usize> LinkedFields<'a, N> { layout: LinkedLayout::Row, captions: None, ranges: None, + lengths: None, } .label(label) } + /// Makes every field a length field (`NumberField::length`): the values are kept in `units.stored` and shown in + /// `units.shown`. `range` is then in the stored unit. + #[must_use] + pub fn lengths(mut self, units: LengthUnits) -> Self { + self.lengths = Some(units); + self + } + /// Shows a caption with each field that also scrubs it, and names the field: inside the field at its start in the /// `Row` layout, beside it in the others. Without captions a field is named by the group's label and its position. #[must_use] @@ -209,7 +220,12 @@ impl<'a, const N: usize> LinkedFields<'a, N> { } fn field(&self, i: usize, group: &Label, words: &LinkedWords, format: &Format, value: Mixed>) -> NumberField<'static> { - NumberField::new(self.name(i, group, words, format), Bind::given(value)).range(self.range_of(i)) + let name = self.name(i, group, words, format); + let field = match self.lengths { + Some(units) => NumberField::length(name, Bind::given(value), units), + None => NumberField::new(name, Bind::given(value)), + }; + field.range(self.range_of(i)) } }