panels-w37: net change of 1 commits

- panels-w37: review fixes (review-1)
This commit is contained in:
aiongg
2026-11-15 09:18:07 +00:00
parent d66c2f286d
commit 6476a39bb5
2 changed files with 32 additions and 4 deletions
+14 -2
View File
@@ -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<LutChoice> {
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<Row>, entries: &'e [Entry<Row>]) -> 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::<LutWords>();
let state = cx.recall::<LutState>();
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 {
+18 -2
View File
@@ -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<f64>; N]>,
/// The lengths every field keeps and shows (`LinkedFields::lengths`); plain numbers without it.
lengths: Option<LengthUnits>,
}
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<Option<f64>>) -> 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))
}
}