diff --git a/crates/ui-egui/src/app/scheme.rs b/crates/ui-egui/src/app/scheme.rs index cb627a1f7..b4156fb70 100644 --- a/crates/ui-egui/src/app/scheme.rs +++ b/crates/ui-egui/src/app/scheme.rs @@ -1,7 +1,6 @@ impl crate::SlideApp { /// Returns the current presentation colour scheme. - #[allow(dead_code)] // P3(panels-w8): pn.A6 pub(crate) fn color_scheme(&self) -> deckcraft_color::ColorScheme { - todo!("pn.A6") + self.session.active().and_then(|d| d.doc.masters.first().map(|m| m.scheme())).unwrap_or_else(|| deckcraft_model::Theme::default().colors) } } diff --git a/crates/ui-egui/src/panels/color_row.rs b/crates/ui-egui/src/panels/color_row.rs index defa0616f..f97ee4622 100644 --- a/crates/ui-egui/src/panels/color_row.rs +++ b/crates/ui-egui/src/panels/color_row.rs @@ -1,32 +1,82 @@ -/// Shows a colour row and reports the selected colour. -#[allow(dead_code)] // P3(panels-w8): pn.A7 +//! Colour rows share the same conversion and delayed eyedropper route as ribbon menus. + +use craft::color_ui::ui::{ColorPick, ThemeColorMenu}; +use craft::ui::buttons::Button; +use craft::ui::contract::{Bind, BodyCx, FieldLayout, Props as _, Show as _, ShowContainer as _}; +use craft::ui::controls::disclosure::DisclosureGlyph; +use craft::ui::form::Field; +use craft::ui::popover::Popover; +use craft::ui::runtime::env::{Env, Label, Word}; +use deckcraft_model::ColorRef; +use egui::Ui; + +use crate::SlideApp; +use crate::eyedropper::{self, Target}; + +craft::ui::words! { + /// The accessible name of a colour opener beside its property label. + struct ColorRowWords { + /// `{label}` identifies the property whose colour will be edited. + named: template "formatShape.namedColor" = "{label} color"; + } +} + +fn color_ref(pick: ColorPick) -> Option> { + match pick { + ColorPick::Scheme { slot, mods, .. } => Some(Some(mods.into_iter().fold(ColorRef::scheme(slot), ColorRef::with))), + ColorPick::Rgb(color) => Some(Some(ColorRef::rgb(color))), + ColorPick::None => Some(None), + _ => None, + } +} + +/// Shows the shared menu body and arms its keyed eyedropper request. +pub(crate) fn color_menu(app: &mut SlideApp, ui: &mut Ui, cx: &mut BodyCx<'_>, key: &str, none: Option<&str>) -> Option> { + let scheme = app.color_scheme(); + let mut menu = ThemeColorMenu::new(Word::plain("Color"), &scheme).key(key); + if let Some(label) = none { + menu = menu.none(label.to_owned()); + } + let output = menu.show(ui, cx); + if output.eyedropper.is_some() { + eyedropper::arm(app, Target::Menu(key.to_owned())); + } + output.pick.and_then(color_ref) +} + +/// Takes one answer for this opener after its popover has closed. +pub(crate) fn take_color_answer(app: &mut SlideApp, key: &str) -> Option> { + ThemeColorMenu::take_answer(&mut app.host_answers, key).and_then(color_ref) +} + +/// Shows a labelled colour opener for a semantic target/property key scoped to the active document. pub(crate) fn color_row( - app: &mut crate::SlideApp, - ui: &mut egui::Ui, + app: &mut SlideApp, + ui: &mut Ui, + key: &str, label: &str, none: Option<&str>, - on_pick: impl FnOnce(&mut crate::SlideApp, Option), + on_pick: impl FnOnce(&mut SlideApp, Option), ) { - let _ = (app, ui, label, none, on_pick); - todo!("pn.A7") -} - -/// Reports the colour menu or eyedropper answer. -#[allow(dead_code)] // P3(panels-w8): pn.A15 -pub(crate) fn color_menu( - app: &mut crate::SlideApp, - ui: &mut egui::Ui, - cx: &mut craft::ui::contract::BodyCx<'_>, - key: &str, - none: Option<&str>, -) -> Option> { - let _ = (app, ui, cx, key, none); - todo!("pn.A15") -} - -/// Reports the colour menu or eyedropper answer. -#[allow(dead_code)] // P3(panels-w8): pn.A15 -pub(crate) fn take_color_answer(app: &mut crate::SlideApp, key: &str) -> Option> { - let _ = (app, key); - todo!("pn.A15") + let Some(uid) = app.session.active().map(|st| st.uid) else { return }; + let key = format!("fmt-color:{uid}:{key}"); + let name = if label == "Color" { + 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) + }); + field.settle(|_, output| { + let mut popup = Popover::new(Word::plain("Color"), Bind::kept().reset(false)) + .id_salt(&key) + .opened_by(&output.response) + .show(ui, |ui, cx| color_menu(app, ui, cx, &key, none)); + let picked = popup.settle(|_, pick| pick.take()).flatten(); + let answer = take_color_answer(app, &key); + if let Some(pick) = picked.or(answer) { + on_pick(app, pick); + } + }); } diff --git a/crates/ui-egui/src/panels/format_shape.rs b/crates/ui-egui/src/panels/format_shape.rs index f324c314b..06f6b3e31 100644 --- a/crates/ui-egui/src/panels/format_shape.rs +++ b/crates/ui-egui/src/panels/format_shape.rs @@ -1,7 +1,36 @@ -use super::effect_presets; +//! Shape formatting uses command-backed fields seeded from the selected document object. + mod effects; mod size; -use super::{Fill, Icon, ShapeKind, SlideApp, Tokens, Ui, color_button, cref_param, json, run, scheme, theme, vec2, widgets}; + +use std::collections::HashMap; + +use craft::ui::buttons::Button; +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::layout_components::{Row, Stack}; +use craft::ui::pickers::Select; +use craft::ui::primitives::IconSpec; +use craft::ui::runtime::env::{UnitKind, Word}; +use craft::ui::sections::Section; +use craft::ui::text::{NumberField, StepArrows}; +use deckcraft_model::{Fill, Shape, ShapeKind}; +use egui::Ui; +use serde_json::json; + +use super::color_row::color_row; +use super::{SlideApp, cref_param, run}; +use crate::icons::Icon; + +/// The formatting pane scale bases and reference options. +#[derive(Default)] +pub struct FormatPaneState { + scale_base: HashMap<(u64, u32), (f64, f64)>, + lock_aspect: bool, + centre_origin: bool, +} /// Percent transparency (0 = opaque) of a solid fill, the same number `shape.fill`'s /// `transparency` parameter writes as an alpha transform. Anything else (no fill, a @@ -26,115 +55,20 @@ pub(super) fn fill_transparency_to_apply(shown_percent: f32, seed_percent: f32) Some(f64::from(shown) / 100.0) } -fn format_tabs(app: &mut SlideApp, ui: &mut Ui, sh: &deckcraft_model::Shape) { - // Tabs as icons. - ui.horizontal(|ui| { - for (tab, icon, tip) in [ - ("fill", Icon::ShapeFill, "Fill & Line"), - ("effects", Icon::ShapeEffects, "Effects"), - ("size", Icon::SlideSize, "Size & Properties"), - ("text", Icon::TextBox, "Text Options"), - ] { - let on = app.ui.format_tab == tab; - if widgets::icon_toggle(ui, icon, tip, true, on).clicked() { - app.ui.format_tab = tab.into(); - } - } - if matches!(sh.kind, ShapeKind::Picture { .. }) - && widgets::icon_toggle(ui, Icon::Picture, "Picture", true, app.ui.format_tab == "picture").clicked() - { - app.ui.format_tab = "picture".into(); - } - }); -} - -fn effects_tab(app: &mut SlideApp, ui: &mut Ui, sh: &deckcraft_model::Shape) { - ui.label(egui::RichText::new("Shadow").font(theme::bold(13.0))); - let fx = sh.effects.clone().unwrap_or_default(); - if let Some(v) = effect_presets::shadow_row(ui, effect_presets::shadow_preset_id(&fx)) { - run(app, "shape.effects", json!({"shadow": v})); - } - let shadow = fx.inner_shadow.as_ref().or(fx.outer_shadow.as_ref()); - if let Some(sw) = shadow { - color_button(app, ui, "Color", None, |c| ("shape.effects".into(), json!({"shadowProps": {"color": c.as_ref().map(cref_param)}}))); - fx_slider( - app, - ui, - ("shadow", sh.id.0, "t"), - "Transparency", - (1.0 - sw.color.alpha()) * 100.0, - 0.0..=100.0, - "%", - "shadowProps", - "transparency", - 0.01, - ); - fx_slider(app, ui, ("shadow", sh.id.0, "s"), "Size", sw.sx * 100.0, 1.0..=200.0, "%", "shadowProps", "size", 0.01); - fx_slider(app, ui, ("shadow", sh.id.0, "b"), "Blur", sw.blur, 0.0..=100.0, " pt", "shadowProps", "blur", 1.0); - fx_slider(app, ui, ("shadow", sh.id.0, "a"), "Angle", sw.dir, 0.0..=359.0, "°", "shadowProps", "dir", 1.0); - fx_slider(app, ui, ("shadow", sh.id.0, "d"), "Distance", sw.dist, 0.0..=200.0, " pt", "shadowProps", "dist", 1.0); - } - ui.add_space(6.0); - ui.label(egui::RichText::new("Reflection").font(theme::bold(13.0))); - ui.horizontal_wrapped(|ui| { - for (l, v) in [("None", "none"), ("Tight", "tight"), ("Half", "half"), ("Full", "full")] { - if ui.button(l).clicked() { - run(app, "shape.effects", json!({"reflection": v})); - } - } - }); - if let Some(r) = &fx.reflection { - fx_slider( - app, - ui, - ("refl", sh.id.0, "t"), - "Transparency", - (1.0 - r.start_alpha) * 100.0, - 0.0..=100.0, - "%", - "reflectionProps", - "transparency", - 0.01, - ); - fx_slider(app, ui, ("refl", sh.id.0, "s"), "Size", r.end_pos * 100.0, 0.0..=100.0, "%", "reflectionProps", "size", 0.01); - fx_slider(app, ui, ("refl", sh.id.0, "d"), "Distance", r.dist, 0.0..=100.0, " pt", "reflectionProps", "dist", 1.0); - fx_slider(app, ui, ("refl", sh.id.0, "b"), "Blur", r.blur, 0.0..=100.0, " pt", "reflectionProps", "blur", 1.0); - } - ui.add_space(6.0); - ui.label(egui::RichText::new("Glow").font(theme::bold(13.0))); - let radius = fx.glow.as_ref().map_or(0.0, |g| g.radius); - if let Some(r) = effect_presets::glow_row(ui, radius) { - run(app, "shape.effects", json!({"glowProps": {"radius": r}})); - } - fx_slider(app, ui, ("glow", sh.id.0, "r"), "Size", radius, 0.0..=150.0, " pt", "glowProps", "radius", 1.0); - if let Some(g) = &fx.glow { - color_button(app, ui, "Color", None, |c| ("shape.effects".into(), json!({"glowProps": {"color": c.as_ref().map(cref_param)}}))); - fx_slider( - app, - ui, - ("glow", sh.id.0, "t"), - "Transparency", - (1.0 - g.color.alpha()) * 100.0, - 0.0..=100.0, - "%", - "glowProps", - "transparency", - 0.01, - ); - } - ui.label(egui::RichText::new("Soft Edges").font(theme::bold(13.0))); - let mut s = sh.effects.as_ref().and_then(|e| e.soft_edge).unwrap_or(0.0); - if let Some(r) = effect_presets::soft_edge_row(ui, s) { - run(app, "shape.effects", json!({"softEdges": r})); - } - if ui.add(egui::Slider::new(&mut s, 0.0..=50.0).text("size (pt)")).drag_stopped() { - run(app, "shape.effects", json!({"softEdges": s})); - } - let raw3d = sh.effects.as_ref().and_then(|e| e.raw3d.clone()); - three_d_options(app, ui, sh.id.0, raw3d.as_deref()); - if ui.button("Reset Effects").clicked() { - run(app, "shape.effects", json!({"reset": true})); +fn format_tabs(app: &mut SlideApp, ui: &mut Ui, sh: &Shape) { + let mut entries: Vec<_> = [ + ("fill", Icon::ShapeFill, "Fill & Line"), + ("effects", Icon::ShapeEffects, "Effects"), + ("size", Icon::SlideSize, "Size & Properties"), + ("text", Icon::TextBox, "Text Options"), + ] + .into_iter() + .map(|(tab, icon, label)| Entry::new(tab.to_owned(), Word::plain(label)).icon(IconSpec::svg(icon.id()))) + .collect(); + if matches!(sh.kind, ShapeKind::Picture { .. }) { + entries.push(Entry::new("picture".to_owned(), Word::plain("Picture")).icon(IconSpec::svg(Icon::Picture.id()))); } + Segmented::new(Word::plain("Format options"), Bind::bound(&mut app.ui.format_tab), &entries).show(ui); } /// A group keeps no slide background fill of its own. It shows Slide background fill when every @@ -164,360 +98,213 @@ fn selection_takes_background_fill(app: &SlideApp) -> bool { ok } -/// Format Shape ▸ Size & Properties: size, rotation, scale, position and alt text. -fn size_tab(app: &mut SlideApp, ui: &mut Ui, sh: &deckcraft_model::Shape, x: deckcraft_model::Xfrm, single: bool, uid: u64) { - let lock_id = ui.scope_id().with("fmt-lock-aspect"); - let mut lock: bool = ui.data_mut(|d| d.get_temp(lock_id).unwrap_or(false)); - let locked = lock; - // Scale is measured from the size the shape had when this tab first showed it, like the - // Size and Position dialog; the origin choice is kept for the session. - let base_id = ui.scope_id().with(("fmt-scale-base", uid, sh.id.0)); - let (base_w, base_h): (f64, f64) = ui.data_mut(|d| d.get_temp(base_id).unwrap_or((x.w, x.h))); - ui.data_mut(|d| d.insert_temp(base_id, (base_w, base_h))); - let origin_id = ui.scope_id().with("fmt-origin-center"); - let mut center: bool = single && ui.data_mut(|d| d.get_temp(origin_id).unwrap_or(false)); - let len = app.session.prefs.units; - let mut fields = |ui: &mut Ui, label: &str, id: &str, v: f64, key: &str, cmd: &str, angle: bool| { - let (unit, suffix) = if angle { (1.0, "°") } else { (len.points_per_unit(), len.suffix()) }; - ui.horizontal(|ui| { - ui.add_sized(vec2(90.0, 20.0), egui::Label::new(label)); - if let Some(nv) = widgets::spinner(ui, id, label, v / unit, 0.1, suffix, 70.0) { - let mut p = json!({key: nv * unit}); - if cmd == "shape.resize" && locked { - p["lockAspect"] = json!(true); - } - run(app, cmd, p); - } - }); - }; - ui.label(egui::RichText::new("Size").font(theme::bold(13.0))); - fields(ui, "Height", "fh", x.h, "h", "shape.resize", false); - fields(ui, "Width", "fw", x.w, "w", "shape.resize", false); - fields(ui, "Rotation", "fr", x.rot, "deg", "shape.rotate", true); - for (label, id, cur, base, key) in [("Scale Height", "fsh", x.h, base_h, "h"), ("Scale Width", "fsw", x.w, base_w, "w")] { - ui.add_enabled_ui(single, |ui| { - ui.horizontal(|ui| { - ui.add_sized(vec2(90.0, 20.0), egui::Label::new(label)); - let pct = if base > 0.0 { cur / base * 100.0 } else { 100.0 }; - if let Some(nv) = widgets::spinner(ui, id, label, pct, 1.0, "%", 70.0) - && nv > 0.0 - { - let mut p = json!({key: base * nv / 100.0}); - if locked { - p["lockAspect"] = json!(true); - } - run(app, "shape.sizePosition", p); - } - }) - }); - } - if ui.checkbox(&mut lock, "Lock aspect ratio").changed() { - ui.data_mut(|d| d.insert_temp(lock_id, lock)); - } - ui.add_space(6.0); - ui.label(egui::RichText::new("Position").font(theme::bold(13.0))); - ui.add_enabled_ui(single, |ui| { - ui.horizontal(|ui| { - ui.add_sized(vec2(90.0, 20.0), egui::Label::new("From")); - let combo = - // P3(panels-w8): earlier framework ComboBox removal (no contract id) - egui::ComboBox::from_id_salt("fmt-origin").selected_text(if center { "Center" } else { "Top Left Corner" }).show_ui(ui, |ui| { - ui.selectable_value(&mut center, false, "Top Left Corner"); - ui.selectable_value(&mut center, true, "Center"); - }); - combo.response.widget_info(|| egui::WidgetInfo::labeled(egui::Role::ComboBox, true, "From")); - }) +fn slider(ui: &mut Ui, label: &'static str, value: f64, range: std::ops::RangeInclusive, unit: UnitKind) -> 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) }); - if single { - ui.data_mut(|d| d.insert_temp(origin_id, center)); - } - let (dx, dy) = if center { (x.w / 2.0, x.h / 2.0) } else { (0.0, 0.0) }; - // The spinner shows `value / unit`; `shape.move` takes the top-left corner, so a centre - // reading is shifted by half the size in both directions. - let (px, py) = (x.x + dx, x.y + dy); - let mut pos = |ui: &mut Ui, label: &str, id: &str, v: f64, off: f64, key: &str| { - ui.horizontal(|ui| { - ui.add_sized(vec2(90.0, 20.0), egui::Label::new(label)); - if let Some(nv) = widgets::spinner(ui, id, label, v / len.points_per_unit(), 0.1, len.suffix(), 70.0) { - run(app, "shape.move", json!({key: nv * len.points_per_unit() - off})); - } - }); - }; - pos(ui, "Horizontal", "fx", px, dx, "x"); - pos(ui, "Vertical", "fy", py, dy, "y"); - ui.add_space(6.0); - ui.label(egui::RichText::new("Alt Text").font(theme::bold(13.0))); - let id = ui.scope_id().with(("alt", uid, sh.id.0)); - let stored: Option<(String, String)> = ui.data_mut(|d| d.get_temp(id)); - let mut alt = widgets::text_draft(stored, &sh.descr); - let r = ui.add(egui::TextEdit::multiline(&mut alt).hint_text("Alt text").desired_rows(3).desired_width(f32::INFINITY)); - if r.lost_focus() && alt != sh.descr { - run(app, "shape.altText", json!({"text": alt})); - } - ui.data_mut(|d| d.insert_temp(id, (sh.descr.clone(), alt))); + field.settle(|_, output| output.events.committed().copied()).flatten().filter(|shown| *shown != value) } -/// Render the shape-format pane with fill/line, effects, size/properties, text, and picture tabs. +fn number(ui: &mut Ui, label: &'static str, value: f64, step: f64, unit: UnitKind) -> Option { + let mut field = Field::new(Word::plain(label)).layout(FieldLayout::Beside).id_salt(label).show(ui, |ui, _| { + NumberField::new(Word::plain(label), Bind::given(Some(value))) + .step(step) + .unit_kind(unit) + .step_arrows(StepArrows::Trailing) + .show(ui) + }); + field.settle(|_, output| output.events.committed().copied().flatten()).flatten().filter(|shown| *shown != value) +} + +fn select(ui: &mut Ui, label: &'static str, current: &str, items: &[(&'static str, &str)]) -> Option { + let entries: Vec<_> = items.iter().map(|(name, value)| Entry::new((*value).to_owned(), Word::plain(name))).collect(); + let mut field = Field::new(Word::plain(label)).layout(FieldLayout::Beside).id_salt(label).show(ui, |ui, _| { + Select::new(Word::plain(label), Bind::given(current.to_owned()), &entries).show(ui) + }); + field.settle(|_, output| output.events.committed().cloned()).flatten().filter(|picked| picked != current) +} + +fn choice_buttons(ui: &mut Ui, label: &'static str, current: &str, items: &[(&'static str, &str)]) -> Option { + let mut field = Field::new(Word::plain(label)).layout(FieldLayout::Beside).id_salt(label).show(ui, |ui, _| { + let mut row = Row::new().wrap(true).show(ui, |ui, _| { + let mut picked = None; + for (name, value) in items { + if Button::new(Word::plain(name)).id_salt(value).show(ui).clicked() { + picked = Some((*value).to_owned()); + } + } + picked + }); + row.settle(|_, picked| picked.take()).flatten() + }); + field.settle(|_, picked| picked.take()).flatten().filter(|picked| picked != current) +} + +fn radios(ui: &mut Ui, label: &'static str, current: &str, items: &[(&'static str, &str)]) -> Option { + let mut group = RadioGroup::new(Word::plain(label), Bind::given(current.to_owned())).id_salt(label).show(ui, |ui, _| { + Stack::new().show(ui, |ui, _| { + for (name, value) in items { + Radio::new((*value).to_owned()).label(Word::plain(name)).show(ui); + } + }); + }); + group.settle(|_, _| ()).and_then(|()| group.output.events.committed().cloned()).filter(|picked| picked != current) +} + +fn checkbox(ui: &mut Ui, label: &'static str, value: bool) -> Option { + Checkbox::new(Bind::given(value)).label(Word::plain(label)).show(ui).events.committed().copied() +} + +/// Renders the shape-format pane's fill, effects, size, text and picture controls. pub(super) fn format_shape(app: &mut SlideApp, ui: &mut Ui) { - let t = Tokens::get(ui.ctx()); let Some(st) = app.session.active() else { return }; let Some(sh) = st.selected_shapes().first().map(|s| (*s).clone()) else { - ui.label(egui::RichText::new("Select a shape to format it.").color(t.text_dim)); + Text::new(Word::plain("Select a shape to format it.")).shade(Shade::Muted).show(ui); return; }; - let x = deckcraft_engine::cmd::xfrm_of(&st.doc, &st.selection, &sh); - // Scale and a centre origin work from the shown shape's size, so they need a single shape. - let single = st.selected_shapes().len() == 1; let uid = st.uid; - format_tabs(app, ui, &sh); - ui.separator(); - match app.ui.format_tab.as_str() { - "effects" => effects_tab(app, ui, &sh), - "size" => size_tab(app, ui, &sh, x, single, uid), - "text" => { - ui.label(egui::RichText::new("Text Fill").font(theme::bold(13.0))); - color_button(app, ui, "Color", None, |c| match c { - Some(c) => ("format.color".into(), json!({"color": cref_param(&c)})), - None => ("format.color".into(), json!({"color": "tx1"})), - }); - text_transparency_slider(app, ui, &sh); - ui.add_space(6.0); - ui.label(egui::RichText::new("Text Box").font(theme::bold(13.0))); - ui.horizontal(|ui| { - ui.label("Vertical alignment"); - for (l, a) in [("Top", "top"), ("Middle", "middle"), ("Bottom", "bottom")] { - if ui.small_button(l).clicked() { - run(app, "format.anchor", json!({"anchor": a})); - } - } - }); - ui.horizontal_wrapped(|ui| { - for (l, m) in [("Do not Autofit", "none"), ("Shrink text on overflow", "shrink"), ("Resize shape to fit text", "resize")] { - if ui.small_button(l).clicked() { - run(app, "format.autofit", json!({"mode": m})); - } - } - }); - let wrap = sh.text.as_ref().and_then(|t| t.body.wrap).unwrap_or(true); - let mut w = wrap; - if ui.checkbox(&mut w, "Wrap text in shape").changed() { - run(app, "format.wrap", json!({"on": w})); - } - ui.label("Margins (pt)"); - let b = sh.text.as_ref().map(|t| t.body.clone()).unwrap_or_default(); - for (l, k, v) in [ - ("Left", "left", b.inset_l.unwrap_or(7.2)), - ("Right", "right", b.inset_r.unwrap_or(7.2)), - ("Top", "top", b.inset_t.unwrap_or(3.6)), - ("Bottom", "bottom", b.inset_b.unwrap_or(3.6)), - ] { - ui.horizontal(|ui| { - ui.add_sized(vec2(60.0, 20.0), egui::Label::new(l)); - if let Some(nv) = widgets::spinner(ui, &format!("m{k}"), l, v, 1.0, " pt", 60.0) { - run(app, "format.margins", json!({k: nv.max(0.0)})); - } - }); - } - ui.horizontal(|ui| { - ui.label("Columns"); - for n in 1..=3 { - if ui.small_button(n.to_string()).clicked() { - run(app, "format.columns", json!({"count": n, "spacing": 18})); - } - } - if ui.small_button("Columns…").clicked() { - run(app, "format.columns", json!({})); - } - }); - } - "picture" => { - let adj = if let ShapeKind::Picture { fill } = &sh.kind { fill.adjust.clone() } else { Default::default() }; - let mut b = adj.brightness as f32; - if ui.add(egui::Slider::new(&mut b, -1.0..=1.0).text("Brightness")).drag_stopped() { - run(app, "picture.adjust", json!({"brightness": b})); - } - let mut c = adj.contrast as f32; - if ui.add(egui::Slider::new(&mut c, -1.0..=1.0).text("Contrast")).drag_stopped() { - run(app, "picture.adjust", json!({"contrast": c})); - } - let mut s = adj.saturation.unwrap_or(1.0) as f32; - if ui.add(egui::Slider::new(&mut s, 0.0..=4.0).text("Saturation")).drag_stopped() { - run(app, "picture.adjust", json!({"saturation": s})); - } - let alpha = if let ShapeKind::Picture { fill } = &sh.kind { fill.alpha.unwrap_or(1.0) } else { 1.0 }; - let mut tr = (1.0 - alpha) as f32; - if ui.add(egui::Slider::new(&mut tr, 0.0..=1.0).text("Transparency")).drag_stopped() { - run(app, "picture.adjust", json!({"transparency": tr})); - } - if ui.button("Reset Picture").clicked() { - run(app, "picture.reset", json!({})); + Stack::new().id_salt(("format-shape", uid, sh.id.0)).show(ui, |ui, _| { + format_tabs(app, ui, &sh); + Divider::horizontal().show(ui); + match app.ui.format_tab.as_str() { + "effects" => effects::tab(app, ui, &sh), + "size" => size::tab(app, ui, &sh, uid), + "text" => text_tab(app, ui, &sh), + "picture" => picture_tab(app, ui, &sh), + _ => { + Section::fixed(Word::plain("Fill")).id_salt("shape-fill").show(ui, |ui, _| fill_options(app, ui, &sh)); + Section::fixed(Word::plain("Line")).id_salt("shape-line").show(ui, |ui, _| line_options(app, ui, &sh)); } } - _ => { - // Fill & Line. - ui.label(egui::RichText::new("Fill").font(theme::bold(13.0))); - let members_background = members_have_background_fill(&sh); - let kind = match &sh.fill { - _ if members_background => "background", - None => "auto", - Some(Fill::None) => "none", - Some(Fill::Solid { .. }) => "solid", - Some(Fill::Gradient(_)) => "gradient", - Some(Fill::Picture(_)) => "picture", - Some(Fill::Pattern(_)) => "pattern", - Some(Fill::Background) => "background", - _ => "auto", - }; - let background_ok = selection_takes_background_fill(app); - for (l, k) in [ - ("No fill", "none"), - ("Solid fill", "solid"), - ("Gradient fill", "gradient"), - ("Picture or texture fill", "picture"), - ("Pattern fill", "pattern"), - ("Slide background fill", "background"), - ("Automatic", "auto"), - ] { - if k == "background" && !background_ok { - continue; - } - if ui.radio(kind == k, l).clicked() { - match k { - "none" => run(app, "shape.fill", json!({"none": true})), - "solid" => run(app, "shape.fill", json!({"color": "accent1"})), - "gradient" => run( - app, - "shape.fill", - json!({"gradient": {"stops": [[0, "accent1"], [1, {"scheme": "accent1", "lumMod": 50000}]], "angle": 90}}), - ), - "pattern" => run(app, "shape.fill", json!({"pattern": {"preset": "pct25", "fg": "accent1", "bg": "bg1"}})), - "picture" => pick_fill_picture(app), - "background" => run(app, "shape.fill", json!({"background": true})), - _ => run(app, "shape.fill", json!({"reset": true})), - } - } - } - // The Color button sets a solid fill, so it shows only for a solid or automatic fill. A - // gradient takes its colors from its stops, and a pattern takes them from its Foreground - // and Background menus below. - if matches!(kind, "solid" | "auto") { - color_button(app, ui, "Color", Some("No Fill"), |c| match c { - Some(c) => ("shape.fill".into(), json!({"color": cref_param(&c)})), - None => ("shape.fill".into(), json!({"none": true})), - }); - } - // `shape.fill {transparency}` changes a solid fill (an automatic one through its - // effective color) and a picture fill; a gradient has a transparency per stop. - let transparency = !members_background && matches!(sh.fill, None | Some(Fill::Solid { .. } | Fill::Picture(_))); - ui.horizontal(|ui| { - if !transparency { - return; - } - let label = ui.label("Transparency"); - // Seed from this shape. A shared temp defaulted to 0, so a shape that was - // already 40% transparent showed as opaque, and leaving the slider wrote 0. - let seed = match &sh.fill { - Some(Fill::Picture(pf)) => ((1.0 - pf.alpha.unwrap_or(1.0)) * 100.0) as f32, - fill => solid_fill_transparency_percent(fill.as_ref()), - }; - let id = ui.scope_id().with(("ftr", sh.id.0)); - let mut v: f32 = ui.data_mut(|d| d.get_temp(id).unwrap_or(seed)); - let r = ui.add(egui::Slider::new(&mut v, 0.0..=100.0).suffix("%")).labelled_by(label.id); - if r.drag_stopped() || r.lost_focus() { - if let Some(t) = fill_transparency_to_apply(v, seed) { - let _ = app.run("shape.fill", json!({"transparency": t})); - } - ui.data_mut(|d| d.remove::(id)); - } else if r.dragged() || r.changed() { - ui.data_mut(|d| d.insert_temp(id, v)); - } - }); - // A group that keeps a fill for its pictures shows no editor for that fill while its - // shapes have the slide background fill. - let shown_fill = sh.fill.as_ref().filter(|_| !members_background); - if let Some(Fill::Picture(pf)) = shown_fill { - picture_fill_options(app, ui, sh.id.0, pf); - } - if let Some(Fill::Gradient(g)) = shown_fill { - let sc = scheme(app); - // P3(panels-w8): pn.A10 - let _ = ≻ - // P3(panels-w8): pn.A10 - if let Some(ng) = crate::fillui::gradient_editor(app, ui, "shape-grad", g) { - run(app, "shape.fill", json!({"gradient": crate::fillui::gradient_json(&ng)})); - } - let mut rot = g.rotate_with_shape; - if ui.checkbox(&mut rot, "Rotate with shape").changed() { - let ng = deckcraft_model::style::Gradient { rotate_with_shape: rot, ..g.clone() }; - run(app, "shape.fill", json!({"gradient": crate::fillui::gradient_json(&ng)})); - } - } - if let Some(Fill::Pattern(pt)) = shown_fill - // P3(panels-w8): pn.A10 - && let Some(np) = crate::fillui::pattern_editor(app, ui, pt) - { - run(app, "shape.fill", json!({"pattern": crate::fillui::pattern_json(&np)})); - } - ui.add_space(8.0); - ui.label(egui::RichText::new("Line").font(theme::bold(13.0))); - let none = matches!(sh.line.as_ref().and_then(|l| l.fill.as_ref()), Some(Fill::None)); - if ui.radio(none, "No line").clicked() { - run(app, "shape.line", json!({"none": true})); - } - if ui.radio(!none && sh.line.is_some(), "Solid line").clicked() { - run(app, "shape.line", json!({"color": "tx1", "width": 1})); - } - if ui.radio(sh.line.is_none(), "Automatic").clicked() { - run(app, "shape.line", json!({"reset": true})); - } - color_button(app, ui, "Color", Some("No Outline"), |c| match c { - Some(c) => ("shape.line".into(), json!({"color": cref_param(&c)})), - None => ("shape.line".into(), json!({"none": true})), - }); - ui.horizontal(|ui| { - ui.label("Width"); - let w = sh.line.as_ref().and_then(|l| l.width).unwrap_or(0.75); - if let Some(v) = widgets::spinner(ui, "lw", "Width", w, 0.25, " pt", 60.0) { - run(app, "shape.line", json!({"width": v.max(0.0)})); - } - }); - ui.horizontal_wrapped(|ui| { - ui.label("Dash"); - for (l, d) in [("—", "solid"), ("···", "sysDot"), ("- -", "dash"), ("-·-", "dashDot"), ("— —", "lgDash")] { - if ui.small_button(l).clicked() { - run(app, "shape.line", json!({"dash": d})); - } - } - }); - line_details(app, ui, &sh); - } - } -} - -/// A labelled drop-down on the Format Shape pane: picks one of `items` (label, value) and runs -/// `shape.line` with `{key: value}`. -fn line_choice(app: &mut SlideApp, ui: &mut Ui, label: &str, key: &str, current: &str, items: &[(&str, &str)]) { - ui.horizontal(|ui| { - let field = ui.add_sized(vec2(90.0, 20.0), egui::Label::new(label)); - let shown = items.iter().find(|(_, v)| *v == current).map_or(current, |(l, _)| *l); - // P3(panels-w8): earlier framework ComboBox removal (no contract id) - let combo = egui::ComboBox::from_id_salt(("fmt-line", key)).selected_text(shown).width(120.0).show_ui(ui, |ui| { - for (l, v) in items { - if ui.selectable_label(*v == current, *l).clicked() { - run(app, "shape.line", json!({key: v})); - } - } - }); - let _ = combo.response.labelled_by(field.id); }); } -/// The rest of PowerPoint's Line page: compound type, cap and join types, and the begin and end -/// arrows with their sizes. -fn line_details(app: &mut SlideApp, ui: &mut Ui, sh: &deckcraft_model::Shape) { +fn fill_options(app: &mut SlideApp, ui: &mut Ui, sh: &Shape) { + let members_background = members_have_background_fill(sh); + let kind = match &sh.fill { + _ if members_background => "background", + None => "auto", + Some(Fill::None) => "none", + Some(Fill::Solid { .. }) => "solid", + Some(Fill::Gradient(_)) => "gradient", + Some(Fill::Picture(_)) => "picture", + Some(Fill::Pattern(_)) => "pattern", + Some(Fill::Background) => "background", + _ => "auto", + }; + let items: Vec<_> = [ + ("No fill", "none"), + ("Solid fill", "solid"), + ("Gradient fill", "gradient"), + ("Picture or texture fill", "picture"), + ("Pattern fill", "pattern"), + ("Slide background fill", "background"), + ("Automatic", "auto"), + ] + .into_iter() + .filter(|(_, key)| *key != "background" || selection_takes_background_fill(app)) + .collect(); + if let Some(picked) = radios(ui, "Fill type", kind, &items) { + match picked.as_str() { + "none" => run(app, "shape.fill", json!({"none": true})), + "solid" => run(app, "shape.fill", json!({"color": "accent1"})), + "gradient" => run( + app, + "shape.fill", + json!({"gradient": {"stops": [[0, "accent1"], [1, {"scheme": "accent1", "lumMod": 50000}]], "angle": 90}}), + ), + "pattern" => run(app, "shape.fill", json!({"pattern": {"preset": "pct25", "fg": "accent1", "bg": "bg1"}})), + "picture" => pick_fill_picture(app), + "background" => run(app, "shape.fill", json!({"background": true})), + _ => run(app, "shape.fill", json!({"reset": true})), + } + } + // A solid colour pick cannot edit a gradient stop or a pattern's two colours. + if matches!(kind, "solid" | "auto") { + color_row(app, ui, &format!("shape:{}:fill", sh.id.0), "Color", Some("No Fill"), |app, pick| { + let params = pick.map_or_else(|| json!({"none": true}), |color| json!({"color": cref_param(&color)})); + run(app, "shape.fill", params); + }); + } + if !members_background && matches!(sh.fill, None | Some(Fill::Solid { .. } | Fill::Picture(_))) { + let seed = match &sh.fill { + 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) + && let Some(value) = fill_transparency_to_apply(shown as f32, seed) + { + run(app, "shape.fill", json!({"transparency": value})); + } + } + // The group's retained fill belongs to its pictures, while its shape members use the background. + match sh.fill.as_ref().filter(|_| !members_background) { + Some(Fill::Picture(picture)) => picture_fill_options(app, ui, picture), + Some(Fill::Gradient(gradient)) => { + // PLAN: assumed gradient_editor(app: &mut SlideApp, ui: &mut Ui, key: &str, label: &str, g: &Gradient) -> Option (panels-w10) + if let Some(changed) = crate::fillui::gradient_editor(app, ui, &format!("shape:{}:fill", sh.id.0), "Gradient", gradient) { + run(app, "shape.fill", json!({"gradient": crate::fillui::gradient_json(&changed)})); + } + if let Some(rotate) = checkbox(ui, "Rotate with shape", gradient.rotate_with_shape) { + let changed = deckcraft_model::style::Gradient { rotate_with_shape: rotate, ..gradient.clone() }; + run(app, "shape.fill", json!({"gradient": crate::fillui::gradient_json(&changed)})); + } + } + Some(Fill::Pattern(pattern)) => { + // PLAN: assumed pattern_editor(app: &mut SlideApp, ui: &mut Ui, key: &str, p: &PatternFill) -> Option (panels-w10) + if let Some(changed) = crate::fillui::pattern_editor(app, ui, &format!("shape:{}:fill", sh.id.0), pattern) { + run(app, "shape.fill", json!({"pattern": crate::fillui::pattern_json(&changed)})); + } + } + _ => {} + } +} + +fn line_options(app: &mut SlideApp, ui: &mut Ui, sh: &Shape) { + let none = matches!(sh.line.as_ref().and_then(|line| line.fill.as_ref()), Some(Fill::None)); + let kind = if none { "none" } else if sh.line.is_some() { "solid" } else { "auto" }; + if let Some(picked) = radios(ui, "Line type", kind, &[("No line", "none"), ("Solid line", "solid"), ("Automatic", "auto")]) { + let params = match picked.as_str() { + "none" => json!({"none": true}), + "solid" => json!({"color": "tx1", "width": 1}), + _ => json!({"reset": true}), + }; + run(app, "shape.line", params); + } + color_row(app, ui, &format!("shape:{}:line", sh.id.0), "Color", Some("No Outline"), |app, pick| { + let params = pick.map_or_else(|| json!({"none": true}), |color| json!({"color": cref_param(&color)})); + run(app, "shape.line", params); + }); + let width = sh.line.as_ref().and_then(|line| line.width).unwrap_or(0.75); + if let Some(value) = number(ui, "Width", width, 0.25, UnitKind::Points) { + run(app, "shape.line", json!({"width": value.max(0.0)})); + } + let dash = match sh.line.as_ref().and_then(|line| line.dash.as_ref()) { + Some(deckcraft_model::style::Dash::Preset { name }) => name.as_str(), + Some(deckcraft_model::style::Dash::Custom { .. }) => "custom", + None => "solid", + }; + if let Some(value) = + choice_buttons(ui, "Dash", dash, &[("—", "solid"), ("···", "sysDot"), ("- -", "dash"), ("-·-", "dashDot"), ("— —", "lgDash")]) + { + run(app, "shape.line", json!({"dash": value})); + } + line_details(app, ui, sh); +} + +fn line_choice(app: &mut SlideApp, ui: &mut Ui, label: &'static str, key: &str, current: &str, items: &[(&'static str, &str)]) { + if let Some(value) = select(ui, label, current, items) { + run(app, "shape.line", json!({key: value})); + } +} + +fn line_details(app: &mut SlideApp, ui: &mut Ui, sh: &Shape) { use deckcraft_model::style::{Compound, LineCap, LineJoin}; - let l = sh.line.clone().unwrap_or_default(); - let compound = match l.compound.unwrap_or_default() { + let line = sh.line.clone().unwrap_or_default(); + let compound = match line.compound.unwrap_or_default() { Compound::Single => "single", Compound::Double => "double", Compound::ThickThin => "thickThin", @@ -532,13 +319,13 @@ fn line_details(app: &mut SlideApp, ui: &mut Ui, sh: &deckcraft_model::Shape) { compound, &[("Single", "single"), ("Double", "double"), ("Thick Thin", "thickThin"), ("Thin Thick", "thinThick"), ("Triple", "triple")], ); - let cap = match l.cap.unwrap_or_default() { + let cap = match line.cap.unwrap_or_default() { LineCap::Flat => "flat", LineCap::Round => "round", LineCap::Square => "square", }; line_choice(app, ui, "Cap type", "cap", cap, &[("Flat", "flat"), ("Round", "round"), ("Square", "square")]); - let join = match l.join.unwrap_or_default() { + let join = match line.join.unwrap_or_default() { LineJoin::Round => "round", LineJoin::Bevel => "bevel", LineJoin::Miter => "miter", @@ -546,226 +333,166 @@ fn line_details(app: &mut SlideApp, ui: &mut Ui, sh: &deckcraft_model::Shape) { line_choice(app, ui, "Join type", "join", join, &[("Round", "round"), ("Bevel", "bevel"), ("Miter", "miter")]); let arrows = [("None", "none"), ("Arrow", "triangle"), ("Open Arrow", "arrow"), ("Stealth", "stealth"), ("Diamond", "diamond"), ("Oval", "oval")]; let sizes = [("Small", "sm"), ("Medium", "med"), ("Large", "lg")]; - for (label, key, size_label, size_key, end) in - [("Begin arrow", "head", "Begin size", "headSize", &l.head), ("End arrow", "tail", "End size", "tailSize", &l.tail)] - { - line_choice(app, ui, label, key, end.as_ref().map_or("none", |e| e.kind.as_str()), &arrows); - if let Some(e) = end { - line_choice(app, ui, size_label, size_key, &e.w, &sizes); + for (label, key, size_label, size_key, end) in [ + ("Begin arrow", "head", "Begin size", "headSize", &line.head), + ("End arrow", "tail", "End size", "tailSize", &line.tail), + ] { + line_choice(app, ui, label, key, end.as_ref().map_or("none", |end| end.kind.as_str()), &arrows); + if let Some(end) = end { + line_choice(app, ui, size_label, size_key, &end.w, &sizes); } } } -/// A slider for one property of a shape effect: shows `value` (in display units), and when the -/// drag ends runs `shape.effects` with `{key: {prop: shown × scale}}`. -#[allow(clippy::too_many_arguments)] -fn fx_slider( - app: &mut SlideApp, - ui: &mut Ui, - id: (&str, u32, &str), - label: &str, - value: f64, - range: std::ops::RangeInclusive, - suffix: &str, - key: &str, - prop: &str, - scale: f64, -) { - ui.horizontal(|ui| { - let label = ui.add_sized(vec2(90.0, 20.0), egui::Label::new(label)); - // Hold the value while dragging; otherwise follow the shape. - let sid = ui.scope_id().with(id); - let mut v: f64 = ui.data_mut(|d| d.get_temp(sid)).unwrap_or(value); - let r = ui.add(egui::Slider::new(&mut v, range).suffix(suffix).max_decimals(0)).labelled_by(label.id); - if r.dragged() || r.has_focus() { - ui.data_mut(|d| d.insert_temp(sid, v)); - } else { - ui.data_mut(|d| d.remove::(sid)); - } - // `changed()` also fires when the slider only rounds the value it shows (55.000000000000007 to 55, - // or 0.5 to 1 on focus, which re-added a reflection the pane had just cleared): only a move to - // another shown value is an edit. Accessibility and keyboard edits are such moves too. - let shown_changed = r.changed() && v.round() != value.round(); - // A slider that only had focus when another control took it (the Reflection "None" button) - // must not commit its stale value: only an edit the user made is committed on losing focus. - let edited_id = sid.with("edited"); - if shown_changed { - ui.data_mut(|d| d.insert_temp(edited_id, true)); - } - let edited = ui.data_mut(|d| d.get_temp::(edited_id)).unwrap_or(false); - if r.drag_stopped() || (r.lost_focus() && edited) || (shown_changed && !r.dragged()) { - ui.data_mut(|d| { - d.remove::(sid); - d.remove::(edited_id); - }); - run(app, "shape.effects", json!({key: {prop: v * scale}})); - } - }); -} - /// Asks for a picture file and makes it the selected shapes' fill. fn pick_fill_picture(app: &mut SlideApp) { - if let Some(pick) = app.services.pick_open.as_mut() - && let Some(path) = pick("picture") - && let Some(Ok(bytes)) = app.services.read.as_ref().map(|r| r(&path)) - { - run(app, "shape.fill", json!({"picture": deckcraft_engine::cmd::base64_encode(&bytes)})); - } + app.pick_and_run("picture", "shape.fill", json!({})); } -/// A number field for one picture-fill option; runs `shape.fill` with `{pictureProps: {key: v × scale}}` -/// when it changes. -fn pic_drag(app: &mut SlideApp, ui: &mut Ui, label: &str, value: f64, suffix: &str, key: &str, scale: f64) { - ui.horizontal(|ui| { - let field = ui.add_sized(vec2(90.0, 20.0), egui::Label::new(label)); - let mut v = value; - let r = ui.add(egui::DragValue::new(&mut v).suffix(suffix).max_decimals(1)).labelled_by(field.id); - if r.drag_stopped() || r.lost_focus() || (r.changed() && !r.dragged()) { - run(app, "shape.fill", json!({"pictureProps": {key: v * scale}})); - } - }); -} - -/// Format Shape ▸ Fill ▸ Picture or texture fill: source, tiling, offsets, transparency. -fn picture_fill_options(app: &mut SlideApp, ui: &mut Ui, id: u32, pf: &deckcraft_model::style::PictureFill) { +fn picture_fill_options(app: &mut SlideApp, ui: &mut Ui, picture: &deckcraft_model::style::PictureFill) { use deckcraft_model::style::PictureMode; - ui.horizontal(|ui| { - ui.label("Picture source"); - if ui.button("Insert…").clicked() { - pick_fill_picture(app); - } - }); - let mut tile = matches!(pf.mode, PictureMode::Tile { .. }); - if ui.checkbox(&mut tile, "Tile picture as texture").changed() { + let mut source = Field::new(Word::plain("Picture source")) + .layout(FieldLayout::Beside) + .show(ui, |ui, _| Button::new(Word::plain("Insert…")).show(ui)); + if source.settle(|_, output| output.clicked()).unwrap_or(false) { + pick_fill_picture(app); + } + if let Some(tile) = checkbox(ui, "Tile picture as texture", matches!(picture.mode, PictureMode::Tile { .. })) { run(app, "shape.fill", json!({"pictureProps": {"tile": tile}})); } - match &pf.mode { + match &picture.mode { PictureMode::Tile { tx, ty, sx, sy, flip, align } => { - pic_drag(app, ui, "Offset X", *tx, " pt", "offsetX", 1.0); - pic_drag(app, ui, "Offset Y", *ty, " pt", "offsetY", 1.0); - pic_drag(app, ui, "Scale X", sx * 100.0, "%", "scaleX", 0.01); - pic_drag(app, ui, "Scale Y", sy * 100.0, "%", "scaleY", 0.01); + for (label, value, unit, key, scale) in [ + ("Offset X", *tx, UnitKind::Points, "offsetX", 1.0), + ("Offset Y", *ty, UnitKind::Points, "offsetY", 1.0), + ("Scale X", sx * 100.0, UnitKind::Percent, "scaleX", 0.01), + ("Scale Y", sy * 100.0, UnitKind::Percent, "scaleY", 0.01), + ] { + if let Some(value) = number(ui, label, value, 0.1, unit) { + run(app, "shape.fill", json!({"pictureProps": {key: value * scale}})); + } + } let aligns = [ - ("tl", "Top left"), - ("t", "Top"), - ("tr", "Top right"), - ("l", "Left"), - ("ctr", "Center"), - ("r", "Right"), - ("bl", "Bottom left"), - ("b", "Bottom"), - ("br", "Bottom right"), + ("Top left", "tl"), + ("Top", "t"), + ("Top right", "tr"), + ("Left", "l"), + ("Center", "ctr"), + ("Right", "r"), + ("Bottom left", "bl"), + ("Bottom", "b"), + ("Bottom right", "br"), ]; - let mirrors = [("none", "None"), ("x", "Horizontal"), ("y", "Vertical"), ("xy", "Both")]; - for (label, key, opts, cur) in [("Alignment", "align", &aligns[..], align), ("Mirror type", "mirror", &mirrors[..], flip)] { - ui.horizontal(|ui| { - let field = ui.add_sized(vec2(90.0, 20.0), egui::Label::new(label)); - let shown = opts.iter().find(|(k, _)| k == cur).map_or(opts[0].1, |(_, l)| *l); - // P3(panels-w8): earlier framework ComboBox removal (no contract id) - let combo = egui::ComboBox::from_id_salt(("picfill", id, key)).selected_text(shown).show_ui(ui, |ui| { - for (k, l) in opts { - if ui.selectable_label(*k == cur.as_str(), *l).clicked() { - run(app, "shape.fill", json!({"pictureProps": {key: k}})); - } - } - }); - let _ = combo.response.labelled_by(field.id); - }); + let mirrors = [("None", "none"), ("Horizontal", "x"), ("Vertical", "y"), ("Both", "xy")]; + for (label, key, options, current) in [("Alignment", "align", &aligns[..], align), ("Mirror type", "mirror", &mirrors[..], flip)] { + if let Some(value) = select(ui, label, current, options) { + run(app, "shape.fill", json!({"pictureProps": {key: value}})); + } } } PictureMode::Stretch { fill_rect } => { - for (i, label) in ["Offset left", "Offset top", "Offset right", "Offset bottom"].into_iter().enumerate() { - ui.horizontal(|ui| { - let field = ui.add_sized(vec2(90.0, 20.0), egui::Label::new(label)); - let mut v = fill_rect[i] * 100.0; - let r = ui.add(egui::DragValue::new(&mut v).suffix("%").max_decimals(0)).labelled_by(field.id); - if r.drag_stopped() || r.lost_focus() || (r.changed() && !r.dragged()) { - let mut rect = *fill_rect; - rect[i] = v / 100.0; - run(app, "shape.fill", json!({"pictureProps": {"stretch": rect}})); - } - }); + // [left, top, right, bottom]: editing top (index 1) preserves indices 0, 2 and 3. + for (index, label) in ["Offset left", "Offset top", "Offset right", "Offset bottom"].into_iter().enumerate() { + if let Some(value) = number(ui, label, fill_rect[index] * 100.0, 1.0, UnitKind::Percent) { + let mut rect = *fill_rect; + rect[index] = value / 100.0; + run(app, "shape.fill", json!({"pictureProps": {"stretch": rect}})); + } } } } - let mut rot = !pf.upright; - if ui.checkbox(&mut rot, "Rotate with shape").changed() { - run(app, "shape.fill", json!({"pictureProps": {"rotateWithShape": rot}})); + if let Some(rotate) = checkbox(ui, "Rotate with shape", !picture.upright) { + run(app, "shape.fill", json!({"pictureProps": {"rotateWithShape": rotate}})); } } -/// "perspectiveHeroicLeftFacing" → "Perspective heroic left facing". -fn preset_label(name: &str) -> String { - let mut out = String::new(); - for (i, c) in name.chars().enumerate() { - if i == 0 { - out.extend(c.to_uppercase()); - } else if c.is_uppercase() { - out.push(' '); - out.extend(c.to_lowercase()); - } else { - out.push(c); +fn text_tab(app: &mut SlideApp, ui: &mut Ui, sh: &Shape) { + use deckcraft_model::text::{Anchor, AutoFit}; + Section::fixed(Word::plain("Text Fill")).id_salt("text-fill").show(ui, |ui, _| { + color_row(app, ui, &format!("shape:{}:text-fill", sh.id.0), "Color", None, |app, pick| { + if let Some(color) = pick { + run(app, "format.color", json!({"color": cref_param(&color)})); + } + }); + text_transparency_slider(app, ui, sh); + }); + let body = sh.text.as_ref().map(|text| text.body.clone()).unwrap_or_default(); + Section::fixed(Word::plain("Text Box")).id_salt("text-box").show(ui, |ui, _| { + let anchor = match body.anchor.unwrap_or(Anchor::Top) { + Anchor::Top => "top", + Anchor::Middle => "middle", + Anchor::Bottom => "bottom", + Anchor::Justified => "justified", + Anchor::Distributed => "distributed", + }; + if let Some(anchor) = choice_buttons(ui, "Vertical alignment", anchor, &[("Top", "top"), ("Middle", "middle"), ("Bottom", "bottom")]) { + run(app, "format.anchor", json!({"anchor": anchor})); } - } - out -} - -/// A drop-down of `options`; picking one runs `shape.effects` with `{threeD: {key: option}}`. -fn three_d_combo(app: &mut SlideApp, ui: &mut Ui, id: u32, label: &str, key: &str, cur: &str, options: &[&str]) { - ui.horizontal(|ui| { - let field = ui.add_sized(vec2(90.0, 20.0), egui::Label::new(label)); - // P3(panels-w8): earlier framework ComboBox removal (no contract id) - let combo = egui::ComboBox::from_id_salt(("3d", id, key)).selected_text(preset_label(cur)).width(170.0).show_ui(ui, |ui| { - for o in options { - if ui.selectable_label(*o == cur, preset_label(o)).clicked() { - run(app, "shape.effects", json!({"threeD": {key: o}})); + let autofit = match body.autofit { + Some(AutoFit::Shrink { .. }) => "shrink", + Some(AutoFit::Shape) => "resize", + _ => "none", + }; + if let Some(mode) = choice_buttons( + ui, + "Autofit", + autofit, + &[("Do not Autofit", "none"), ("Shrink text on overflow", "shrink"), ("Resize shape to fit text", "resize")], + ) { + run(app, "format.autofit", json!({"mode": mode})); + } + if let Some(wrap) = checkbox(ui, "Wrap text in shape", body.wrap.unwrap_or(true)) { + run(app, "format.wrap", json!({"on": wrap})); + } + Section::fixed(Word::plain("Margins (pt)")).show(ui, |ui, _| { + for (label, key, value) in [ + ("Left", "left", body.inset_l.unwrap_or(7.2)), + ("Right", "right", body.inset_r.unwrap_or(7.2)), + ("Top", "top", body.inset_t.unwrap_or(3.6)), + ("Bottom", "bottom", body.inset_b.unwrap_or(3.6)), + ] { + if let Some(value) = number(ui, label, value, 1.0, UnitKind::Points) { + run(app, "format.margins", json!({key: value.max(0.0)})); } } }); - let _ = combo.response.labelled_by(field.id); - }); -} - -/// A number field running `shape.effects` with `{threeD: {key: value}}` when it changes. -fn three_d_drag(app: &mut SlideApp, ui: &mut Ui, label: &str, value: f64, suffix: &str, key: &str) { - ui.horizontal(|ui| { - let field = ui.add_sized(vec2(90.0, 20.0), egui::Label::new(label)); - let mut v = value; - let r = ui.add(egui::DragValue::new(&mut v).suffix(suffix).max_decimals(1)).labelled_by(field.id); - if r.drag_stopped() || r.lost_focus() || (r.changed() && !r.dragged()) { - run(app, "shape.effects", json!({"threeD": {key: v}})); + let mut columns = Field::new(Word::plain("Columns")).layout(FieldLayout::Beside).show(ui, |ui, _| { + let mut row = Row::new().show(ui, |ui, _| { + let mut picked = None; + for count in 1..=3 { + if Button::new(count.to_string()).show(ui).clicked() { + picked = Some(count); + } + } + (picked, Button::new(Word::plain("Columns…")).show(ui).clicked()) + }); + row.settle(|_, output| *output) + }); + if let Some((count, dialog)) = columns.settle(|_, output| *output).flatten() { + if let Some(count) = count { + run(app, "format.columns", json!({"count": count, "spacing": 18})); + } + if dialog { + app.open_dialog("columns", json!({})); + } } }); } -/// Format Shape ▸ Effects ▸ 3-D Format and 3-D Rotation. -fn three_d_options(app: &mut SlideApp, ui: &mut Ui, id: u32, raw: Option<&str>) { - use deckcraft_engine::cmd::three_d::{BEVELS, CAMERAS, LIGHTS, MATERIALS, Shape3d}; - let s3 = raw.map(Shape3d::parse).unwrap_or_default(); - let with_none: Vec<&str> = std::iter::once("none").chain(BEVELS.iter().copied()).collect(); - ui.add_space(6.0); - ui.label(egui::RichText::new("3-D Format").font(theme::bold(13.0))); - for (label, key, b) in [("Top bevel", "bevelTop", &s3.top), ("Bottom bevel", "bevelBottom", &s3.bottom)] { - three_d_combo(app, ui, id, label, key, b.as_ref().map_or("none", |b| b.preset.as_str()), &with_none); - if let Some(b) = b { - three_d_drag(app, ui, " Width", b.w, " pt", &format!("{key}W")); - three_d_drag(app, ui, " Height", b.h, " pt", &format!("{key}H")); +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})); } } - three_d_drag(app, ui, "Depth", s3.depth, " pt", "depth"); - three_d_drag(app, ui, "Contour", s3.contour, " pt", "contour"); - three_d_combo(app, ui, id, "Material", "material", &s3.material, MATERIALS); - three_d_combo(app, ui, id, "Lighting", "lighting", &s3.light, LIGHTS); - ui.add_space(6.0); - ui.label(egui::RichText::new("3-D Rotation").font(theme::bold(13.0))); - three_d_combo(app, ui, id, "Presets", "camera", &s3.camera, CAMERAS); - let (rx, ry, rz) = s3.rot.unwrap_or((0.0, 0.0, 0.0)); - three_d_drag(app, ui, "X Rotation", rx, "°", "rotX"); - three_d_drag(app, ui, "Y Rotation", ry, "°", "rotY"); - three_d_drag(app, ui, "Z Rotation", rz, "°", "rotZ"); - three_d_drag(app, ui, "Distance from ground", s3.z, " pt", "z"); - if ui.add_enabled(raw.is_some(), egui::Button::new("Reset 3-D")).clicked() { - run(app, "shape.effects", json!({"threeD": {"reset": true}})); + if Button::new(Word::plain("Reset Picture")).show(ui).clicked() { + run(app, "picture.reset", json!({})); } } @@ -779,28 +506,9 @@ pub(crate) fn text_transparency_of(sh: &deckcraft_model::Shape) -> f64 { } } -/// Text Fill › Transparency, as in PowerPoint's Format Shape › Text Options (#32). +/// 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) { - ui.horizontal(|ui| { - let label = ui.label("Transparency"); - let id = ui.scope_id().with(("text-transparency", sh.id)); - let stored = (text_transparency_of(sh) * 100.0) as f32; - let mut v: f32 = ui.data_mut(|d| d.get_temp(id).unwrap_or(stored)); - let r = ui.add(egui::Slider::new(&mut v, 0.0..=100.0).suffix("%")).labelled_by(label.id); - if r.drag_stopped() || r.lost_focus() || (r.changed() && !r.dragged()) { - let _ = app.run("format.textTransparency", json!({"value": v as f64 / 100.0})); - ui.data_mut(|d| d.remove::(id)); - } else if r.dragged() { - ui.data_mut(|d| d.insert_temp(id, v)); - } - }); -} - -/// The formatting pane scale bases and reference options. -#[allow(dead_code)] // P3(panels-w8): pn.A8 -#[derive(Default)] -pub struct FormatPaneState { - scale_base: std::collections::HashMap<(u64, u32), (f64, f64)>, - lock_aspect: bool, - centre_origin: bool, + if let Some(value) = slider(ui, "Transparency", text_transparency_of(sh) * 100.0, 0.0..=100.0, UnitKind::Percent) { + run(app, "format.textTransparency", json!({"value": value / 100.0})); + } } diff --git a/crates/ui-egui/src/panels/format_shape_tests.rs b/crates/ui-egui/src/panels/format_shape_tests.rs new file mode 100644 index 000000000..2882303fe --- /dev/null +++ b/crates/ui-egui/src/panels/format_shape_tests.rs @@ -0,0 +1,272 @@ +//! Regression coverage for fill editing and selection-dependent Format Shape rows. + +use deckcraft_color::{ColorTransform, SchemeSlot}; +use deckcraft_engine::Session; +use deckcraft_model::{ColorRef, Fill, ShapeId, ShapeKind}; +use egui::accesskit::{Role, Toggled}; +use egui_kittest::Harness; +use egui_kittest::kittest::{NodeT, Queryable}; +use serde_json::{Value, json}; + +use super::format_shape::{fill_transparency_to_apply, solid_fill_transparency_percent}; +use crate::{Services, SlideApp}; + +type TestResult = Result>; + +fn pane(session: Session) -> Harness<'static, SlideApp> { + let mut h = crate::test_harness::harness_with( + session, + Services::default(), + Harness::builder().with_size(egui::vec2(1800.0, 1500.0)), + |_| {}, + ); + h.state_mut().ui.pane = Some("format".into()); + h.state_mut().ui.format_tab = "fill".into(); + h.run_steps(3); + h +} + +fn rectangle(session: &mut Session) -> TestResult { + let result = session.execute("shape.insert", &json!({"preset": "rect", "rect": [40.0, 40.0, 120.0, 80.0]}))?; + Ok(u32::try_from(result["id"].as_u64().ok_or("shape.insert did not return an id")?)?) +} + +fn fill_pane(params: Option) -> TestResult> { + let mut session = Session::with_new(); + session.execute("slide.new", &json!({"layout": "blank"}))?; + let id = rectangle(&mut session)?; + session.execute("edit.select", &json!({"ids": [id]}))?; + if let Some(params) = params { + session.execute("shape.fill", ¶ms)?; + } + Ok(pane(session)) +} + +fn picture_data() -> String { + // Generated pixels keep the fixture independent of external assets. + let png = deckcraft_render::Image { width: 2, height: 2, pixels: [255, 0, 0, 255].repeat(4) }.to_png(); + deckcraft_engine::cmd::base64_encode(&png) +} + +fn selected_fill(h: &Harness<'_, SlideApp>) -> TestResult> { + let state = h.state().session.active().ok_or("no active document")?; + Ok(state.selected_shapes().first().ok_or("no selected shape")?.fill.clone()) +} + +fn shape_fill(h: &Harness<'_, SlideApp>, id: u32) -> TestResult> { + Ok(h.state().session.active().ok_or("no active document")?.shape(ShapeId(id)).ok_or("shape is absent")?.fill.clone()) +} + +fn undo_len(h: &Harness<'_, SlideApp>) -> TestResult { + Ok(h.state().session.active().ok_or("no active document")?.history.undo.len()) +} + +fn transparency(h: &Harness<'_, SlideApp>) -> TestResult { + Ok(h.get_by_role_and_label(Role::Slider, "Transparency").accesskit_node().numeric_value().ok_or("slider has no numeric value")?) +} + +fn color_rows(h: &Harness<'_, SlideApp>) -> usize { + h.query_all_by_role_and_label(Role::Button, "Color").count() +} + +#[test] +fn solid_fill_transparency_reads_the_alpha_shape_fill_writes() -> TestResult { + let plain = Fill::solid(ColorRef::scheme(SchemeSlot::Accent1)); + let opaque = solid_fill_transparency_percent(Some(&plain)); + for fill in [None, Some(&Fill::None), Some(&Fill::Group)] { + assert_eq!(solid_fill_transparency_percent(fill), opaque); + } + // Alpha order is document order: .2 then .8 leaves .8 opacity, hence .2 transparency. + let earlier = ColorTransform::Alpha(20_000); + let later = ColorTransform::Alpha(80_000); + let layered = Fill::solid(ColorRef::scheme(SchemeSlot::Accent1).with(earlier).with(later)); + let last_color = ColorRef::scheme(SchemeSlot::Accent1).with(later); + let last = Fill::solid(last_color.clone()); + let shown = solid_fill_transparency_percent(Some(&layered)); + assert_eq!(shown, solid_fill_transparency_percent(Some(&last))); + assert!(shown > opaque); + let clear = Fill::solid(ColorRef::scheme(SchemeSlot::Accent1).with(ColorTransform::Alpha(0))); + assert!(solid_fill_transparency_percent(Some(&clear)) > shown); + assert!(fill_transparency_to_apply(shown, shown).is_none()); + assert!(fill_transparency_to_apply(shown + 0.005, shown).is_none()); + assert!(fill_transparency_to_apply(f32::NAN, shown).is_none()); + let fraction = fill_transparency_to_apply(shown, opaque).ok_or("a changed transparency must be an edit")?; + assert!((fraction - (1.0 - last_color.alpha())).abs() < 0.000_001); + assert!(fill_transparency_to_apply(opaque, shown).ok_or("returning to opaque must be an edit")? < fraction); + Ok(()) +} + +#[test] +fn fill_transparency_slider_follows_the_selection() -> TestResult { + let mut session = Session::with_new(); + session.execute("slide.new", &json!({"layout": "blank"}))?; + let a = rectangle(&mut session)?; + let b = rectangle(&mut session)?; + session.execute("shape.fill", &json!({"id": a, "color": "accent1", "transparency": 0.0}))?; + session.execute("shape.fill", &json!({"id": b, "color": "accent2", "transparency": 0.4}))?; + session.execute("edit.select", &json!({"ids": [a]}))?; + let mut h = pane(session); + let first = transparency(&h)?; + let before = shape_fill(&h, b)?; + h.state_mut().session.execute("edit.select", &json!({"ids": [b]}))?; + h.run_steps(3); + let second = transparency(&h)?; + assert!(second > first); + assert_eq!(selected_fill(&h)?, before, "opening and changing the selection must not edit its fill"); + assert!((second - f64::from(solid_fill_transparency_percent(before.as_ref()))).abs() < 0.01); + + let undo = undo_len(&h)?; + h.get_by_role_and_label(Role::Slider, "Transparency").click(); + h.run_steps(2); + let after = transparency(&h)?; + assert!(after > second); + assert_ne!(selected_fill(&h)?, before); + assert!((after - f64::from(solid_fill_transparency_percent(selected_fill(&h)?.as_ref()))).abs() < 0.01); + assert_eq!(undo_len(&h)?, undo + 1); + h.state_mut().session.execute("edit.select", &json!({"ids": [a]}))?; + h.run_steps(2); + assert_eq!(transparency(&h)?, first, "the other shape retains its own value"); + Ok(()) +} + +#[test] +fn fill_color_and_transparency_show_only_where_they_change_the_fill() -> TestResult { + let baseline = fill_pane(Some(json!({"none": true})))?; + let line_colors = color_rows(&baseline); + let opaque = f64::from(solid_fill_transparency_percent(Some(&Fill::solid(ColorRef::scheme(SchemeSlot::Accent1))))); + for (kind, params, color, slider, gradient, pattern) in [ + ("automatic", None, true, true, false, false), + // shape_solid_fill_keeps_its_transparency_without_a_pattern_gallery shares this table + // so its slider and absent pattern controls are checked against the other fill kinds. + ("solid", Some(json!({"color": "accent2", "transparency": 0.4})), true, true, false, false), + ("none", Some(json!({"none": true})), false, false, false, false), + ( + "gradient", + Some(json!({"gradient": {"stops": [[0, "accent1"], [1, "accent2"]], "angle": 90}})), + false, + false, + true, + false, + ), + ("picture", Some(json!({"picture": picture_data(), "transparency": 0.4})), false, true, false, false), + ("pattern", Some(json!({"pattern": {"preset": "pct25", "fg": "accent1", "bg": "bg1"}})), false, false, false, true), + ] { + let mut h = fill_pane(params)?; + if gradient { + h.get_by_role_and_label(Role::GraphicsObject, "Color stop 1 of 2").click(); + h.run_steps(2); + } + assert_eq!(color_rows(&h) > line_colors, color, "{kind}: fill colour row"); + assert_eq!(h.query_by_role_and_label(Role::Slider, "Transparency").is_some(), slider, "{kind}: fill transparency"); + assert_eq!(h.query_by_role_and_label(Role::SpinButton, "Opacity").is_some(), gradient, "{kind}: stop opacity"); + assert_eq!(h.query_by_role_and_label(Role::Group, "Gradient").is_some(), gradient, "{kind}: gradient editor"); + assert_eq!(h.query_by_role_and_label(Role::Button, "Foreground color").is_some(), pattern, "{kind}: pattern colour row"); + let tile_name = crate::fillui::pattern_label("zigZag"); + assert_eq!(h.query_by_role_and_label(Role::ListItem, tile_name).is_some(), pattern, "{kind}: pattern preset tile"); + if let Some(Fill::Picture(picture)) = selected_fill(&h)? { + assert!((transparency(&h)? / 100.0 - (1.0 - picture.alpha.unwrap_or(1.0))).abs() < 0.000_001); + assert!(h.query_by_role_and_label(Role::CheckBox, "Tile picture as texture").is_some()); + } + if let Some(Fill::Solid { .. }) = selected_fill(&h)? { + assert!((transparency(&h)? - f64::from(solid_fill_transparency_percent(selected_fill(&h)?.as_ref()))).abs() < 0.01); + } + if kind == "solid" { + assert!(transparency(&h)? > opaque, "{kind}: a translucent solid retains its transparency without a pattern gallery"); + } + } + Ok(()) +} + +#[test] +fn slide_background_fill_is_a_fill_option() -> TestResult { + for kind in ["rectangle", "picture", "group", "retained gradient"] { + let mut session = Session::with_new(); + session.execute("slide.new", &json!({"layout": "blank"}))?; + let mut picture_id = None; + let mut shape_id = None; + if kind == "rectangle" { + shape_id = Some(rectangle(&mut session)?); + } else { + let result = session.execute("insert.picture", &json!({"data": picture_data(), "name": "generated.png"}))?; + let picture = u32::try_from(result["id"].as_u64().ok_or("insert.picture did not return an id")?)?; + picture_id = Some(picture); + if kind != "picture" { + let shape = rectangle(&mut session)?; + shape_id = Some(shape); + session.execute("edit.select", &json!({"ids": [picture, shape]}))?; + session.execute("arrange.group", &json!({}))?; + let fill = if kind == "retained gradient" { + json!({"gradient": {"stops": [[0, "accent1"], [1, "accent2"]]}}) + } else { + json!({"color": "accent1"}) + }; + session.execute("shape.fill", &fill)?; + if kind == "retained gradient" { + session.edit(|doc, _| { + for slide in &mut doc.slides { + if let Some(picture) = std::sync::Arc::make_mut(slide).shape_mut(ShapeId(picture)) { + picture.fill = Some(Fill::Group); + } + } + Ok(()) + })?; + } + } + } + let mut h = pane(session); + let allowed = kind != "picture"; + let options = h.get_by_role_and_label(Role::RadioGroup, "Fill type"); + assert!(options.query_by_role_and_label(Role::RadioButton, "Pattern fill").is_some(), "{kind}: fill options are shown"); + assert_eq!(options.query_by_role_and_label(Role::RadioButton, "Slide background fill").is_some(), allowed, "{kind}"); + let initial = match kind { + "group" => "Solid fill", + "retained gradient" => "Gradient fill", + _ => "Automatic", + }; + assert_eq!(options.get_by_role_and_label(Role::RadioButton, initial).accesskit_node().toggled(), Some(Toggled::True), "{kind}"); + if !allowed { + continue; + } + let radio = h.get_by_role_and_label(Role::RadioButton, "Slide background fill"); + assert_ne!(radio.accesskit_node().toggled(), Some(Toggled::True)); + let group_fill = selected_fill(&h)?; + let picture_fill = picture_id.map(|id| shape_fill(&h, id)).transpose()?; + let undo = undo_len(&h)?; + radio.click(); + h.run_steps(3); + assert_eq!(undo_len(&h)?, undo + 1, "{kind}: one undo step"); + let selected = h.get_by_role_and_label(Role::RadioButton, "Slide background fill"); + assert_eq!(selected.accesskit_node().toggled(), Some(Toggled::True), "{kind}: the displayed radio follows members"); + assert!(h.query_by_role_and_label(Role::Slider, "Transparency").is_none()); + assert!(h.query_by_role_and_label(Role::Group, "Gradient").is_none(), "a retained group fill must not expose an editor"); + assert_eq!(shape_fill(&h, shape_id.ok_or("selection has no shape")?)?, Some(Fill::Background)); + if let Some(id) = picture_id { + assert_eq!(shape_fill(&h, id)?, picture_fill.ok_or("picture fill was not captured")?, "pictures retain their fill"); + let state = h.state().session.active().ok_or("no active document")?; + assert!(state.selected_shapes().first().is_some_and(|shape| matches!(shape.kind, ShapeKind::Group { .. }))); + if kind == "retained gradient" { + assert_eq!(selected_fill(&h)?, group_fill, "the picture still inherits the retained gradient"); + } else { + assert!(selected_fill(&h)?.is_none()); + } + } + h.state_mut().session.execute("edit.undo", &json!({}))?; + h.run_steps(2); + assert_ne!(h.get_by_role_and_label(Role::RadioButton, "Slide background fill").accesskit_node().toggled(), Some(Toggled::True)); + } + let h = fill_pane(Some(json!({"background": true})))?; + assert_eq!(h.get_by_role_and_label(Role::RadioButton, "Slide background fill").accesskit_node().toggled(), Some(Toggled::True)); + let chosen_automatic = h + .query_all_by_role_and_label(Role::RadioButton, "Automatic") + .filter(|node| node.accesskit_node().toggled() == Some(Toggled::True)) + .count(); + let line_only = fill_pane(Some(json!({"none": true})))?; + let line_automatic = line_only + .query_all_by_role_and_label(Role::RadioButton, "Automatic") + .filter(|node| node.accesskit_node().toggled() == Some(Toggled::True)) + .count(); + assert_eq!(chosen_automatic, line_automatic, "only the line's Automatic is selected"); + assert_eq!(color_rows(&h), color_rows(&line_only)); + Ok(()) +} +