diff --git a/crates/ui-egui/src/animpane_tests.rs b/crates/ui-egui/src/animpane_tests.rs index 856b1627b..0c2855577 100644 --- a/crates/ui-egui/src/animpane_tests.rs +++ b/crates/ui-egui/src/animpane_tests.rs @@ -58,6 +58,17 @@ fn after_previous_bar_starts_where_the_first_ends() { assert!((b.width() - 2.0 * a.width()).abs() < 1.5, "2 s bar twice the 1 s bar"); } +#[test] +fn a_long_name_keeps_the_timeline_column() { + let mut h = harness(); + let before = h.get_by_role_and_label(egui::accesskit::Role::Slider, "Timing bar 1").rect(); + let id = h.state().session.active().unwrap().current_slide().unwrap().animations[0].shape.0; + h.state_mut().run("shape.rename", json!({"id": id, "name": "Aurora borealis over the northern lakes at midnight in winter"})).unwrap(); + h.run_steps(3); + let after = h.query_by_role_and_label(egui::accesskit::Role::Slider, "Timing bar 1").map(|node| node.rect()); + assert!(after.is_some_and(|after| after.width() >= before.width() - 0.5), "{before:?} {after:?}"); +} + #[test] fn dragging_a_bar_sets_the_delay_and_undoes() { let mut h = harness(); diff --git a/crates/ui-egui/src/panels/animation.rs b/crates/ui-egui/src/panels/animation.rs index e6396e085..d0e8fea8f 100644 --- a/crates/ui-egui/src/panels/animation.rs +++ b/crates/ui-egui/src/panels/animation.rs @@ -113,10 +113,11 @@ pub(super) fn animation(app: &mut SlideApp, ui: &mut Ui) { let seconds = animtimeline::ruler_seconds(&bars); let range = 0.0..=f64::from(seconds); let every = (seconds / 6).max(1); + // The name and the timeline share the row, so a long name elides and the timeline keeps its column. let columns = vec![ craft::ui::contract::ColumnSpec::new(CLICK, Label::Empty, ColumnWidth::Content), - craft::ui::contract::ColumnSpec::new(NAME, Label::Empty, ColumnWidth::Content), - craft::ui::contract::ColumnSpec::new(TIMING, Label::Empty, ColumnWidth::fill(1.0)).at_least(Env::of(ui).tokens.size.length.track), + craft::ui::contract::ColumnSpec::new(NAME, Label::Empty, ColumnWidth::fill(2.0)), + craft::ui::contract::ColumnSpec::new(TIMING, Label::Empty, ColumnWidth::fill(3.0)).at_least(Env::of(ui).tokens.size.length.track), craft::ui::contract::ColumnSpec::new(REPEAT, Label::Empty, ColumnWidth::Controls(1.0)), ]; let commits = RefCell::new(Vec::new()); diff --git a/crates/ui-egui/src/panels/background.rs b/crates/ui-egui/src/panels/background.rs index 412c4fd0a..49a361ad7 100644 --- a/crates/ui-egui/src/panels/background.rs +++ b/crates/ui-egui/src/panels/background.rs @@ -110,7 +110,7 @@ pub(super) fn background(app: &mut SlideApp, ui: &mut Ui) { _ => None, }; let picture = matches!(fill, Some(Fill::Picture(_))); - let mut buttons = Row::new().show(ui, |ui, _| { + let mut buttons = Row::new().wrap(true).show(ui, |ui, _| { let apply = Button::new(Word::plain("Apply to All")).enabled(current.is_some() || picture).show(ui).clicked(); let reset = Button::new(Word::plain("Reset Background")).show(ui).clicked(); (apply, reset) @@ -130,7 +130,10 @@ pub(super) fn background(app: &mut SlideApp, ui: &mut Ui) { } fn transparency(ui: &mut Ui, alpha: f64) -> Option { - let result = SliderField::new(Word::plain("Transparency"), Bind::given((1.0 - alpha) * 100.0), 0.0..=100.0).unit_kind(UnitKind::Percent).show(ui); + let result = SliderField::new(Word::plain("Transparency"), Bind::given((1.0 - alpha) * 100.0), 0.0..=100.0) + .unit_kind(UnitKind::Percent) + .field_decimals(super::format_shape::TRANSPARENCY_DECIMALS) + .show(ui); result.events.committed().map(|value| json!({"transparency": value / 100.0})) } diff --git a/crates/ui-egui/src/panels/color_row.rs b/crates/ui-egui/src/panels/color_row.rs index b6b5d2283..1cfdd6fe1 100644 --- a/crates/ui-egui/src/panels/color_row.rs +++ b/crates/ui-egui/src/panels/color_row.rs @@ -1,11 +1,13 @@ //! Colour rows share the same conversion and delayed eyedropper route as ribbon menus. use craft::color_ui::ui::{ColorPick, ThemeColorMenu}; +use craft::theme::Srgba; use craft::ui::buttons::Button; use craft::ui::contract::{Bind, BodyCx, FieldLayout, Props as _, Show as _, ShowContainer as _, Trigger}; use craft::ui::controls::disclosure::DisclosureGlyph; use craft::ui::form::Field; use craft::ui::popover::Popover; +use craft::ui::primitives::IconSpec; use craft::ui::runtime::env::{Env, Label, Word}; use deckcraft_model::ColorRef; use egui::Ui; @@ -61,6 +63,19 @@ pub(crate) fn color_row( color_row_named(app, ui, key, label, label == "Color", none, on_pick); } +/// Like [`color_row`], with the opener showing `current` as a chip in place of its word: a colour that is always set +/// (a pattern's foreground and background). +pub(crate) fn color_row_showing( + app: &mut SlideApp, + ui: &mut Ui, + key: &str, + label: &str, + current: Srgba, + on_pick: impl FnOnce(&mut SlideApp, Option), +) { + color_opener(app, ui, key, label, Face::Chip(current), on_pick); +} + /// Like [`color_row`], with the opener named by its label alone (`plain`) or as "{label} color". pub(crate) fn color_row_named( app: &mut SlideApp, @@ -71,12 +86,34 @@ pub(crate) fn color_row_named( none: Option<&str>, on_pick: impl FnOnce(&mut SlideApp, Option), ) { + color_opener(app, ui, key, label, Face::Word { plain, none }, on_pick); +} + +/// What a colour opener shows. +#[derive(Clone, Copy)] +enum Face<'a> { + /// The word "Color", the opener named by its label alone (`plain`) or as "{label} color"; the menu offers `none`. + Word { plain: bool, none: Option<&'a str> }, + /// The current colour as a chip, the opener named "{label} color". + Chip(Srgba), +} + +fn color_opener(app: &mut SlideApp, ui: &mut Ui, key: &str, label: &str, face: Face<'_>, on_pick: impl FnOnce(&mut SlideApp, Option)) { let Some(uid) = app.session.active().map(|st| st.uid) else { return }; let key = format!("fmt-color:{uid}:{key}"); + let (plain, none) = match face { + Face::Word { plain, none } => (plain, none), + Face::Chip(_) => (false, None), + }; let name = if plain { Label::from(Word::plain("Color")) } else { Label::from(Env::of(ui).words::().named.fill(&[("label", label)])) }; let mut field = Field::new(label.to_owned()).layout(FieldLayout::Beside).id_salt(&key).show(ui, |ui, _| { - Button::new(name.clone()).painted(Word::plain("Color")).keeps_name(true).trailing_icon(DisclosureGlyph::dropdown()).show(ui) + let button = Button::new(name.clone()).keeps_name(true).trailing_icon(DisclosureGlyph::dropdown()); + match face { + Face::Chip(color) => button.icon(IconSpec::swatch(color)).painted(Label::Empty), + Face::Word { .. } => button.painted(Word::plain("Color")), + } + .show(ui) }); field.settle(|_, output| { let mut popup = Popover::new(Word::plain("Color"), Bind::kept().reset(false)) diff --git a/crates/ui-egui/src/panels/fillui.rs b/crates/ui-egui/src/panels/fillui.rs index a84924777..70d1ded36 100644 --- a/crates/ui-egui/src/panels/fillui.rs +++ b/crates/ui-egui/src/panels/fillui.rs @@ -5,7 +5,7 @@ use craft::color_ui::gradient::{ColorStop, GradientStops, StopRows, StopRules}; use craft::color_ui::ui::gradient::{GradientEditor, StopFields}; use craft::i18n::Word; -use craft::theme::Srgba; +use craft::theme::{Rgba, Srgba}; use craft::ui::buttons::IconButton; use craft::ui::contract::overlay::Anchor; use craft::ui::contract::{Bind, Entry, FieldLayout, Props as _, Show as _, ShowContainer as _, clicked}; @@ -25,7 +25,7 @@ use deckcraft_model::style::{Gradient, GradientFlip, GradientShape, GradientStop use egui::{Color32, CornerRadius, Rect, Ui, vec2}; use serde_json::{Value, json}; -use super::color_row::{color_menu, color_row, take_color_answer}; +use super::color_row::{color_menu, color_row_showing, take_color_answer}; use super::preset_grid::preset_grid; use crate::ribbon::cref_param; use crate::theme; @@ -456,8 +456,9 @@ pub(crate) fn pattern_editor(app: &mut crate::SlideApp, ui: &mut Ui, p: &Pattern if let Some(preset) = grid.settle(|_, picked| picked.take()).flatten().filter(|preset| preset != &pt.preset) { out = Some(PatternFill { preset, ..pt.clone() }); } - for (label, foreground) in [("Foreground", true), ("Background", false)] { - color_row(app, ui, if foreground { "pattern-foreground" } else { "pattern-background" }, label, None, |_, picked| { + for (label, foreground, current) in [("Foreground", true, fg), ("Background", false, bg)] { + let chip = Srgba::from(Rgba(current.to_srgba_unmultiplied())); + color_row_showing(app, ui, if foreground { "pattern-foreground" } else { "pattern-background" }, label, chip, |_, picked| { if let Some(color) = picked { let pattern = out.get_or_insert_with(|| pt.clone()); if foreground { diff --git a/crates/ui-egui/src/panels/format_shape.rs b/crates/ui-egui/src/panels/format_shape.rs index 6b4fee305..d55fb5010 100644 --- a/crates/ui-egui/src/panels/format_shape.rs +++ b/crates/ui-egui/src/panels/format_shape.rs @@ -9,7 +9,7 @@ use craft::ui::buttons::{Button, IconButton}; use craft::ui::choice::{Checkbox, Radio, RadioGroup, Segmented}; use craft::ui::contract::{Bind, Entry, FieldLayout, Props as _, Show as _, ShowContainer as _}; use craft::ui::display::{Divider, Shade, Text}; -use craft::ui::form::{Field, SliderField, SliderFieldLayout}; +use craft::ui::form::{Field, FieldDecimals, FieldGroup, SliderField, SliderFieldLayout}; use craft::ui::layout_components::{Row, Stack}; use craft::ui::pickers::Select; use craft::ui::primitives::IconSpec; @@ -24,6 +24,9 @@ use super::color_row::color_row; use super::{SlideApp, cref_param, run}; use crate::icons::Icon; +/// A transparency reads to a tenth of a percent ("0.0%"). +pub(crate) const TRANSPARENCY_DECIMALS: FieldDecimals = FieldDecimals::Fixed(1); + /// The formatting pane scale bases and reference options. #[derive(Default)] pub struct FormatPaneState { @@ -98,9 +101,20 @@ fn selection_takes_background_fill(app: &SlideApp) -> bool { ok } -fn slider(ui: &mut Ui, label: &'static str, value: f64, range: std::ops::RangeInclusive, unit: UnitKind) -> Option { +fn slider( + ui: &mut Ui, + label: &'static str, + value: f64, + range: std::ops::RangeInclusive, + unit: UnitKind, + decimals: FieldDecimals, +) -> Option { let mut field = Field::new(Word::plain(label)).layout(FieldLayout::Beside).id_salt(label).show(ui, |ui, _| { - SliderField::new(Word::plain(label), Bind::given(value), range.clone()).layout(SliderFieldLayout::Inline).unit_kind(unit).show(ui) + SliderField::new(Word::plain(label), Bind::given(value), range.clone()) + .layout(SliderFieldLayout::Inline) + .unit_kind(unit) + .field_decimals(decimals) + .show(ui) }); field.settle(|_, output| output.events.committed().copied()).flatten().filter(|shown| *shown != value) } @@ -288,7 +302,7 @@ fn fill_options(app: &mut SlideApp, ui: &mut Ui, sh: &Shape) { Some(Fill::Picture(pf)) => ((1.0 - pf.alpha.unwrap_or(1.0)) * 100.0) as f32, fill => solid_fill_transparency_percent(fill.as_ref()), }; - if let Some(shown) = slider(ui, "Transparency", f64::from(seed), 0.0..=100.0, UnitKind::Percent) + if let Some(shown) = slider(ui, "Transparency", f64::from(seed), 0.0..=100.0, UnitKind::Percent, TRANSPARENCY_DECIMALS) && let Some(value) = fill_transparency_to_apply(shown as f32, seed) { run(app, "shape.fill", json!({"transparency": value})); @@ -511,7 +525,7 @@ fn text_tab(app: &mut SlideApp, ui: &mut Ui, sh: &Shape) { } }); let mut columns = Field::new(Word::plain("Columns")).layout(FieldLayout::Beside).show(ui, |ui, _| { - let mut row = Row::new().show(ui, |ui, _| { + let mut row = Row::new().wrap(true).show(ui, |ui, _| { let mut picked = None; for count in 1..=3 { if Button::new(count.to_string()).show(ui).clicked() { @@ -535,15 +549,22 @@ fn text_tab(app: &mut SlideApp, ui: &mut Ui, sh: &Shape) { fn picture_tab(app: &mut SlideApp, ui: &mut Ui, sh: &Shape) { let ShapeKind::Picture { fill } = &sh.kind else { return }; - for (label, key, value, range) in [ - ("Brightness", "brightness", fill.adjust.brightness * 100.0, -100.0..=100.0), - ("Contrast", "contrast", fill.adjust.contrast * 100.0, -100.0..=100.0), - ("Saturation", "saturation", fill.adjust.saturation.unwrap_or(1.0) * 100.0, 0.0..=400.0), - ("Transparency", "transparency", (1.0 - fill.alpha.unwrap_or(1.0)) * 100.0, 0.0..=100.0), - ] { - if let Some(value) = slider(ui, label, value, range, UnitKind::Percent) { - run(app, "picture.adjust", json!({key: value / 100.0})); + // One label column for the four sliders, so their tracks line up. + let mut adjusts = Vec::new(); + FieldGroup::new(Word::plain("Picture Corrections")).show(ui, |ui, _| { + for (label, key, value, range) in [ + ("Brightness", "brightness", fill.adjust.brightness * 100.0, -100.0..=100.0), + ("Contrast", "contrast", fill.adjust.contrast * 100.0, -100.0..=100.0), + ("Saturation", "saturation", fill.adjust.saturation.unwrap_or(1.0) * 100.0, 0.0..=400.0), + ("Transparency", "transparency", (1.0 - fill.alpha.unwrap_or(1.0)) * 100.0, 0.0..=100.0), + ] { + if let Some(value) = slider(ui, label, value, range, UnitKind::Percent, FieldDecimals::Look) { + adjusts.push(json!({key: value / 100.0})); + } } + }); + for params in adjusts { + run(app, "picture.adjust", params); } if Button::new(Word::plain("Reset Picture")).show(ui).clicked() { run(app, "picture.reset", json!({})); @@ -562,7 +583,7 @@ pub(crate) fn text_transparency_of(sh: &deckcraft_model::Shape) -> f64 { /// Edits the selected text's transparency without a draft shared across shapes. pub(crate) fn text_transparency_slider(app: &mut SlideApp, ui: &mut Ui, sh: &deckcraft_model::Shape) { - if let Some(value) = slider(ui, "Transparency", text_transparency_of(sh) * 100.0, 0.0..=100.0, UnitKind::Percent) { + if let Some(value) = slider(ui, "Transparency", text_transparency_of(sh) * 100.0, 0.0..=100.0, UnitKind::Percent, TRANSPARENCY_DECIMALS) { run(app, "format.textTransparency", json!({"value": value / 100.0})); } } diff --git a/crates/ui-egui/src/panels/format_shape/effects.rs b/crates/ui-egui/src/panels/format_shape/effects.rs index 90fedb63e..4e839693b 100644 --- a/crates/ui-egui/src/panels/format_shape/effects.rs +++ b/crates/ui-egui/src/panels/format_shape/effects.rs @@ -4,7 +4,7 @@ use craft::i18n::Word; use craft::ui::buttons::Button; use craft::ui::choice::Segmented; use craft::ui::contract::{Bind, Entry, Props as _, Show as _, ShowContainer as _}; -use craft::ui::form::{Field, SliderField}; +use craft::ui::form::{Field, FieldDecimals, SliderField}; use craft::ui::pickers::Select; use craft::ui::runtime::env::UnitKind; use craft::ui::sections::Section; @@ -103,8 +103,15 @@ pub(super) fn tab(app: &mut SlideApp, ui: &mut Ui, sh: &deckcraft_model::Shape) } } +/// An effect amount reads in whole units, so a preset's half-point blur reads "0 pt". fn slider(ui: &mut Ui, label: &'static str, value: f64, range: std::ops::RangeInclusive, unit: UnitKind) -> Option { - SliderField::new(Word::plain(label), Bind::given(value), range).unit_kind(unit).show(ui).events.committed().copied() + SliderField::new(Word::plain(label), Bind::given(value), range) + .unit_kind(unit) + .field_decimals(FieldDecimals::Fixed(0)) + .show(ui) + .events + .committed() + .copied() } /// Camel-case preset ids are file-format names; the field presents readable words. diff --git a/crates/ui-egui/src/panels/format_shape_tests.rs b/crates/ui-egui/src/panels/format_shape_tests.rs index a14381117..c3026bcd6 100644 --- a/crates/ui-egui/src/panels/format_shape_tests.rs +++ b/crates/ui-egui/src/panels/format_shape_tests.rs @@ -279,3 +279,20 @@ fn dash_samples_and_direction_buttons_set_what_they_show() -> TestResult { assert!((angle - 180.0).abs() < 0.5, "the 180° button turns the gradient to 180°: {angle}"); Ok(()) } + +#[test] +fn picture_sliders_share_one_column() -> TestResult { + let mut session = Session::with_new(); + session.execute("slide.new", &json!({"layout": "blank"}))?; + let result = session.execute("insert.picture", &json!({"data": picture_data(), "name": "generated.png"}))?; + session.execute("edit.select", &json!({"ids": [result["id"]]}))?; + let mut h = pane(session); + h.state_mut().ui.format_tab = "picture".into(); + h.run_steps(3); + let starts: Vec = ["Brightness", "Contrast", "Saturation", "Transparency"] + .iter() + .map(|label| h.get_by_role_and_label(Role::Slider, label).rect().left()) + .collect(); + assert!(starts.windows(2).all(|pair| (pair[0] - pair[1]).abs() < 0.5), "the sliders start in one column: {starts:?}"); + Ok(()) +} diff --git a/crates/ui-egui/src/panels/pattern_fill_tests.rs b/crates/ui-egui/src/panels/pattern_fill_tests.rs index a33e8b718..f9633cd2f 100644 --- a/crates/ui-egui/src/panels/pattern_fill_tests.rs +++ b/crates/ui-egui/src/panels/pattern_fill_tests.rs @@ -99,5 +99,20 @@ fn shape_pattern_fill_keeps_preset_and_system_colors() { assert_eq!(recolored.fg, ColorRef::rgb(Rgba::from_hex("00FF00").unwrap()), "the hex submission reached the foreground"); assert_eq!(recolored.bg, before.bg, "a foreground edit keeps the system background"); assert_eq!(recolored.preset, picked.preset, "a foreground edit keeps the chosen pattern"); + assert!(paints_color(&h, "Foreground color", egui::Color32::from_rgb(0, 255, 0)), "the opener shows the colour picked"); } } + +/// Whether the button `label` paints `color` inside itself. +fn paints_color(h: &Harness<'_, SlideApp>, label: &str, color: egui::Color32) -> bool { + fn any(shape: &egui::Shape, within: egui::Rect, color: egui::Color32) -> bool { + match shape { + egui::Shape::Vec(shapes) => shapes.iter().any(|shape| any(shape, within, color)), + egui::Shape::Rect(rect) => rect.fill == color && within.contains_rect(rect.rect), + egui::Shape::Mesh(mesh) => mesh.vertices.iter().any(|vertex| vertex.color == color && within.contains(vertex.pos)), + _ => false, + } + } + let button = h.get_by_role_and_label(Role::Button, label).rect().expand(0.5); + h.output().shapes.iter().any(|shape| any(&shape.shape, button, color)) +} diff --git a/crates/ui-egui/src/panels/selpane.rs b/crates/ui-egui/src/panels/selpane.rs index b14240e00..e1c481869 100644 --- a/crates/ui-egui/src/panels/selpane.rs +++ b/crates/ui-egui/src/panels/selpane.rs @@ -144,7 +144,7 @@ fn toolbar(ui: &mut Ui, has_selection: bool, commands: &mut Vec) { Bar::new("Selection actions", BarKind::Tool) .trailing(|ui, _| { for (icon, label, command) in - [(Icon::ChevronDown, "Send Backward", "arrange.sendBackward"), (Icon::ChevronUp, "Bring Forward", "arrange.bringForward")] + [(Icon::ChevronUp, "Bring Forward", "arrange.bringForward"), (Icon::ChevronDown, "Send Backward", "arrange.sendBackward")] { if IconButton::new(icon.id()).label(label).enabled(has_selection).show(ui).clicked() { trailing.push((command, json!({}))); @@ -196,8 +196,8 @@ pub fn show(app: &mut SlideApp, ui: &mut Ui) { let mut line = ListRow::new(row.name.clone()) .depth(row.depth) .cells(icx.cells()) - .toggle(ToggleCell::eye(EYE, !row.hidden).name(if row.hidden { "Show {row}" } else { "Hide {row}" })) - .toggle(ToggleCell::lock(LOCK, row.locked).name(if row.locked { "Unlock {row}" } else { "Lock {row}" })); + .toggle(ToggleCell::eye(EYE, !row.hidden).name(if row.hidden { "Show {row}" } else { "Hide {row}" }).always_visible()) + .toggle(ToggleCell::lock(LOCK, row.locked).name(if row.locked { "Unlock {row}" } else { "Lock {row}" }).always_visible()); if row.group { line = line.group(icx.row.open); } diff --git a/crates/ui-egui/src/panels/selpane/ui_tests.rs b/crates/ui-egui/src/panels/selpane/ui_tests.rs index 2296f5238..5e77278e8 100644 --- a/crates/ui-egui/src/panels/selpane/ui_tests.rs +++ b/crates/ui-egui/src/panels/selpane/ui_tests.rs @@ -79,6 +79,32 @@ fn lists_front_most_first_with_groups_expanded() { assert!(h.query_by_label("Hide A").is_some() && h.query_by_label("Lock A").is_some()); } +/// Whether something is painted inside the node named `label`. +fn paints_inside(h: &Harness<'_, SlideApp>, label: &str) -> bool { + fn any(shape: &egui::Shape, within: egui::Rect) -> bool { + match shape { + egui::Shape::Vec(shapes) => shapes.iter().any(|shape| any(shape, within)), + shape => { + let bounds = shape.visual_bounding_rect(); + bounds.is_positive() && within.expand(0.5).contains_rect(bounds) + } + } + } + let cell = h.get_by_label(label).rect(); + h.output().shapes.iter().any(|shape| any(&shape.shape, cell)) +} + +#[test] +fn an_unlocked_row_and_a_hidden_group_show_their_toggles_without_the_pointer() { + let (mut h, ids) = harness(); + h.state_mut().run("shape.visible", json!({"id": ids[5], "visible": false})).unwrap(); + h.run_steps(3); + h.hover_at(Pos2::new(1.0, 1.0)); + h.run_steps(2); + assert!(paints_inside(&h, "Lock A"), "an unlocked shape shows the padlock it is locked with"); + assert!(paints_inside(&h, "Show G"), "a hidden group shows its struck eye"); +} + #[test] fn click_ctrl_click_and_shift_click_select() { let (mut h, _) = harness();