diff --git a/crates/color/src/ui/picker_dialog.rs b/crates/color/src/ui/picker_dialog.rs index a30222f41..134ba3c1d 100644 --- a/crates/color/src/ui/picker_dialog.rs +++ b/crates/color/src/ui/picker_dialog.rs @@ -454,6 +454,7 @@ impl StackDialog for ColorPickerDialog { let shown = Dialog::new(title.clone()) .opened(Bind::bound(open)) .buttons(buttons) + .side_buttons(true) .close_on_enter(true) .initial_focus(Initial::Keep) .roomy(true) diff --git a/crates/draw/src/ui/shape_drag/dialog.rs b/crates/draw/src/ui/shape_drag/dialog.rs index c10d7fa24..ad6b6e35a 100644 --- a/crates/draw/src/ui/shape_drag/dialog.rs +++ b/crates/draw/src/ui/shape_drag/dialog.rs @@ -410,7 +410,7 @@ fn body( typed: &mut Option, ) -> bool { let document = values.units.unwrap_or_else(pixels_only); - let entries: Vec> = length_units(values).map(|kind| Entry::new(kind, Label::from(numbers.symbol(kind)))).collect(); + let entries: Vec> = length_units(values).map(|kind| Entry::new(kind, numbers.name(kind))).collect(); let kind = values.kind; FieldGroup::new(title_of(kind, words)).show(ui, |ui, _| { let (width, height) = (Label::from(words.width.as_str().to_owned()), Label::from(words.height.as_str().to_owned())); diff --git a/crates/imaging/src/ui/adjust/curves_panel.rs b/crates/imaging/src/ui/adjust/curves_panel.rs index 5c6966e40..f01d19b13 100644 --- a/crates/imaging/src/ui/adjust/curves_panel.rs +++ b/crates/imaging/src/ui/adjust/curves_panel.rs @@ -1,5 +1,5 @@ -//! [`CurvesPanel`]: the Curves adjustment around the [`CurveEditor`]: the Channel select, the mode -//! icons (points, pencil), Smooth, the point pickers, the other channels overlaid on the composite +//! [`CurvesPanel`]: the Curves adjustment around the [`CurveEditor`]: the point pickers, the Channel +//! select, the mode icons (points, pencil), Smooth, the other channels overlaid on the composite //! and the hint line; and the ⌘/Ctrl-click-on-the-image helper //! ([`CurvesPanel::add_point_from_sample`]). @@ -139,15 +139,15 @@ type SamplerFn<'a> = Box Vec + 'a>; /// The Curves adjustment: Image › Adjustments › Curves and a Curves layer's Properties panel. /// -/// Top to bottom: -/// 1. The Channel select ([`ToneChannels`]); an isolated channel is the only entry, its name shown exactly as the +/// Top to bottom (PhotoCraft's order): +/// 1. With [`pickers`](Self::pickers), the point picker row. +/// 2. The Channel select ([`ToneChannels`]); an isolated channel is the only entry, its name shown exactly as the /// host gave it. -/// 2. The mode row: two icon-only toggle buttons ("Edit points to modify the curve", "Draw to modify the curve", the +/// 3. The mode row: two icon-only toggle buttons ("Edit points to modify the curve", "Draw to modify the curve", the /// current one pressed) and Smooth (enabled in pencil mode only). -/// 3. The [`CurveEditor`] for the shown channel: in its colour, over its histogram, in pencil mode for a drawn curve, +/// 4. The [`CurveEditor`] for the shown channel: in its colour, over its histogram, in pencil mode for a drawn curve, /// and, on a composite only, the other channels' curves as overlays (Photoshop; none for an isolated channel). -/// 4. The hint line, with the key names from the platform's shortcut words. -/// 5. With [`pickers`](Self::pickers), the point picker row. +/// 5. The hint line, with the key names from the platform's shortcut words. /// /// - **Smooth** replaces the shown map with its moving average over 7 levels (radius 3, shrunk at the ends so the /// first and last levels keep their values: PhotoCraft's `smooth_curve_map`), as one `Set`. @@ -168,7 +168,7 @@ pub struct CurvesPanel<'a> { /// The host's interpolation of point curves ([`CurveEditor::sampler`]). #[prop(boxed = "Fn(&[[f32; 2]]) -> Vec + 'a")] sampler: Option>, - /// The armed point picker; the picker row shows when it is given. + /// The armed point picker; the picker row shows, first, when it is given. #[prop] pickers: Option>>, /// The document canvas the ⌘/Ctrl-click and the eyedroppers reach under the dialog. @@ -313,6 +313,21 @@ impl<'a> CurvesPanel<'a> { // Alt+2…Alt+6 pick the Channel select's entry in a dialog; Properties has no such keys. let stack = if context.is_dialog() { stack.command_scope(ToneChannelCommands::SCOPE) } else { stack }; let group = stack.show(ui, |ui, cx| { + if let Some(armed) = pickers.as_mut() { + let mut row = TonePickerRow::new(armed.reborrowed()); + if pickers_unavailable { + row = row.unavailable(); + } + if let Some(canvas) = canvas { + row = row.canvas(canvas); + } + for each in TonePicker::ALL { + let usable = picker_enabled[each as usize] && !(each == TonePicker::Gray && (channels.is_gray() || context.is_gray())); + row = row.enabled_picker(each, usable); + } + picker = row.show(ui).change; + } + let value = match curves.reborrow().read(cx) { Some(Mixed::Same(value)) => value, _ => ToneCurves::identity(&channels), @@ -406,20 +421,6 @@ impl<'a> CurvesPanel<'a> { } edit = events; - if let Some(armed) = pickers.as_mut() { - let mut row = TonePickerRow::new(armed.reborrowed()); - if pickers_unavailable { - row = row.unavailable(); - } - if let Some(canvas) = canvas { - row = row.canvas(canvas); - } - for each in TonePicker::ALL { - let usable = picker_enabled[each as usize] && !(each == TonePicker::Gray && (channels.is_gray() || context.is_gray())); - row = row.enabled_picker(each, usable); - } - picker = row.show(ui).change; - } // An edit belongs to the channel it was drawn for; a switch shows from the next pass, with no selection. shown_channel = if picked == channel || !edit.is_empty() { channel } else { picked }; write_shown(&mut channel_bind, cx, stored, shown_channel); diff --git a/crates/imaging/src/ui/adjust/hosted.rs b/crates/imaging/src/ui/adjust/hosted.rs index 9f4e55536..6117a1c2c 100644 --- a/crates/imaging/src/ui/adjust/hosted.rs +++ b/crates/imaging/src/ui/adjust/hosted.rs @@ -87,8 +87,8 @@ type Editor = dyn for<'b> Fn(&mut Ui, &mut V, &mut AdjustDialogCx<'b>) -> type JsonForm = dyn Fn(&V, bool) -> serde_json::Map + Send; /// An Image › Adjustments dialog the [`DialogHost`](craft_ui::dialog::DialogHost) owns: an adjustment editor over a -/// value `V` the host keeps, in a form dialog with OK and Cancel beside the editor (Alt turns Cancel into Reset, which -/// restores the value the dialog opened with) and the Preview box under them. The editor runs in its dialog form +/// value `V` the host keeps, in a form dialog with the Preview box at the start of the footer and OK and Cancel at its +/// end (Alt turns Cancel into Reset, which restores the value the dialog opened with). The editor runs in its dialog form /// ([`AdjustContext::dialog`]). What the editor asks of the app (Levels' Auto, Black & White's Auto) is an `E` that /// waits in [`take_asks`](Self::take_asks). It answers with the value at OK. /// diff --git a/crates/imaging/src/ui/adjust/levels_panel.rs b/crates/imaging/src/ui/adjust/levels_panel.rs index 9e5c44d1b..62951796c 100644 --- a/crates/imaging/src/ui/adjust/levels_panel.rs +++ b/crates/imaging/src/ui/adjust/levels_panel.rs @@ -1,5 +1,5 @@ -//! [`LevelsPanel`]: the Levels adjustment around the [`LevelsEditor`]: the Channel select, Auto, -//! the editor over the shown channel's histogram and the point pickers. +//! [`LevelsPanel`]: the Levels adjustment around the [`LevelsEditor`]: the point pickers, the +//! Channel select, Auto and the editor over the shown channel's histogram. #[cfg(feature = "screen-testing")] mod stories; @@ -78,20 +78,19 @@ impl Outcome for LevelsPanelOutput { /// The Levels adjustment: Image › Adjustments › Levels and a Levels layer's Properties panel /// (the same call with [`AdjustContext::properties`]). /// -/// Top to bottom (PhotoCraft's and Photoshop's order): -/// 1. The Channel select ([`ToneChannels`]; an isolated channel is the only entry, named as given) +/// Top to bottom (PhotoCraft's order): +/// 1. With [`pickers`](Self::pickers), the [`TonePickerRow`]: Set Black, Neutral Gray, White Point. +/// 2. The Channel select ([`ToneChannels`]; an isolated channel is the only entry, named as given) /// and Auto. Picking a channel shows that channel's levels and histogram; the choice is the /// panel's own state, reported as [`LevelsPanelOutput::channel`]. -/// 2. The [`LevelsEditor`] for the shown channel, over its histogram drawn in the channel's colour; +/// 3. The [`LevelsEditor`] for the shown channel, over its histogram drawn in the channel's colour; /// a [`stale`](Self::stale) histogram shows the stale mark. -/// 3. With [`pickers`](Self::pickers), the [`TonePickerRow`] below: Set Black, Neutral Gray, White -/// Point. /// /// - **Auto** sets the shown channel to [`Levels::auto`] of its histogram as one `Set`; without a /// histogram it is disabled. /// - **Edits**: the editor's events pass through for the shown channel, mapped onto the per-channel /// values. -/// - **Keyboard**: Tab visits the Channel select, Auto, the editor, then the pickers. +/// - **Keyboard**: Tab visits the pickers, the Channel select, Auto, then the editor. #[must_use = "show the panel with `show`"] #[derive(Pattern, Props)] pub struct LevelsPanel<'a> { @@ -105,7 +104,7 @@ pub struct LevelsPanel<'a> { /// The histograms are being recounted. #[prop] stale: bool, - /// The armed point picker; the picker row shows when it is given. + /// The armed point picker; the picker row shows, first, when it is given. #[prop] pickers: Option>>, /// The document canvas the armed picker samples. @@ -178,6 +177,22 @@ impl<'a> LevelsPanel<'a> { // Alt+2…Alt+6 pick the Channel select's entry in a dialog; Properties has no such keys. let stack = if context.is_dialog() { stack.command_scope(ToneChannelCommands::SCOPE) } else { stack }; let group = stack.show(ui, |ui, cx| { + if let Some(armed) = pickers.as_mut() { + let mut row = TonePickerRow::new(armed.reborrowed()); + if pickers_unavailable { + row = row.unavailable(); + } + if let Some(canvas) = canvas { + row = row.canvas(canvas); + } + for each in TonePicker::ALL { + // A grey document has no Neutral Gray point. + let usable = picker_enabled[each as usize] && !(each == TonePicker::Gray && (channels.is_gray() || context.is_gray())); + row = row.enabled_picker(each, usable); + } + picker = row.show(ui).change; + } + let all: Vec = match levels.reborrow().read(cx) { Some(Mixed::Same(all)) => all, _ => Vec::new(), @@ -232,21 +247,6 @@ impl<'a> LevelsPanel<'a> { } edit = events; - if let Some(armed) = pickers.as_mut() { - let mut row = TonePickerRow::new(armed.reborrowed()); - if pickers_unavailable { - row = row.unavailable(); - } - if let Some(canvas) = canvas { - row = row.canvas(canvas); - } - for each in TonePicker::ALL { - // A grey document has no Neutral Gray point. - let usable = picker_enabled[each as usize] && !(each == TonePicker::Gray && (channels.is_gray() || context.is_gray())); - row = row.enabled_picker(each, usable); - } - picker = row.show(ui).change; - } // An edit belongs to the channel it was drawn for; a switch shows from the next pass. shown = if picked == channel || !edit.is_empty() { channel } else { picked }; write_shown(&mut channel_bind, cx, stored, shown); diff --git a/crates/imaging/src/ui/layer_style/blending.rs b/crates/imaging/src/ui/layer_style/blending.rs index 7db5e6681..5d9c7e091 100644 --- a/crates/imaging/src/ui/layer_style/blending.rs +++ b/crates/imaging/src/ui/layer_style/blending.rs @@ -5,7 +5,7 @@ use std::cell::RefCell; use craft_behavior::EditEvents; use craft_ui::choice::Checkbox; use craft_ui::contract::{Bind, Entry, Props as _, Show as _, ShowContainer as _}; -use craft_ui::form::{Field, FieldGroup, SliderField}; +use craft_ui::form::{Field, FieldGroup, SliderField, SliderFieldLayout}; use craft_ui::layout_components::Stack; use craft_ui::pickers::Select; use craft_ui::runtime::env::UnitKind; @@ -200,7 +200,12 @@ fn with_current(modes: &[Entry], current: &str) -> Vec> { /// A 0..=100 % slider and field, whole percent. fn percent(ui: &mut Ui, label: &Label, value: f32) -> craft_ui::contract::EditResponse { - SliderField::new(label.clone(), Bind::given(f64::from(value)), 0.0..=100.0).step(1.0).unit_kind(UnitKind::Percent).show(ui).edit + SliderField::new(label.clone(), Bind::given(f64::from(value)), 0.0..=100.0) + .step(1.0) + .unit_kind(UnitKind::Percent) + .layout(SliderFieldLayout::Inline) + .show(ui) + .edit } /// The Advanced Blending checks' values, in Photoshop's order. diff --git a/crates/imaging/src/ui/layer_style/hosted.rs b/crates/imaging/src/ui/layer_style/hosted.rs index 9c6a5e17e..2d5464cde 100644 --- a/crates/imaging/src/ui/layer_style/hosted.rs +++ b/crates/imaging/src/ui/layer_style/hosted.rs @@ -363,6 +363,7 @@ impl StackDialog for HostedLayerStyle { let shown = FormDialog::new(label.clone(), Bind::bound(&mut *draft)) .opened(Bind::bound(open)) .preview(Some(Bind::bound(&mut preview))) + .side_buttons(true) .extra_buttons([FooterButton::new(new_style, DialogRole::Other)]) .footer_extra(|ui| { if let (Some(paint), Some(draft)) = (preview_thumb.as_deref(), snapshot.as_ref()) { diff --git a/crates/imaging/src/ui/layer_style/page.rs b/crates/imaging/src/ui/layer_style/page.rs index 8536269a4..03d87ee43 100644 --- a/crates/imaging/src/ui/layer_style/page.rs +++ b/crates/imaging/src/ui/layer_style/page.rs @@ -9,7 +9,7 @@ use craft_ui::buttons::Button; use craft_ui::choice::{Checkbox, Swatch}; use craft_ui::contract::{Bind, EditResponse, Entry, Props as _, Show as _, ShowContainer as _, clicked}; use craft_ui::display::Text; -use craft_ui::form::{Field, FieldGroup, SliderField}; +use craft_ui::form::{Field, FieldGroup, SliderField, SliderFieldLayout}; use craft_ui::layout::RowAlign; use craft_ui::layout_components::{Row, Stack}; use craft_ui::patterns::presets::{PresetPicker, PresetRow, PresetState}; @@ -201,8 +201,16 @@ fn field_row(ui: &mut Ui, input: &PageInput<'_>, field: &EffectField, shown: &St if let Some(default) = input.spec.defaults.number(key) { bind = bind.reset(default); } - let slider = SliderField::new(label.clone(), bind.reborrowed(), *min..=*max).unit_kind(unit_kind(*unit)).step(1.0).id_salt(key).show(ui); - push_edit(&mut out.edit, style_edit(&slider, input.style, |v| param(StyleValue::Number(v.round())))); + let slider = Field::new(label.clone()).id_salt(key).show(ui, |ui, _| { + SliderField::new(label.clone(), bind.reborrowed(), *min..=*max) + .unit_kind(unit_kind(*unit)) + .step(1.0) + .layout(SliderFieldLayout::Inline) + .show(ui) + }); + if let Some(slider) = slider.inner { + push_edit(&mut out.edit, style_edit(&slider, input.style, |v| param(StyleValue::Number(v.round())))); + } } FieldKind::Angle => { let value = shown.number(key).unwrap_or(0.0); diff --git a/crates/print/src/ui/dialog.rs b/crates/print/src/ui/dialog.rs index b44d8b64c..a8c0124d6 100644 --- a/crates/print/src/ui/dialog.rs +++ b/crates/print/src/ui/dialog.rs @@ -16,7 +16,7 @@ use craft_ui::runtime::env::{Env, Label}; use craft_ui::runtime::focus::{ActivateKeys, KeepKeys, KeyUse}; use craft_ui::runtime::overlay::CloseReason; use craft_ui::runtime::requests::HostAnswer; -use craft_ui::sections::{DialogRole, FooterButton}; +use craft_ui::sections::{DialogRole, FooterButton, Section}; use craft_ui::style::{ComponentStyle, Corners, RuleKind, StyleCx, SurfaceKind}; use egui::load::SizedTexture; use egui::{Pos2, Rect, Response, Ui, Vec2, pos2, vec2}; @@ -31,6 +31,7 @@ craft_ui::words! { print: "printDialog.print" = "Print"; done: "printDialog.done" = "Done"; preview: "printDialog.preview" = "Print preview image"; + printer_setup: "printDialog.printerSetup" = "Printer Setup"; image_box: "printDialog.imageBox" = "Image box"; } } @@ -461,11 +462,15 @@ impl<'a> PrintDialog<'a> { Text::new(sheet.readout.clone()).show(ui); }); Stack::new().show(ui, |ui, _| { - let panel = PrintPanel::new(settings.reborrowed(), printers).discovering(discovering).busy(busy).show(ui); - refresh |= panel.refresh; - for section in sections { - let mut rows = ParamRows::new(section.title.clone(), §ion.params, Bind::bound(&mut *values)).show(ui); - form.requests().absorb(&mut rows); + Section::fixed(words.printer_setup.clone()).id_salt("printer").show(ui, |ui, _| { + let panel = PrintPanel::new(settings.reborrowed(), printers).discovering(discovering).busy(busy).show(ui); + refresh |= panel.refresh; + }); + for (at, section) in sections.iter().enumerate() { + Section::fixed(section.title.clone()).id_salt(("section", at)).show(ui, |ui, _| { + let mut rows = ParamRows::new(section.title.clone(), §ion.params, Bind::bound(&mut *values)).show(ui); + form.requests().absorb(&mut rows); + }); } }); }); diff --git a/crates/ui-contract/src/runtime/env/units.rs b/crates/ui-contract/src/runtime/env/units.rs index 65a4cdeb1..5e9de334e 100644 --- a/crates/ui-contract/src/runtime/env/units.rs +++ b/crates/ui-contract/src/runtime/env/units.rs @@ -1,7 +1,7 @@ //! `Units`: what typed number input and unit readouts need from the env (core 2.1): the locale's separators and the //! unit spellings of a number's kind in the user's language, and the file sizes and durations written with them. -use super::EnvValue; +use super::{EnvValue, Label}; use craft_behavior::NumberCodec; use craft_behavior::quantity::{Reader, is_unit_spelling}; use craft_i18n::{FileSize, Format, WordSet as _, Words}; @@ -10,7 +10,8 @@ use std::ops::RangeInclusive; use std::sync::{Arc, OnceLock}; craft_ui::words! { - /// The unit words: `{n}` is where the number goes. + /// The unit words: `{n}` is where the number goes. The `_name` words name a unit in a list of units (a unit + /// select), without a number. pub struct UnitWords { pixels: unit "units.pixels" = "{n} px"; percent: unit "units.percent" = "{n}%"; @@ -28,6 +29,21 @@ craft_ui::words! { lines_per_centimetre: unit "units.linesPerCentimetre" = "{n} lpcm"; minutes: unit "units.minutes" = "{n} min"; columns: unit "units.columns" = "{n} col"; + pixels_name: "units.pixelsName" = "Pixels"; + percent_name: "units.percentName" = "Percent"; + degrees_name: "units.degreesName" = "Degrees"; + points_name: "units.pointsName" = "Points"; + times_name: "units.timesName" = "Times"; + inches_name: "units.inchesName" = "Inches"; + centimetres_name: "units.centimetresName" = "Centimetres"; + millimetres_name: "units.millimetresName" = "Millimetres"; + picas_name: "units.picasName" = "Picas"; + pixels_per_inch_name: "units.pixelsPerInchName" = "Pixels/Inch"; + pixels_per_centimetre_name: "units.pixelsPerCentimetreName" = "Pixels/Centimetre"; + minutes_name: "units.minutesName" = "Minutes"; + columns_name: "units.columnsName" = "Columns"; + lines_per_inch_name: "units.linesPerInchName" = "Lines/Inch"; + lines_per_centimetre_name: "units.linesPerCentimetreName" = "Lines/Centimetre"; } } @@ -342,6 +358,29 @@ impl Units { } } + /// The unit's name in the user's language, as a list of units shows it: Pixels, Pixels/Inch. + pub fn name(&self, kind: UnitKind) -> Label { + let words = &*self.words; + let name = match kind { + UnitKind::Pixels => &words.pixels_name, + UnitKind::Percent => &words.percent_name, + UnitKind::Degrees => &words.degrees_name, + UnitKind::Points => &words.points_name, + UnitKind::Times => &words.times_name, + UnitKind::Inches => &words.inches_name, + UnitKind::Centimetres => &words.centimetres_name, + UnitKind::Millimetres => &words.millimetres_name, + UnitKind::Picas => &words.picas_name, + UnitKind::PixelsPerInch => &words.pixels_per_inch_name, + UnitKind::PixelsPerCentimetre => &words.pixels_per_centimetre_name, + UnitKind::Minutes => &words.minutes_name, + UnitKind::Columns => &words.columns_name, + UnitKind::LinesPerInch => &words.lines_per_inch_name, + UnitKind::LinesPerCentimetre => &words.lines_per_centimetre_name, + }; + name.clone() + } + /// The unit's spelling in the user's language without the number: `mm`, `px`. pub fn symbol(&self, kind: UnitKind) -> String { self.template(kind).replace("{n}", "").trim().to_owned() diff --git a/crates/ui-patterns/src/patterns/form_dialogs/dialog.rs b/crates/ui-patterns/src/patterns/form_dialogs/dialog.rs index 9106347b7..fb0d69635 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/dialog.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/dialog.rs @@ -17,6 +17,7 @@ use crate::contract::{Bind, BodyCx, CanvasGesture, NoValue, Outcome, Remember as use crate::dialog::{Alert, Dialog, DialogId, DialogResult, DialogStack, FieldRefusal, FooterHooks, HeldAnswer, HeldOk, StackDialog, dialog_id}; use crate::display::{Shade, Text}; +use crate::form::SliderFieldLayout; use crate::layout_components::{Row, Stack}; use crate::notices::{Notice, NoticeLayout}; @@ -47,15 +48,37 @@ craft_ui::words! { } } -/// Where the preview pane sits. +/// How a parameter dialog arranges its rows, its preview pane and its buttons. #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] #[non_exhaustive] pub enum ParamLayout { - /// The preview pane to the right of the rows, under the zoom row. + /// The preview pane to the right of the rows, under the zoom row. A dialog that previews has its buttons in a + /// column beside the body, with the Preview check box under them. #[default] Beside, - /// The preview pane under the rows. + /// The preview pane under the rows, under the zoom row. A dialog that previews has its buttons in a column beside + /// the body, with the Preview check box under them: Photoshop's filter dialogs. Below, + /// One column: each slider row stacked (the label and the number field with its unit on one line, a full-width + /// slider under them), then the preview pane with the zoom row under it, and the buttons across the foot with the + /// Preview check box at their start: PhotoCraft's filter dialogs. The other rows keep the form's label and control + /// columns. + Stacked, +} + +impl ParamLayout { + /// Whether a dialog that previews stands its buttons in a column beside the body. + fn side_buttons(self) -> bool { + !matches!(self, ParamLayout::Stacked) + } + + /// How the range rows arrange their slider and number field. + fn sliders(self) -> SliderFieldLayout { + match self { + ParamLayout::Stacked => SliderFieldLayout::Stacked, + ParamLayout::Beside | ParamLayout::Below => SliderFieldLayout::Inline, + } + } } /// What a parameter dialog answers with at OK. @@ -139,8 +162,8 @@ impl Outcome for ParamDialogOutput { /// fills the parameters' defaults and, with `remember`, the values saved by [`ParamResult::remember`]. /// - Preview: a dialog that `previews` has the Preview check box; the host renders from the reported values while /// `preview_on` (on the canvas, or as the picture it hands to `preview`), the unfiltered picture while `comparing` -/// (the Preview check box held down). Drag pans the picture, the zoom buttons scale it. A dialog that previews has -/// its buttons in a column beside the body, with the Preview check box and the footer note under them. +/// (the Preview check box held down). Drag pans the picture, the zoom buttons scale it. The +/// [`layout`](ParamDialog::layout) places the pane and the buttons. /// - Footer: [`extra_buttons`](ParamDialog::extra_buttons) keep the dialog open and come back as /// `ParamDialogOutput::footer_action`; [`footer_note`](ParamDialog::footer_note) is a muted line at the start edge. /// - A command form is a dialog with no preview and no remember key. @@ -191,7 +214,7 @@ pub struct ParamDialog<'a> { /// keys added since the open go. #[prop] reset_to: Option, - /// Where the preview pane sits. + /// How the rows, the preview pane and the buttons are arranged. #[prop] layout: ParamLayout, /// Whether the title row has a close action. @@ -459,7 +482,7 @@ impl<'a> ParamDialog<'a> { form = form.opened(open); } if previews { - form = form.preview(preview_on); + form = form.preview(preview_on).side_buttons(layout.side_buttons()); } // The pane shows only in a dialog that previews. let preview = preview.filter(|_| previews); @@ -523,7 +546,10 @@ impl<'a> ParamDialog<'a> { live.view = live.view.centred_on(point, texture.size); } let mut show_rows = |ui: &mut Ui, values: &mut DialogFields| { - let mut shown = ParamRows::new(title.clone(), ¶ms, Bind::bound(values)).patterns(&patterns).preview_colors(&preview_colors); + let mut shown = ParamRows::new(title.clone(), ¶ms, Bind::bound(values)) + .patterns(&patterns) + .preview_colors(&preview_colors) + .sliders(layout.sliders()); if let Some(canvas) = canvas { shown = shown.canvas(canvas); } @@ -533,13 +559,15 @@ impl<'a> ParamDialog<'a> { (Some(texture), ParamLayout::Beside) => { Row::new().show(ui, |ui, _| { show_rows(ui, values); - Stack::new().show(ui, |ui, _| shown_preview = show_preview(ui, &preview_label, texture, click_centres, &mut live)); + Stack::new() + .show(ui, |ui, _| shown_preview = show_preview(ui, &preview_label, texture, click_centres, ZoomRow::Above, &mut live)); }); } - (Some(texture), ParamLayout::Below) => { + (Some(texture), layout) => { + let zoom = if layout == ParamLayout::Stacked { ZoomRow::Below } else { ZoomRow::Above }; Stack::new().show(ui, |ui, _| { show_rows(ui, values); - shown_preview = show_preview(ui, &preview_label, texture, click_centres, &mut live); + shown_preview = show_preview(ui, &preview_label, texture, click_centres, zoom, &mut live); }); } (None, _) => show_rows(ui, values), @@ -722,12 +750,20 @@ struct ShownPreview { centre: Option, } +/// Where the zoom row stands: over the preview pane or under it. +#[derive(Clone, Copy, PartialEq, Eq)] +enum ZoomRow { + Above, + Below, +} + /// The zoom row and the pane. -fn show_preview(ui: &mut Ui, label: &Label, texture: &SizedTexture, click_centres: bool, live: &mut Live) -> ShownPreview { - let zoom = PreviewZoom::new(&live.view).show(ui); +fn show_preview(ui: &mut Ui, label: &Label, texture: &SizedTexture, click_centres: bool, zoom_row: ZoomRow, live: &mut Live) -> ShownPreview { + let above = (zoom_row == ZoomRow::Above).then(|| PreviewZoom::new(&live.view).show(ui)); let pane = PreviewPane::new(label.clone(), *texture, &live.view).click_centres(click_centres).show(ui); + let below = (zoom_row == ZoomRow::Below).then(|| PreviewZoom::new(&live.view).show(ui)); let centre = pane.shown.centre(texture.size); - live.view = zoom.view.or(pane.view).unwrap_or(pane.shown); + live.view = above.or(below).and_then(|zoom| zoom.view).or(pane.view).unwrap_or(pane.shown); ShownPreview { clicked: pane.clicked, centre: Some(centre) } } diff --git a/crates/ui-patterns/src/patterns/form_dialogs/dialog/stories.rs b/crates/ui-patterns/src/patterns/form_dialogs/dialog/stories.rs index ef90768a1..c444e9a44 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/dialog/stories.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/dialog/stories.rs @@ -27,15 +27,15 @@ fn picture(ui: &Ui, unfiltered: bool) -> SizedTexture { SizedTexture::new(id, Vec2::new(PICTURE[0] as f32, PICTURE[1] as f32)) } -const LAYOUTS: [(&str, ParamLayout); 2] = [("Beside", ParamLayout::Beside), ("Below", ParamLayout::Below)]; +const LAYOUTS: [(&str, ParamLayout); 3] = [("Beside", ParamLayout::Beside), ("Below", ParamLayout::Below), ("Stacked", ParamLayout::Stacked)]; /// A blur dialog with the `preview` and `layout` values of the story. fn blur_story(ui: &mut Ui, data: &mut StoryData, preview: bool, layout: ParamLayout) -> StoryOutput { let preview = *data.value("preview", preview); let layout = *data.choice("layout", layout, &LAYOUTS); let comparing = *data.value("comparing", false); - let dialog = ParamDialog::new("blur", "Blur", Param::parse_list(SPEC)).opened(Bind::bound(data.value("open", true))).history(true); - let dialog = if preview { dialog.previews(true).preview(picture(ui, comparing)).layout(layout) } else { dialog }; + let dialog = ParamDialog::new("blur", "Blur", Param::parse_list(SPEC)).opened(Bind::bound(data.value("open", true))).history(true).layout(layout); + let dialog = if preview { dialog.previews(true).preview(picture(ui, comparing)) } else { dialog }; let shown = dialog.show(ui); *data.value("comparing", false) = shown.comparing; shown.into() @@ -56,6 +56,12 @@ fn param_dialog_with_preview_below(ui: &mut Ui, data: &mut StoryData) -> StoryOu blur_story(ui, data, true, ParamLayout::Below) } +/// PhotoCraft's filter dialogs: stacked slider rows, the pane with the zoom row under it, the buttons across the foot. +#[story(ParamDialog<'static>, covers = [], drive = Drive::Never)] +fn param_dialog_stacked(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { + blur_story(ui, data, true, ParamLayout::Stacked) +} + #[story(ParamDialog<'static>, covers = [], drive = Drive::Never)] fn param_dialog_close_without_reset(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { ParamDialog::new("blur", "Blur", Param::parse_list(SPEC)) diff --git a/crates/ui-patterns/src/patterns/form_dialogs/export.rs b/crates/ui-patterns/src/patterns/form_dialogs/export.rs index b0acc9689..7eef8f472 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/export.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/export.rs @@ -32,6 +32,7 @@ craft_ui::words! { pub struct ExportWords { title: "export.title" = "Export As"; export: "export.export" = "Export…"; + file_settings: "export.fileSettings" = "File Settings"; format: "export.format" = "Format"; quality: "export.quality" = "Quality"; lossless: "export.lossless" = "Lossless"; diff --git a/crates/ui-patterns/src/patterns/form_dialogs/export/as_dialog.rs b/crates/ui-patterns/src/patterns/form_dialogs/export/as_dialog.rs index cbbd0bbae..90dbccd30 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/export/as_dialog.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/export/as_dialog.rs @@ -32,7 +32,7 @@ use crate::pickers::Select; use crate::runtime::env::{Env, Label, UnitKind, Units}; use crate::runtime::overlay::CloseReason; -use crate::sections::{HeaderStrength, Section}; +use crate::sections::Section; use crate::style::TypeRole; use crate::text::NumberField; @@ -650,6 +650,26 @@ struct Pass<'p> { impl Pass<'_> { fn settings(&self, ui: &mut Ui, options: &mut ExportOptions, held: &mut Held) { + let words = self.words; + let mut format = None; + Section::fixed(words.file_settings.clone()).id_salt("file").show(ui, |ui, _| format = self.file_settings(ui, options)); + let Some(format) = format else { return }; + Section::fixed(words.color_space.clone()).id_salt("color-space").show(ui, |ui, _| { + let mut srgb = options.profile == ExportProfile::Srgb; + check(ui, &words.convert_srgb, "profile", &mut srgb); + options.profile = if srgb { ExportProfile::Srgb } else { ExportProfile::Document }; + check(ui, &words.embed_profile, "embed", &mut options.embed_profile); + }); + + Section::fixed(words.image_size.clone()).id_salt("size").show(ui, |ui, _| self.size(ui, options, held, format)); + Section::fixed(words.scale_all.clone()).id_salt("scale-all").show(ui, |ui, _| self.scale_all(ui, options)); + if let Some(library) = self.library { + self.preset_row(ui, options, held, library); + } + } + + /// File Settings: the format, its options and the metadata; the format shown, `None` when the list has none. + fn file_settings(&self, ui: &mut Ui, options: &mut ExportOptions) -> Option<&ExportFormat> { let words = self.words; let chosen = self.formats.iter().position(|format| format.id == options.format).unwrap_or(0); let entries: Vec> = self.formats.iter().enumerate().map(|(at, format)| Entry::new(at, format.name)).collect(); @@ -658,7 +678,7 @@ impl Pass<'_> { if now != chosen { self.switch(options, now); } - let Some(format) = self.formats.get(now) else { return }; + let format = self.formats.get(now)?; if format.lossless { check(ui, &words.lossless, "lossless", &mut options.lossless); @@ -689,21 +709,7 @@ impl Pass<'_> { Entry::new(ExportMetadata::All, words.metadata_all.clone()), ]; choose(ui, &words.metadata, "metadata", &metadata, &mut options.metadata); - Section::fixed(words.color_space.clone()).strength(HeaderStrength::Caption).id_salt("color-space").show(ui, |ui, _| { - let mut srgb = options.profile == ExportProfile::Srgb; - check(ui, &words.convert_srgb, "profile", &mut srgb); - options.profile = if srgb { ExportProfile::Srgb } else { ExportProfile::Document }; - check(ui, &words.embed_profile, "embed", &mut options.embed_profile); - }); - - Section::fixed(words.image_size.clone()) - .strength(HeaderStrength::Caption) - .id_salt("size") - .show(ui, |ui, _| self.size(ui, options, held, format)); - Section::fixed(words.scale_all.clone()).strength(HeaderStrength::Caption).id_salt("scale-all").show(ui, |ui, _| self.scale_all(ui, options)); - if let Some(library) = self.library { - self.preset_row(ui, options, held, library); - } + Some(format) } /// The preset row under Image Size: a pick applies the preset's options, and each new, renamed or deleted preset diff --git a/crates/ui-patterns/src/patterns/form_dialogs/form.rs b/crates/ui-patterns/src/patterns/form_dialogs/form.rs index 8b0fa5e7c..b41cd4dbb 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/form.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/form.rs @@ -158,8 +158,9 @@ type ResetWithFn<'a, V> = Box V + 'a>; /// - The body returns whether the value can be accepted; OK is enabled while it can and `ok_enabled` is true. /// - With [`history`](FormDialog::history), Cmd/Ctrl+Z and Shift+Cmd/Ctrl+Z step the dialog's own value; a drag or a /// typing run is one step. -/// - With [`preview`](FormDialog::preview), the buttons stand in a column beside the body, with the Preview check box -/// and the footer controls under them. +/// - The footer goes across the foot, the Preview check box and the footer controls at its start edge; with +/// [`side_buttons`](FormDialog::side_buttons) the buttons stand in a column beside the body, with the Preview check +/// box and the footer controls under them. #[must_use = "show the dialog with `show`"] #[derive(crate::contract::Pattern)] #[pattern(probe(FormDialog<'static, bool>))] @@ -179,6 +180,7 @@ pub struct FormDialog<'a, V: Value + Default> { closable: bool, accept_stays_open: bool, enter_confirms: bool, + side_buttons: bool, footer_extra: Option>, /// The Preview check box when shown, over its owner's bind or (`None`) the footer's memory. preview: Option>>, @@ -210,6 +212,7 @@ impl<'a, V: Value + Default> FormDialog<'a, V> { closable: true, accept_stays_open: false, enter_confirms: true, + side_buttons: false, footer_extra: None, preview: None, extra_buttons: Vec::new(), @@ -308,15 +311,21 @@ impl<'a, V: Value + Default> FormDialog<'a, V> { self } - /// The Preview check box, first under the buttons, which stand beside the body: the host previews the value while - /// it is on, and the unfiltered picture while it is held ([`FormOutput::comparing`]). With `on`, the box reads and - /// writes that bind (a kept bind starts on). Without it, every open starts with the box on, and the dialog keeps - /// it off while it stays open. + /// The Preview check box, first in the footer: the host previews the value while it is on, and the unfiltered + /// picture while it is held ([`FormOutput::comparing`]). With `on`, the box reads and writes that bind (a kept + /// bind starts on). Without it, every open starts with the box on, and the dialog keeps it off while it stays open. pub fn preview(mut self, on: Option>) -> Self { self.preview = Some(on); self } + /// Whether the buttons stand in a column beside the body, with the Preview check box and the footer controls under + /// them (`Dialog::side_buttons`), instead of across the foot: Photoshop's button-column dialogs. + pub fn side_buttons(mut self, on: bool) -> Self { + self.side_buttons = on; + self + } + /// Footer buttons after OK and Cancel, which keep the dialog open: the caller acts on /// [`FormOutput::picked`]. pub fn extra_buttons(mut self, buttons: impl IntoIterator) -> Self { @@ -375,6 +384,7 @@ impl<'a, V: Value + Default> FormDialog<'a, V> { closable, accept_stays_open, enter_confirms, + side_buttons, footer_extra, preview, extra_buttons, @@ -413,7 +423,11 @@ impl<'a, V: Value + Default> FormDialog<'a, V> { } } }; - let mut dialog = Dialog::new(title).closable(closable).close_on_enter(ok_enabled && enter_confirms).outer_gesture(outer_gesture); + let mut dialog = Dialog::new(title) + .closable(closable) + .close_on_enter(ok_enabled && enter_confirms) + .outer_gesture(outer_gesture) + .side_buttons(side_buttons); dialog = reset.install(dialog, accept, restore); if let Some(open) = open { dialog = dialog.opened(open); @@ -423,9 +437,6 @@ impl<'a, V: Value + Default> FormDialog<'a, V> { } let changed = RefCell::new(None::); let (preview_on, comparing) = (Rc::new(Cell::new(false)), Rc::new(Cell::new(false))); - if preview.is_some() { - dialog = dialog.side_buttons(true); - } if footer_extra.is_some() || preview.is_some() { let (on, held, label) = (Rc::clone(&preview_on), Rc::clone(&comparing), env.words::().preview.clone()); let (mut extra, mut preview) = (footer_extra, preview); diff --git a/crates/ui-patterns/src/patterns/form_dialogs/guides.rs b/crates/ui-patterns/src/patterns/form_dialogs/guides.rs index 3bc28b93e..5e2dfdb1b 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/guides.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/guides.rs @@ -331,7 +331,7 @@ impl<'a> GuideLayoutDialog<'a> { let env = Env::of(ui); let words = env.words::(); let number_units = env.units(); - let mut dialog = FormDialog::new(words.layout_title.clone(), values).outer_gesture(true).answers(answers).preview(preview); + let mut dialog = FormDialog::new(words.layout_title.clone(), values).outer_gesture(true).answers(answers).preview(preview).side_buttons(true); if let Some(open) = open { dialog = dialog.opened(open); } diff --git a/crates/ui-patterns/src/patterns/form_dialogs/new_document/details.rs b/crates/ui-patterns/src/patterns/form_dialogs/new_document/details.rs index 538136904..a287ae5e9 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/new_document/details.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/new_document/details.rs @@ -80,9 +80,9 @@ fn apply_number(session: &mut Session, events: &EditEvents>, set: im } } -/// The entries of a unit list, named by the units' symbols. +/// The entries of a unit list, named by the units' names. fn unit_entries(read: &Read<'_>, kinds: &[UnitKind]) -> Vec> { - kinds.iter().map(|kind| Entry::new(*kind, read.units.symbol(*kind))).collect() + kinds.iter().map(|kind| Entry::new(*kind, read.units.name(*kind))).collect() } /// Shows the column. diff --git a/crates/ui-patterns/src/patterns/form_dialogs/rows.rs b/crates/ui-patterns/src/patterns/form_dialogs/rows.rs index 4b7eb3994..2ee03c78a 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/rows.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/rows.rs @@ -90,7 +90,9 @@ impl Outcome for ParamRowsOutput { /// - **Values.** They live in the caller's [`DialogFields`] binding; a missing key shows its parameter's default, /// which the pass writes. The host keeps its own history of the values and its own Reset. /// - **Rows.** A row is shown while its `visible_when` holds and takes input while its `enabled_when` holds. A -/// [`Param::section`] opens a section whose body is the rows up to the next section. +/// [`Param::section`] opens a section, a bold title under a rule, whose body is the rows up to the next section. +/// A range row is a slider and its number field beside the row's label, or stacked under the label +/// ([`sliders`](ParamRows::sliders)). /// - **Requests.** A colour press, a Browse press and the eyedropper toggle come back in [`ParamRowsOutput`]. /// - **Random.** The Random button of an int row draws from a sequence seeded by `seed`'s binding; without one the /// sequence starts the same in every run. @@ -107,12 +109,31 @@ pub struct ParamRows<'a> { canvas: Option, patterns: &'a [PresetRow], preview_colors: &'a [(String, Srgba)], + sliders: SliderFieldLayout, } impl<'a> ParamRows<'a> { /// Rows for `params` over `fields`, the group named `label`. pub fn new(label: impl Into