mirror of
https://github.com/storytold/deckcraft.git
synced 2026-12-01 10:13:09 -06:00
ribbon-w8: net change of 2 commits
- ribbon-w8: written from its sheet - ribbon-w8: repair 1
This commit is contained in:
@@ -1,62 +0,0 @@
|
||||
//! Add Animation (#1370): the menu scrolls, so the last effect can be reached and added.
|
||||
|
||||
use deckcraft_engine::Session;
|
||||
use egui_kittest::Harness;
|
||||
use egui_kittest::kittest::Queryable;
|
||||
use serde_json::json;
|
||||
|
||||
use crate::{Services, SlideApp};
|
||||
|
||||
fn harness(size: egui::Vec2) -> Harness<'static, SlideApp> {
|
||||
let mut session = Session::with_new();
|
||||
let id = session.execute("shape.insert", &json!({"preset": "rect", "rect": [80.0, 80.0, 200.0, 120.0]})).unwrap()["id"].as_u64().unwrap();
|
||||
session.execute("edit.select", &json!({"ids": [id]})).unwrap();
|
||||
// P3(ribbon-w8): sh.A2
|
||||
let mut app = SlideApp::new_base(session, Services::default());
|
||||
app.ui.tab = "Animations".into();
|
||||
let mut h = Harness::builder().with_size(size).with_step_dt(1.0 / 60.0).build_ui_state(
|
||||
|ui, app: &mut SlideApp| {
|
||||
app.logic(ui.ctx());
|
||||
app.ui(ui);
|
||||
},
|
||||
app,
|
||||
);
|
||||
h.run_steps(3);
|
||||
h
|
||||
}
|
||||
|
||||
fn open_add_animation(h: &mut Harness<'static, SlideApp>, window: egui::Vec2) {
|
||||
// The Animations ribbon is wider than a short window. The edge chevron is what a person uses
|
||||
// to reach Add Animation; scroll-into-view on the button does not move that bar.
|
||||
for _ in 0..12 {
|
||||
let rect = h.get_by_label("Add Animation").rect();
|
||||
if rect.min.x >= 8.0 && rect.max.x <= window.x - 8.0 {
|
||||
break;
|
||||
}
|
||||
let Some(cue) = h.query_by_label("Scroll ribbon right") else { break };
|
||||
cue.click();
|
||||
h.run_steps(2);
|
||||
}
|
||||
h.get_by_label("Add Animation").click();
|
||||
h.run_steps(3);
|
||||
}
|
||||
|
||||
fn added_effect(h: &Harness<'_, SlideApp>) -> Option<(String, deckcraft_model::anim::AnimClass)> {
|
||||
h.state().session.active().and_then(|d| d.current_slide()).and_then(|s| s.animations.first()).map(|a| (a.effect.clone(), a.class))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_last_effect_is_reachable_by_scrolling() {
|
||||
let size = egui::vec2(800.0, 700.0);
|
||||
let mut h = harness(size);
|
||||
open_add_animation(&mut h, size);
|
||||
let before = h.get_by_label("Neutron — Motion").rect();
|
||||
assert!(before.min.y > 700.0, "the last effect starts below the window: {before:?}");
|
||||
h.get_by_label("Neutron — Motion").scroll_to_me();
|
||||
h.run_steps(4);
|
||||
let row = h.get_by_label("Neutron — Motion").rect();
|
||||
assert!(row.min.y >= 0.0 && row.max.y <= 700.0, "a scrolled effect stays inside the window: {row:?}");
|
||||
h.get_by_label("Neutron — Motion").click();
|
||||
h.run_steps(3);
|
||||
assert_eq!(added_effect(&h), Some(("neutron".into(), deckcraft_model::anim::AnimClass::Path)));
|
||||
}
|
||||
@@ -1,209 +1,211 @@
|
||||
use super::{
|
||||
Align2, AnimClass, CornerRadius, Icon, Rect, Sense, SlideApp, Tokens, Ui, big, big_button, big_button_ex, dropdown, enabled, group, icons, json,
|
||||
pos2, rows, run, theme, vec2, widgets,
|
||||
};
|
||||
use super::design::{grid_pick, tile_groups};
|
||||
use crate::{SlideApp, icons::Icon};
|
||||
use craft::keymap::CommandRef;
|
||||
use craft::menu::ribbon::{Gallery, GalleryFace, GalleryItem, GalleryMore, RibbonGroup, RibbonRow};
|
||||
use craft::ui::buttons::{Arrangement, Button, ToggleButton};
|
||||
use craft::ui::contract::{Bind, BodyCx, Entry, PopupKind, Props as _, Show as _, ShowContainer as _, Trigger};
|
||||
use craft::ui::list::ThumbAspect;
|
||||
use craft::ui::menu::{Menu, MenuItem};
|
||||
use craft::ui::pickers::Select;
|
||||
use craft::ui::primitives::{ContentPainterCx, IconSpec};
|
||||
use craft::ui::text::NumberField;
|
||||
use craft::ui::tile_grid::{CaptionPlace, Tile, TileGrid};
|
||||
use deckcraft_model::AnimClass;
|
||||
use egui::{Rect, Ui, pos2, vec2};
|
||||
use serde_json::json;
|
||||
|
||||
// ---------- Animations ----------
|
||||
|
||||
/// Render animation preview, gallery, add/effect options, trigger, timing, and playback controls.
|
||||
// P3(ribbon-w8): rb.A4
|
||||
pub(super) fn animations_base(app: &mut SlideApp, ui: &mut Ui) {
|
||||
/// Opens the animation controls for the selected shape.
|
||||
pub(crate) fn animations(app: &mut SlideApp, row: &mut RibbonRow<'_>) {
|
||||
let has_sel = app.session.active().is_some_and(|d| !d.selection.shapes.is_empty());
|
||||
let cur: Option<deckcraft_model::Animation> = app.session.active().and_then(|d| {
|
||||
let s = d.current_slide()?;
|
||||
let cur = app.session.active().and_then(|d| {
|
||||
let slide = d.current_slide()?;
|
||||
let id = d.selection.shapes.first()?;
|
||||
s.animations.iter().find(|a| a.shape == *id).cloned()
|
||||
slide.animations.iter().find(|a| a.shape == *id).cloned()
|
||||
});
|
||||
group(ui, |ui| {
|
||||
let playing = app.anim_preview_active();
|
||||
let (resp, _) = big_button_ex(ui, Icon::Preview, "Preview", true, false, playing);
|
||||
if resp.on_hover_text("Play this slide's animations on the canvas").clicked() {
|
||||
run(app, "animation.preview", json!({}));
|
||||
}
|
||||
row.group(RibbonGroup::new("preview", "Preview", Icon::Preview.id().into()), |ui| {
|
||||
ToggleButton::command("animation.preview")
|
||||
.label("Preview")
|
||||
.icon(Icon::Preview.id())
|
||||
.arrangement(Arrangement::Stacked)
|
||||
.tooltip("Play this slide's animations on the canvas")
|
||||
.show(ui);
|
||||
});
|
||||
group(ui, |ui| {
|
||||
let quick: Vec<_> = deckcraft_model::anim::ANIMATIONS
|
||||
.iter()
|
||||
.filter(|a| {
|
||||
matches!(
|
||||
a.0,
|
||||
"appear"
|
||||
| "fade"
|
||||
| "fly"
|
||||
| "float"
|
||||
| "split"
|
||||
| "wipe"
|
||||
| "zoom"
|
||||
| "pulse"
|
||||
| "spin"
|
||||
| "growShrink"
|
||||
| "fadeOut"
|
||||
| "flyOut"
|
||||
| "lines"
|
||||
)
|
||||
row.group(RibbonGroup::new("animations", "Animation", Icon::AnimEntrance.id().into()), |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
let quick: Vec<_> = deckcraft_model::anim::ANIMATIONS
|
||||
.iter()
|
||||
.filter(|a| {
|
||||
matches!(
|
||||
a.0,
|
||||
"appear"
|
||||
| "fade"
|
||||
| "fly"
|
||||
| "float"
|
||||
| "split"
|
||||
| "wipe"
|
||||
| "zoom"
|
||||
| "pulse"
|
||||
| "spin"
|
||||
| "growShrink"
|
||||
| "fadeOut"
|
||||
| "flyOut"
|
||||
| "lines"
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
let classes =
|
||||
[(AnimClass::Entrance, "Entrance"), (AnimClass::Emphasis, "Emphasis"), (AnimClass::Exit, "Exit"), (AnimClass::Path, "Motion Paths")];
|
||||
let all: Vec<_> = classes.iter().flat_map(|(class, _)| deckcraft_model::anim::ANIMATIONS.iter().filter(move |a| a.2 == *class)).collect();
|
||||
let sections: Vec<_> = classes.iter().map(|(class, label)| (*label, all.iter().filter(|a| a.2 == *class).count())).collect();
|
||||
let groups = tile_groups(§ions);
|
||||
let selected = cur.as_ref().and_then(|c| quick.iter().position(|a| a.0 == c.effect && a.2 == c.class));
|
||||
let more_selected = cur.as_ref().and_then(|c| all.iter().position(|a| a.0 == c.effect && a.2 == c.class));
|
||||
let paints: Vec<Box<dyn Fn(&ContentPainterCx, Rect) + '_>> = quick
|
||||
.iter()
|
||||
.map(|a| Box::new(move |cx: &ContentPainterCx, r| paint_anim_tile(cx, r, a.2)) as Box<dyn Fn(&ContentPainterCx, Rect)>)
|
||||
.collect();
|
||||
let items: Vec<_> = quick
|
||||
.iter()
|
||||
.zip(&paints)
|
||||
.enumerate()
|
||||
.map(|(i, (a, paint))| GalleryItem { key: i, label: a.1.into(), face: GalleryFace::Paint(&**paint) })
|
||||
.collect();
|
||||
let mut more_pick = None;
|
||||
let mut more = |ui: &mut Ui, cx: &mut BodyCx<'_>| {
|
||||
if let Some(index) =
|
||||
grid_pick(ui, TileGrid::new("Animations").groups(&groups).card_columns(7).enabled(has_sel), all.len(), more_selected, |i| {
|
||||
let a = all[i];
|
||||
Tile::new(a.1).thumb(ThumbAspect::new(1, 1), move |cx, r| paint_anim_tile(cx, r, a.2))
|
||||
})
|
||||
{
|
||||
more_pick = Some(index);
|
||||
cx.request_close();
|
||||
}
|
||||
};
|
||||
let output = Gallery::new("Animations", &items, selected.as_ref())
|
||||
.tiles(8, 4)
|
||||
.caption(CaptionPlace::Below)
|
||||
.enabled(has_sel)
|
||||
.more(GalleryMore::Body(&mut more))
|
||||
.show(ui);
|
||||
if let Some(a) = output.picked.and_then(|i| quick.get(i).copied()).or_else(|| more_pick.and_then(|i| all.get(i).copied())) {
|
||||
let _ = app.run("animation.set", json!({"effect": a.0, "class": a.2.xml()}));
|
||||
}
|
||||
let effect_rows = cur.as_ref().map(|c| animation_effect_rows(&c.effect, c.class, Some(c.option.as_str()))).unwrap_or_default();
|
||||
let effect = cur.as_ref().map(|c| c.effect.as_str()).unwrap_or_default();
|
||||
let build = cur.as_ref().map(|c| text_build_id(c.text_build));
|
||||
let button = Button::new("Effect\nOptions")
|
||||
.icon(Icon::EffectOptions.id())
|
||||
.arrangement(Arrangement::Stacked)
|
||||
.enabled(cur.is_some())
|
||||
.popup(PopupKind::Menu)
|
||||
.show(ui);
|
||||
Menu::new("Effect Options").opened_by(&button.response, Trigger::Click).show(ui, |ui, _| {
|
||||
for &(option, on) in &effect_rows {
|
||||
if MenuItem::new(animation_option_label(effect, option)).radio_mark(on).show(ui).ran {
|
||||
let _ = app.run("animation.options", json!({"option": option}));
|
||||
}
|
||||
}
|
||||
for (id, on) in marked_options(&["asOne", "byParagraph"], build) {
|
||||
let label = if id == "byParagraph" { "By Paragraph" } else { "As One Object" };
|
||||
if MenuItem::new(label).radio_mark(on).show(ui).ran {
|
||||
let _ = app.run("animation.options", json!({"textBuild": id}));
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
row.group(RibbonGroup::new("advanced-animation", "Advanced Animation", Icon::AddAnimation.id().into()), |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
let button = Button::new("Add\nAnimation")
|
||||
.icon(Icon::AddAnimation.id())
|
||||
.arrangement(Arrangement::Stacked)
|
||||
.enabled(has_sel)
|
||||
.popup(PopupKind::Menu)
|
||||
.show(ui);
|
||||
Menu::new("Add Animation").opened_by(&button.response, Trigger::Click).show(ui, |ui, _| {
|
||||
for (class, label) in [
|
||||
(AnimClass::Entrance, "Entrance"),
|
||||
(AnimClass::Emphasis, "Emphasis"),
|
||||
(AnimClass::Exit, "Exit"),
|
||||
(AnimClass::Path, "Motion Paths"),
|
||||
] {
|
||||
MenuItem::heading(label).show(ui);
|
||||
for a in deckcraft_model::anim::ANIMATIONS.iter().filter(|a| a.2 == class) {
|
||||
if MenuItem::new(a.1).show(ui).ran {
|
||||
let _ = app.run("animation.add", json!({"effect": a.0, "class": a.2.xml()}));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
Button::command(CommandRef::with_params("view.pane", json!({"pane": "animation"})))
|
||||
.label("Animation\nPane")
|
||||
.icon(Icon::AnimationPane.id())
|
||||
.arrangement(Arrangement::Stacked)
|
||||
.show(ui);
|
||||
let button = Button::new("Trigger")
|
||||
.icon(Icon::Trigger.id())
|
||||
.arrangement(Arrangement::Stacked)
|
||||
.enabled(cur.is_some())
|
||||
.popup(PopupKind::Menu)
|
||||
.show(ui);
|
||||
Menu::new("Trigger").opened_by(&button.response, Trigger::Click).show(ui, |ui, _| {
|
||||
if MenuItem::new("On Click of… (none)").show(ui).ran {
|
||||
let _ = app.run("animation.timing", json!({"trigger": null}));
|
||||
}
|
||||
let shapes: Vec<_> = app.session.active().map(|d| d.shapes().iter().map(|s| (s.id.0, s.name.clone())).collect()).unwrap_or_default();
|
||||
Menu::submenu_row(ui, "On Click Of", |ui, _| {
|
||||
for (id, name) in &shapes {
|
||||
if MenuItem::new(name.clone()).show(ui).ran {
|
||||
let _ = app.run("animation.timing", json!({"trigger": id}));
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
let armed = app.session.anim_painter.is_some();
|
||||
super::home::painter_toggle(app, ui, Icon::AnimationPainter, "Animation\nPainter", "animation.painter", armed);
|
||||
});
|
||||
});
|
||||
row.group(RibbonGroup::new("timing", "Timing", Icon::Duration.id().into()), |ui| {
|
||||
let starts = [
|
||||
Entry::new("onClick".to_string(), "On Click"),
|
||||
Entry::new("withPrevious".to_string(), "With Previous"),
|
||||
Entry::new("afterPrevious".to_string(), "After Previous"),
|
||||
];
|
||||
let start = cur
|
||||
.as_ref()
|
||||
.map(|c| match c.start {
|
||||
deckcraft_model::AnimStart::OnClick => "onClick",
|
||||
deckcraft_model::AnimStart::WithPrevious => "withPrevious",
|
||||
deckcraft_model::AnimStart::AfterPrevious => "afterPrevious",
|
||||
})
|
||||
.collect();
|
||||
let sel = cur.as_ref().and_then(|c| quick.iter().position(|a| a.0 == c.effect));
|
||||
if let Some(i) = widgets::gallery(
|
||||
ui,
|
||||
quick.len(),
|
||||
vec2(50.0, 56.0),
|
||||
sel,
|
||||
|p, r, i| {
|
||||
if let Some(a) = quick.get(i) {
|
||||
paint_anim_tile(p, r, a.1, a.2, has_sel);
|
||||
}
|
||||
},
|
||||
|i| quick.get(i).map(|a| a.1.to_string()).unwrap_or_default(),
|
||||
) && let Some(a) = quick.get(i)
|
||||
{
|
||||
run(app, "animation.set", json!({"effect": a.0, "class": a.2.xml()}));
|
||||
.unwrap_or("")
|
||||
.to_string();
|
||||
let out = Select::new("Start:", Bind::given(start), &starts).enabled(cur.is_some()).show(ui);
|
||||
if let Some(start) = out.events.committed() {
|
||||
let _ = app.run("animation.timing", json!({"start": start}));
|
||||
}
|
||||
let more = widgets::drop_button(ui, "", vec2(14.0, 52.0), has_sel);
|
||||
egui::Popup::menu(&more).width(420.0).show(|ui| {
|
||||
for (cls, label) in
|
||||
[(AnimClass::Entrance, "Entrance"), (AnimClass::Emphasis, "Emphasis"), (AnimClass::Exit, "Exit"), (AnimClass::Path, "Motion Paths")]
|
||||
{
|
||||
ui.label(egui::RichText::new(label).font(theme::bold(12.0)));
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
for a in deckcraft_model::anim::ANIMATIONS.iter().filter(|a| a.2 == cls) {
|
||||
let (r, resp) = ui.allocate_exact_size(vec2(56.0, 54.0), Sense::click());
|
||||
if resp.hovered() {
|
||||
ui.painter().rect_filled(r, CornerRadius::same(4), Tokens::get(ui.ctx()).hover);
|
||||
}
|
||||
paint_anim_tile(ui.painter(), r.shrink(2.0), a.1, a.2, true);
|
||||
if resp.clicked() {
|
||||
run(app, "animation.set", json!({"effect": a.0, "class": a.2.xml()}));
|
||||
ui.close();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
let effect_rows = cur.as_ref().map(|c| animation_effect_rows(&c.effect, c.class, Some(c.option.as_str()))).unwrap_or_default();
|
||||
let effect = cur.as_ref().map(|c| c.effect.as_str()).unwrap_or_default();
|
||||
let build = cur.as_ref().map(|c| text_build_id(c.text_build));
|
||||
let build_rows = marked_options(&["asOne", "byParagraph"], build);
|
||||
let r = big_button(ui, Icon::EffectOptions, "Effect\nOptions", !effect_rows.is_empty());
|
||||
egui::Popup::menu(&r).show(|ui| {
|
||||
for &(o, on) in &effect_rows {
|
||||
if ui.selectable_label(on, animation_option_label(effect, o)).clicked() {
|
||||
run(app, "animation.options", json!({"option": o}));
|
||||
ui.close();
|
||||
}
|
||||
}
|
||||
ui.separator();
|
||||
for &(id, on) in &build_rows {
|
||||
let label = if id == "byParagraph" { "By Paragraph" } else { "As One Object" };
|
||||
if ui.selectable_label(on, label).clicked() {
|
||||
run(app, "animation.options", json!({"textBuild": id}));
|
||||
ui.close();
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
group(ui, |ui| {
|
||||
let r = big_button(ui, Icon::AddAnimation, "Add\nAnimation", has_sel);
|
||||
// Every effect in one column is taller than a 1440p screen, so cap the height and scroll (#1370).
|
||||
// The menu opens under the title bar and the ribbon; keep that chrome out of the cap.
|
||||
let max_h = (r.ctx.viewport_rect().height() - 160.0).max(120.0);
|
||||
egui::Popup::menu(&r).width(260.0).show(|ui| {
|
||||
egui::ScrollArea::vertical().id_salt("add_animation").max_height(max_h).show(ui, |ui| {
|
||||
for a in deckcraft_model::anim::ANIMATIONS.iter().filter(|a| a.2 != AnimClass::Media) {
|
||||
if ui
|
||||
.button(format!(
|
||||
"{} — {}",
|
||||
a.1,
|
||||
match a.2 {
|
||||
AnimClass::Entrance => "Entrance",
|
||||
AnimClass::Emphasis => "Emphasis",
|
||||
AnimClass::Exit => "Exit",
|
||||
_ => "Motion",
|
||||
}
|
||||
))
|
||||
.clicked()
|
||||
{
|
||||
run(app, "animation.add", json!({"effect": a.0, "class": a.2.xml()}));
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
big(app, ui, Icon::AnimationPane, "Animation\nPane", "view.pane", json!({"pane": "animation"}));
|
||||
let r = big_button(ui, Icon::Trigger, "Trigger", cur.is_some());
|
||||
egui::Popup::menu(&r).show(|ui| {
|
||||
if ui.button("On Click of… (none)").clicked() {
|
||||
run(app, "animation.timing", json!({"trigger": null}));
|
||||
}
|
||||
let shapes: Vec<(u32, String)> =
|
||||
app.session.active().map(|d| d.shapes().iter().map(|s| (s.id.0, s.name.clone())).collect()).unwrap_or_default();
|
||||
for (id, name) in shapes {
|
||||
if ui.button(format!("On Click of {name}")).clicked() {
|
||||
run(app, "animation.timing", json!({"trigger": id}));
|
||||
}
|
||||
}
|
||||
});
|
||||
let on = app.session.anim_painter.is_some();
|
||||
let en = enabled(app, "animation.painter");
|
||||
let (r, _) = big_button_ex(ui, Icon::AnimationPainter, "Animation\nPainter", en, false, on);
|
||||
let r = r.on_hover_text("Animation Painter (double-click to keep it on)");
|
||||
if r.double_clicked() {
|
||||
run(app, "animation.painter", json!({"sticky": true}));
|
||||
} else if r.clicked() {
|
||||
if on {
|
||||
app.session.anim_painter = None;
|
||||
} else {
|
||||
run(app, "animation.painter", json!({}));
|
||||
for (label, key, seconds) in [
|
||||
("Duration:", "duration", cur.as_ref().map(|c| c.duration_ms as f64 / 1000.0).unwrap_or(0.5)),
|
||||
("Delay:", "delay", cur.as_ref().map(|c| c.delay_ms as f64 / 1000.0).unwrap_or(0.0)),
|
||||
] {
|
||||
let out = NumberField::new(label, Bind::given(Some(seconds))).range(0.0..=f64::MAX).step(0.25).unit("s").enabled(cur.is_some()).show(ui);
|
||||
if let Some(seconds) = out.events.committed().and_then(|value| *value) {
|
||||
let _ = app.run("animation.timing", json!({(key): (seconds * 1000.0).round() as u64}));
|
||||
}
|
||||
}
|
||||
});
|
||||
group(ui, |ui| {
|
||||
rows(ui, |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Start:");
|
||||
let s = cur.as_ref().map(|c| match c.start {
|
||||
deckcraft_model::AnimStart::OnClick => "On Click",
|
||||
deckcraft_model::AnimStart::WithPrevious => "With Previous",
|
||||
deckcraft_model::AnimStart::AfterPrevious => "After Previous",
|
||||
});
|
||||
dropdown(ui, "Start", s.unwrap_or(""), 112.0, cur.is_some(), |ui| {
|
||||
for (l, v) in [("On Click", "onClick"), ("With Previous", "withPrevious"), ("After Previous", "afterPrevious")] {
|
||||
if ui.button(l).clicked() {
|
||||
run(app, "animation.timing", json!({"start": v}));
|
||||
ui.close();
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Duration:");
|
||||
if let Some(v) =
|
||||
widgets::spinner(ui, "adur", "Duration", cur.as_ref().map(|c| c.duration_ms as f64 / 1000.0).unwrap_or(0.5), 0.25, "", 46.0)
|
||||
{
|
||||
run(app, "animation.timing", json!({"duration": (v.max(0.0) * 1000.0).round() as u64}));
|
||||
}
|
||||
});
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Delay:");
|
||||
if let Some(v) =
|
||||
widgets::spinner(ui, "adelay", "Delay", cur.as_ref().map(|c| c.delay_ms as f64 / 1000.0).unwrap_or(0.0), 0.25, "", 46.0)
|
||||
{
|
||||
run(app, "animation.timing", json!({"delay": (v.max(0.0) * 1000.0).round() as u64}));
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
pub fn paint_anim_tile(p: &egui::Painter, r: Rect, label: &str, class: AnimClass, enabled: bool) {
|
||||
let t = Tokens::get(p.ctx());
|
||||
fn paint_anim_tile(cx: &ContentPainterCx<'_>, r: Rect, class: AnimClass) {
|
||||
let icon = match class {
|
||||
AnimClass::Entrance => Icon::AnimEntrance,
|
||||
AnimClass::Emphasis => Icon::AnimEmphasis,
|
||||
AnimClass::Exit => Icon::AnimExit,
|
||||
_ => Icon::AnimPath,
|
||||
};
|
||||
icons::paint(p, Rect::from_center_size(pos2(r.center().x, r.min.y + 18.0), vec2(28.0, 28.0)), icon, t.text, !enabled);
|
||||
p.text(pos2(r.center().x, r.max.y - 8.0), Align2::CENTER_CENTER, label, theme::font(10.0), if enabled { t.text } else { t.text_faint });
|
||||
// PLAN: plan error: the icon-only tile signature delegates its removed label to the gallery caption.
|
||||
cx.icon(Rect::from_center_size(pos2(r.center().x, r.min.y + 18.0), vec2(28.0, 28.0)), &IconSpec::from(icon.id()));
|
||||
}
|
||||
|
||||
/// The stored id is the one marked row. Every other id stays unmarked.
|
||||
@@ -268,7 +270,7 @@ fn animation_option_label(effect: &str, option: &str) -> String {
|
||||
(_, "counterClockwise") => "Counterclockwise".into(),
|
||||
(_, "in") => "In".into(),
|
||||
(_, "out") => "Out".into(),
|
||||
(_, other) => super::transitions::option_label(other),
|
||||
(_, other) => option_label(other),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -290,51 +292,29 @@ pub(super) fn text_build_id(build: deckcraft_model::anim::TextBuild) -> &'static
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod animation_option_label_tests {
|
||||
use super::animation_option_label;
|
||||
use deckcraft_model::anim::ANIMATIONS;
|
||||
|
||||
#[test]
|
||||
fn labels_every_animation_gallery_option_without_changing_its_code() {
|
||||
for &(effect, _, _, _, _, options) in ANIMATIONS {
|
||||
for &option in options {
|
||||
let label = animation_option_label(effect, option);
|
||||
assert!(!label.is_empty(), "{effect}/{option}");
|
||||
assert_ne!(label, option, "raw option shown for {effect}/{option}");
|
||||
fn option_label(o: &str) -> String {
|
||||
match o {
|
||||
"l" => "From Left".into(),
|
||||
"r" => "From Right".into(),
|
||||
"u" => "From Top".into(),
|
||||
"d" => "From Bottom".into(),
|
||||
"horz" => "Horizontal".into(),
|
||||
"vert" => "Vertical".into(),
|
||||
"in" => "In".into(),
|
||||
"out" => "Out".into(),
|
||||
other => {
|
||||
let mut s = String::new();
|
||||
for (i, c) in other.chars().enumerate() {
|
||||
if i == 0 {
|
||||
s.extend(c.to_uppercase());
|
||||
} else if c.is_uppercase() {
|
||||
s.push(' ');
|
||||
s.push(c);
|
||||
} else {
|
||||
s.push(c);
|
||||
}
|
||||
}
|
||||
s
|
||||
}
|
||||
assert_eq!(animation_option_label("fly", "lb"), "From Bottom-Left");
|
||||
assert_eq!(animation_option_label("flyOut", "rt"), "To Top-Right");
|
||||
assert_eq!(animation_option_label("flyOut", "b"), "To Bottom");
|
||||
assert_eq!(animation_option_label("peekOut", "l"), "To Left");
|
||||
assert_eq!(animation_option_label("wipe", "b"), "From Bottom");
|
||||
assert_eq!(animation_option_label("wheel", "1"), "1 Spoke");
|
||||
assert_eq!(animation_option_label("split", "vertOut"), "Vertical Out");
|
||||
assert_eq!(animation_option_label("shape", "circleIn"), "Circle In");
|
||||
assert_eq!(animation_option_label("diamond", "out"), "Diamond Out");
|
||||
assert_eq!(animation_option_label("diamondOut", "in"), "Diamond In");
|
||||
assert_eq!(animation_option_label("diamondOut", "out"), "Diamond Out");
|
||||
assert_eq!(animation_option_label("strips", "lu"), "Left Up");
|
||||
assert_eq!(animation_option_label("strips", "ru"), "Right Up");
|
||||
assert_eq!(animation_option_label("strips", "ld"), "Left Down");
|
||||
assert_eq!(animation_option_label("strips", "rd"), "Right Down");
|
||||
assert_eq!(animation_option_label("crawl", "b"), "From Bottom");
|
||||
assert_eq!(animation_option_label("crawl", "l"), "From Left");
|
||||
assert_eq!(animation_option_label("crawl", "t"), "From Top");
|
||||
assert_eq!(animation_option_label("crawl", "r"), "From Right");
|
||||
assert_eq!(animation_option_label("crawlOut", "l"), "To Left");
|
||||
assert_eq!(animation_option_label("crawlOut", "r"), "To Right");
|
||||
assert_eq!(animation_option_label("plus", "in"), "In");
|
||||
assert_eq!(animation_option_label("plus", "out"), "Out");
|
||||
assert_eq!(animation_option_label("changeFontSize", "increase"), "Increase");
|
||||
assert_eq!(animation_option_label("changeFontSize", "decrease"), "Decrease");
|
||||
}
|
||||
}
|
||||
|
||||
/// Opens this tab's ribbon groups.
|
||||
#[allow(dead_code)] // P3(ribbon-w8): rb.A4
|
||||
pub(crate) fn animations(app: &mut SlideApp, row: &mut craft::menu::ribbon::RibbonRow<'_>) {
|
||||
let _ = (app, row);
|
||||
todo!("rb.A4")
|
||||
}
|
||||
|
||||
+220
-160
@@ -1,191 +1,251 @@
|
||||
use super::{
|
||||
Align2, Color32, CornerRadius, Icon, Rect, Sense, SlideApp, Stroke, Tokens, Ui, big, big_button, enabled, group, json, pos2, run, scheme,
|
||||
small_button, theme, vec2, widgets,
|
||||
use crate::{SlideApp, icons::Icon, theme};
|
||||
use craft::behavior::{Selection, SelectionChange, keyed};
|
||||
use craft::keymap::CommandRef;
|
||||
use craft::menu::ribbon::{Gallery, GalleryFace, GalleryItem, GalleryMore, RibbonGroup, RibbonRow};
|
||||
use craft::ui::buttons::{Arrangement, Button};
|
||||
use craft::ui::contract::{
|
||||
Bind, BodyCx, CollectionEvent, PopupKind, Props as _, SelectMode, Show as _, ShowCollection as _, ShowContainer as _, Sizing, Trigger,
|
||||
};
|
||||
use craft::ui::fonts::FontRef;
|
||||
use craft::ui::list::ThumbAspect;
|
||||
use craft::ui::menu::{Menu, MenuItem};
|
||||
use craft::ui::primitives::{ContentPainterCx, DocRun, DocText, FacePaint, PaintShape};
|
||||
use craft::ui::style::DataColor;
|
||||
use craft::ui::tile_grid::{CaptionPlace, Tile, TileGrid, TileGroup};
|
||||
use egui::{Color32, CornerRadius, Rect, Ui, pos2, vec2};
|
||||
use serde_json::json;
|
||||
|
||||
// ---------- Design ----------
|
||||
|
||||
/// Render the Design tab's themes, variants, colours, fonts, effects, background, and slide
|
||||
/// size controls.
|
||||
// P3(ribbon-w8): rb.A4
|
||||
pub(super) fn design_base(app: &mut SlideApp, ui: &mut Ui) {
|
||||
/// Opens the document design controls in the ribbon.
|
||||
pub(crate) fn design(app: &mut SlideApp, row: &mut RibbonRow<'_>) {
|
||||
let themes = deckcraft_model::theme::builtin_themes();
|
||||
let cur = app.session.active().and_then(|d| d.doc.masters.first().map(|m| m.theme.name.clone())).unwrap_or_default();
|
||||
group(ui, |ui| {
|
||||
let sel = themes.iter().position(|th| th.name == cur);
|
||||
let names: Vec<String> = themes.iter().map(|t| t.name.clone()).collect();
|
||||
if let Some(i) = widgets::gallery(
|
||||
ui,
|
||||
themes.len(),
|
||||
vec2(84.0, 56.0),
|
||||
sel,
|
||||
|p, r, i| {
|
||||
if let Some(th) = themes.get(i) {
|
||||
// P3(ribbon-w8): rb.A20
|
||||
paint_theme_tile_base(p, r, th);
|
||||
}
|
||||
},
|
||||
|i| names.get(i).cloned().unwrap_or_default(),
|
||||
) && let Some(n) = names.get(i)
|
||||
{
|
||||
run(app, "design.theme", json!({"name": n}));
|
||||
}
|
||||
if small_button(ui, Icon::Themes, "Browse for Themes…", enabled(app, "design.browseTheme"), false).clicked() {
|
||||
run(app, "app.browseThemeDialog", json!({}));
|
||||
let current = app.session.active().and_then(|d| d.doc.masters.first().map(|m| m.theme.name.clone())).unwrap_or_default();
|
||||
let names: Vec<_> = themes.iter().map(|t| t.name.clone()).collect();
|
||||
let paints: Vec<Box<dyn Fn(&ContentPainterCx, Rect) + '_>> = themes
|
||||
.iter()
|
||||
.map(|th| Box::new(move |cx: &ContentPainterCx, r| paint_theme_tile(cx, r, th)) as Box<dyn Fn(&ContentPainterCx, Rect)>)
|
||||
.collect();
|
||||
let items: Vec<_> = names
|
||||
.iter()
|
||||
.zip(&paints)
|
||||
.enumerate()
|
||||
.map(|(i, (name, paint))| GalleryItem { key: i, label: name.clone().into(), face: GalleryFace::Paint(&**paint) })
|
||||
.collect();
|
||||
let selected = names.iter().position(|n| *n == current);
|
||||
row.group(RibbonGroup::new("themes", "Themes", Icon::Themes.id().into()), |ui| {
|
||||
let mut more_pick = None;
|
||||
let mut more = |ui: &mut Ui, cx: &mut BodyCx<'_>| {
|
||||
if let Some(i) = grid_pick(ui, TileGrid::new("Themes").card_columns(4), themes.len(), selected, |i| {
|
||||
let th = &themes[i];
|
||||
Tile::new(names[i].clone()).thumb(ThumbAspect::new(3, 2), move |cx, r| paint_theme_tile(cx, r, th))
|
||||
}) {
|
||||
more_pick = Some(names[i].clone());
|
||||
cx.request_close();
|
||||
}
|
||||
// PLAN: plan error: design.browseTheme requires import data; the picker command is app.browseThemeDialog.
|
||||
if Button::command("app.browseThemeDialog").label("Browse for Themes…").show(ui).clicked() {
|
||||
cx.request_close();
|
||||
}
|
||||
};
|
||||
let output = Gallery::new("Themes", &items, selected.as_ref())
|
||||
.tiles(5, 2)
|
||||
.aspect(ThumbAspect::new(3, 2))
|
||||
.caption(CaptionPlace::Below)
|
||||
.more(GalleryMore::Body(&mut more))
|
||||
.show(ui);
|
||||
if let Some(name) = output.picked.and_then(|i| names.get(i).cloned()).or(more_pick) {
|
||||
let _ = app.run("design.theme", json!({"name": name}));
|
||||
}
|
||||
});
|
||||
// Variants: the current theme in its four colour variations.
|
||||
if let Some(th) = app.session.active().and_then(|d| d.doc.masters.first().map(|m| m.theme.clone())) {
|
||||
let variants = deckcraft_model::theme::theme_variants(&th);
|
||||
let tiles: Vec<deckcraft_model::Theme> = variants.iter().map(|c| deckcraft_model::Theme { colors: c.clone(), ..th.clone() }).collect();
|
||||
let names: Vec<String> = variants.iter().map(|c| c.name.clone()).collect();
|
||||
let sel = variants.iter().position(|c| c.colors == th.colors.colors);
|
||||
group(ui, |ui| {
|
||||
if let Some(i) = widgets::gallery(
|
||||
ui,
|
||||
tiles.len(),
|
||||
vec2(84.0, 56.0),
|
||||
sel,
|
||||
|p, r, i| {
|
||||
if let Some(t) = tiles.get(i) {
|
||||
// P3(ribbon-w8): rb.A20
|
||||
paint_theme_tile_base(p, r, t);
|
||||
}
|
||||
},
|
||||
|i| names.get(i).cloned().unwrap_or_default(),
|
||||
) {
|
||||
run(app, "design.variant", json!({"index": i}));
|
||||
let tiles: Vec<_> = variants.iter().map(|c| deckcraft_model::Theme { colors: c.clone(), ..th.clone() }).collect();
|
||||
let current = variants.iter().position(|c| c.colors == th.colors.colors);
|
||||
let paints: Vec<Box<dyn Fn(&ContentPainterCx, Rect) + '_>> = tiles
|
||||
.iter()
|
||||
.map(|th| Box::new(move |cx: &ContentPainterCx, r| paint_theme_tile(cx, r, th)) as Box<dyn Fn(&ContentPainterCx, Rect)>)
|
||||
.collect();
|
||||
let items: Vec<_> = tiles
|
||||
.iter()
|
||||
.zip(&paints)
|
||||
.enumerate()
|
||||
.map(|(i, (th, paint))| GalleryItem { key: i, label: th.colors.name.clone().into(), face: GalleryFace::Paint(&**paint) })
|
||||
.collect();
|
||||
row.group(RibbonGroup::new("variants", "Variants", Icon::Themes.id().into()), |ui| {
|
||||
if let Some(index) = Gallery::new("Variants", &items, current.as_ref())
|
||||
.tiles(4, 2)
|
||||
.aspect(ThumbAspect::new(3, 2))
|
||||
.caption(CaptionPlace::Below)
|
||||
.show(ui)
|
||||
.picked
|
||||
{
|
||||
let _ = app.run("design.variant", json!({"index": index}));
|
||||
}
|
||||
});
|
||||
}
|
||||
group(ui, |ui| {
|
||||
let r = big_button(ui, Icon::Colors, "Colors", true);
|
||||
r.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Button, true, "Colors"));
|
||||
egui::Popup::menu(&r).width(240.0).show(|ui| {
|
||||
for cs in deckcraft_model::theme::builtin_color_schemes() {
|
||||
ui.horizontal(|ui| {
|
||||
let (rect, resp) = ui.allocate_exact_size(vec2(220.0, 20.0), Sense::click());
|
||||
let p = ui.painter();
|
||||
for (k, c) in cs.colors.iter().take(10).skip(2).enumerate() {
|
||||
p.rect_filled(
|
||||
Rect::from_min_size(rect.min + vec2(k as f32 * 12.0, 3.0), vec2(11.0, 14.0)),
|
||||
CornerRadius::ZERO,
|
||||
theme::to_color32(*c),
|
||||
);
|
||||
row.group(RibbonGroup::new("theme-options", "Customize", Icon::Colors.id().into()), |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
let button = Button::new("Colors").icon(Icon::Colors.id()).arrangement(Arrangement::Stacked).popup(PopupKind::Menu).show(ui);
|
||||
Menu::new("Colors").opened_by(&button.response, Trigger::Click).show(ui, |ui, _| {
|
||||
for (i, cs) in deckcraft_model::theme::builtin_color_schemes().into_iter().enumerate() {
|
||||
let colors = cs.colors;
|
||||
let sample = FacePaint::new(i as u64, move |cx, r| {
|
||||
cx.with_draw(|draw| {
|
||||
for (k, color) in colors.iter().take(10).skip(2).enumerate() {
|
||||
let rect = Rect::from_min_size(r.min + vec2(k as f32 * 12.0, 3.0), vec2(11.0, 14.0));
|
||||
draw.data_fill(&PaintShape::Rect(rect, CornerRadius::ZERO), DataColor::new(theme::to_color32(*color)));
|
||||
}
|
||||
})
|
||||
});
|
||||
// PLAN: plan error: the widget MenuItem::new takes a label; the two-argument signature belongs to cloud-ui.
|
||||
if MenuItem::new(cs.name.clone()).sample(ThumbAspect::new(48, 10), sample).show(ui).ran {
|
||||
let _ = app.run("design.colors", json!({"name": cs.name}));
|
||||
}
|
||||
p.text(rect.min + vec2(104.0, 10.0), Align2::LEFT_CENTER, &cs.name, theme::font(12.0), Tokens::get(ui.ctx()).text);
|
||||
if resp.clicked() {
|
||||
run(app, "design.colors", json!({"name": cs.name}));
|
||||
ui.close();
|
||||
}
|
||||
if MenuItem::new("Customize Colors…").show(ui).ran {
|
||||
let _ = app.run("design.colors", json!({}));
|
||||
}
|
||||
});
|
||||
let button = Button::new("Fonts").icon(Icon::Fonts.id()).arrangement(Arrangement::Stacked).popup(PopupKind::Menu).show(ui);
|
||||
Menu::new("Fonts").opened_by(&button.response, Trigger::Click).show(ui, |ui, _| {
|
||||
for fs in deckcraft_model::theme::builtin_font_schemes() {
|
||||
if MenuItem::new(fs.name.clone()).detail(format!("{} / {}", fs.major.latin, fs.minor.latin)).show(ui).ran {
|
||||
let _ = app.run("design.fonts", json!({"name": fs.name}));
|
||||
}
|
||||
});
|
||||
}
|
||||
ui.separator();
|
||||
if ui.button("Customize Colors…").clicked() {
|
||||
run(app, "design.colors", json!({}));
|
||||
ui.close();
|
||||
}
|
||||
});
|
||||
let r = big_button(ui, Icon::Fonts, "Fonts", true);
|
||||
r.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Button, true, "Fonts"));
|
||||
egui::Popup::menu(&r).width(220.0).show(|ui| {
|
||||
for fs in deckcraft_model::theme::builtin_font_schemes() {
|
||||
if ui.button(format!("{}\n {} / {}", fs.name, fs.major.latin, fs.minor.latin)).clicked() {
|
||||
run(app, "design.fonts", json!({"name": fs.name}));
|
||||
}
|
||||
}
|
||||
ui.separator();
|
||||
if ui.button("Customize Fonts…").clicked() {
|
||||
run(app, "design.fonts", json!({}));
|
||||
ui.close();
|
||||
}
|
||||
});
|
||||
let r = big_button(ui, Icon::ShapeEffects, "Effects", true);
|
||||
r.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Button, true, "Effects"));
|
||||
egui::Popup::menu(&r).width(180.0).show(|ui| {
|
||||
for fs in deckcraft_model::theme::builtin_format_schemes() {
|
||||
if ui.button(&fs.name).clicked() {
|
||||
run(app, "design.effects", json!({"name": fs.name}));
|
||||
ui.close();
|
||||
if MenuItem::new("Customize Fonts…").show(ui).ran {
|
||||
let _ = app.run("design.fonts", json!({}));
|
||||
}
|
||||
}
|
||||
});
|
||||
let r = big_button(ui, Icon::BackgroundStyles, "Background\nStyles", true);
|
||||
egui::Popup::menu(&r).show(|ui| {
|
||||
egui::Grid::new("bgstyles").show(ui, |ui| {
|
||||
let sc = scheme(app);
|
||||
for i in 1..=12 {
|
||||
let slots = [
|
||||
deckcraft_color::SchemeSlot::Lt1,
|
||||
deckcraft_color::SchemeSlot::Lt2,
|
||||
deckcraft_color::SchemeSlot::Dk2,
|
||||
deckcraft_color::SchemeSlot::Dk1,
|
||||
];
|
||||
let base = theme::to_color32(sc.get(slots[(i - 1) % 4]));
|
||||
let shade = match (i - 1) / 4 {
|
||||
});
|
||||
let button = Button::new("Effects").icon(Icon::ShapeEffects.id()).arrangement(Arrangement::Stacked).popup(PopupKind::Menu).show(ui);
|
||||
Menu::new("Effects").opened_by(&button.response, Trigger::Click).show(ui, |ui, _| {
|
||||
for fs in deckcraft_model::theme::builtin_format_schemes() {
|
||||
if MenuItem::new(fs.name.clone()).show(ui).ran {
|
||||
let _ = app.run("design.effects", json!({"name": fs.name}));
|
||||
}
|
||||
}
|
||||
});
|
||||
let button =
|
||||
Button::new("Background\nStyles").icon(Icon::BackgroundStyles.id()).arrangement(Arrangement::Stacked).popup(PopupKind::Menu).show(ui);
|
||||
Menu::new("Background Styles").opened_by(&button.response, Trigger::Click).show(ui, |ui, cx| {
|
||||
let scheme = app.color_scheme();
|
||||
let slots = [
|
||||
deckcraft_color::SchemeSlot::Lt1,
|
||||
deckcraft_color::SchemeSlot::Lt2,
|
||||
deckcraft_color::SchemeSlot::Dk2,
|
||||
deckcraft_color::SchemeSlot::Dk1,
|
||||
];
|
||||
if let Some(index) = grid_pick(ui, TileGrid::new("Background Styles").card_columns(4).caption(CaptionPlace::None), 12, None, |i| {
|
||||
let base = theme::to_color32(scheme.get(slots[i % 4]));
|
||||
let shade = match i / 4 {
|
||||
0 => base,
|
||||
1 => base.lerp_to_gamma(Color32::GRAY, 0.15),
|
||||
_ => base.lerp_to_gamma(Color32::BLACK, 0.12),
|
||||
};
|
||||
let (rect, resp) = ui.allocate_exact_size(vec2(48.0, 28.0), Sense::click());
|
||||
ui.painter().rect(rect, CornerRadius::same(2), shade, Stroke::new(1.0, Tokens::get(ui.ctx()).border), egui::StrokeKind::Inside);
|
||||
if resp.on_hover_text(format!("Style {i}")).clicked() {
|
||||
run(app, "design.background", json!({"style": i, "all": true}));
|
||||
ui.close();
|
||||
}
|
||||
if i % 4 == 0 {
|
||||
ui.end_row();
|
||||
}
|
||||
Tile::new(format!("Style {}", i + 1)).tooltip(format!("Style {}", i + 1)).thumb(ThumbAspect::new(12, 7), move |cx, r| {
|
||||
cx.with_draw(|draw| draw.data_fill(&PaintShape::Rect(r, CornerRadius::same(2)), DataColor::new(shade)));
|
||||
})
|
||||
}) {
|
||||
let _ = app.run("design.background", json!({"style": index + 1, "all": true}));
|
||||
cx.request_close();
|
||||
}
|
||||
if MenuItem::new("Reset Slide Background").show(ui).ran {
|
||||
let _ = app.run("design.background", json!({"reset": true}));
|
||||
}
|
||||
});
|
||||
if ui.button("Reset Slide Background").clicked() {
|
||||
run(app, "design.background", json!({"reset": true}));
|
||||
}
|
||||
});
|
||||
});
|
||||
group(ui, |ui| {
|
||||
let r = big_button(ui, Icon::SlideSize, "Slide\nSize", true);
|
||||
egui::Popup::menu(&r).show(|ui| {
|
||||
if ui.button("Standard (4:3)").clicked() {
|
||||
run(app, "design.slideSize", json!({"preset": "standard"}));
|
||||
}
|
||||
if ui.button("Widescreen (16:9)").clicked() {
|
||||
run(app, "design.slideSize", json!({"preset": "widescreen"}));
|
||||
}
|
||||
if ui.button("Page Setup…").clicked() {
|
||||
app.dialog = Some(crate::dialogs::Dialog::new("slideSize"));
|
||||
}
|
||||
row.group(RibbonGroup::new("slide-size", "Slide Size", Icon::SlideSize.id().into()), |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
let button = Button::new("Slide\nSize").icon(Icon::SlideSize.id()).arrangement(Arrangement::Stacked).popup(PopupKind::Menu).show(ui);
|
||||
Menu::new("Slide Size").opened_by(&button.response, Trigger::Click).show(ui, |ui, _| {
|
||||
for (label, preset) in [("Standard (4:3)", "standard"), ("Widescreen (16:9)", "widescreen")] {
|
||||
if MenuItem::new(label).show(ui).ran {
|
||||
let _ = app.run("design.slideSize", json!({"preset": preset}));
|
||||
}
|
||||
}
|
||||
if MenuItem::new("Page Setup…").show(ui).ran {
|
||||
app.open_dialog("slideSize", json!({}));
|
||||
}
|
||||
});
|
||||
Button::command(CommandRef::with_params("view.pane", json!({"pane": "background"})))
|
||||
.label("Format\nBackground")
|
||||
.icon(Icon::FormatBackground.id())
|
||||
.arrangement(Arrangement::Stacked)
|
||||
.show(ui);
|
||||
});
|
||||
big(app, ui, Icon::FormatBackground, "Format\nBackground", "view.pane", json!({"pane": "background"}));
|
||||
});
|
||||
group(ui, |ui| {
|
||||
big(app, ui, Icon::DesignIdeas, "Design\nIdeas", "view.pane", json!({"pane": "designer"}));
|
||||
row.group(RibbonGroup::new("designer", "Design Ideas", Icon::DesignIdeas.id().into()), |ui| {
|
||||
Button::command(CommandRef::with_params("view.pane", json!({"pane": "designer"})))
|
||||
.label("Design\nIdeas")
|
||||
.icon(Icon::DesignIdeas.id())
|
||||
.arrangement(Arrangement::Stacked)
|
||||
.show(ui);
|
||||
});
|
||||
}
|
||||
|
||||
// P3(ribbon-w8): rb.A20
|
||||
pub(crate) fn paint_theme_tile_base(p: &egui::Painter, r: Rect, th: &deckcraft_model::Theme) {
|
||||
let bg = theme::to_color32(th.colors.get(deckcraft_color::SchemeSlot::Lt1));
|
||||
let fg = theme::to_color32(th.colors.get(deckcraft_color::SchemeSlot::Dk1));
|
||||
p.rect(r, CornerRadius::same(2), bg, Stroke::new(1.0, Color32::from_gray(200)), egui::StrokeKind::Inside);
|
||||
p.text(r.min + vec2(8.0, r.height() * 0.42), Align2::LEFT_CENTER, "Aa", theme::font(r.height() * 0.38), fg);
|
||||
let w = (r.width() - 16.0) / 6.0;
|
||||
for k in 0..6 {
|
||||
let c = theme::to_color32(th.colors.colors.get(4 + k).copied().unwrap_or(deckcraft_color::Rgba::BLACK));
|
||||
p.rect_filled(Rect::from_min_size(pos2(r.min.x + 8.0 + k as f32 * w, r.max.y - 11.0), vec2(w - 1.5, 5.0)), CornerRadius::ZERO, c);
|
||||
/// Paints the document colours of a theme, with the interface's border role.
|
||||
pub fn paint_theme_tile(cx: &ContentPainterCx<'_>, r: Rect, th: &deckcraft_model::Theme) {
|
||||
let bg = DataColor::new(theme::to_color32(th.colors.get(deckcraft_color::SchemeSlot::Lt1)));
|
||||
let fg = DataColor::new(theme::to_color32(th.colors.get(deckcraft_color::SchemeSlot::Dk1)));
|
||||
cx.with_draw(|draw| {
|
||||
let outline = PaintShape::Rect(r, CornerRadius::same(2));
|
||||
draw.data_fill(&outline, bg);
|
||||
let runs = [DocRun::new("Aa", FontRef::proportional(), r.height() * 0.38, fg)];
|
||||
draw.doc(Rect::from_min_max(r.min + vec2(8.0, r.height() * 0.23), r.max), &DocText::new(&runs));
|
||||
let width = (r.width() - 16.0) / 6.0;
|
||||
for (k, color) in th.colors.colors.iter().skip(4).take(6).enumerate() {
|
||||
let bar = Rect::from_min_size(pos2(r.min.x + 8.0 + k as f32 * width, r.max.y - 11.0), vec2(width - 1.5, 5.0));
|
||||
draw.data_fill(&PaintShape::Rect(bar, CornerRadius::ZERO), DataColor::new(theme::to_color32(*color)));
|
||||
}
|
||||
draw.stroke(&outline, craft::ui::primitives::StrokeWidth::Thin, draw.role(|c| c.line.border));
|
||||
});
|
||||
}
|
||||
|
||||
/// Shows a single-choice grid and returns only the choice made by this pass's input.
|
||||
pub(super) fn grid_pick<'a>(
|
||||
ui: &mut Ui,
|
||||
grid: TileGrid<'a, usize>,
|
||||
count: usize,
|
||||
current: Option<usize>,
|
||||
mut tile: impl FnMut(usize) -> Tile<'a>,
|
||||
) -> Option<usize> {
|
||||
let keys: Vec<_> = (0..count).collect();
|
||||
let source = keyed(&keys, |i| *i);
|
||||
let selection = Selection::new(current.into_iter().collect(), current, current);
|
||||
let output = grid
|
||||
.select(SelectMode::Single)
|
||||
.allow_empty(false)
|
||||
.slow_click_rename(false)
|
||||
.selection(Bind::given(selection))
|
||||
.sizing(Sizing::Content)
|
||||
.show_items(ui, &source, &mut |key, _| tile(*key));
|
||||
let mut picked = None;
|
||||
for event in output.response.events {
|
||||
match event {
|
||||
CollectionEvent::Activate(key) => picked = Some(key),
|
||||
CollectionEvent::Selection { change, .. } => match change {
|
||||
SelectionChange::Set(keys) => picked = keys.last().copied(),
|
||||
SelectionChange::Toggle(key) => picked = (current != Some(key)).then_some(key),
|
||||
SelectionChange::Clear => picked = None,
|
||||
_ => {}
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
picked
|
||||
}
|
||||
|
||||
/// Opens this tab's ribbon groups.
|
||||
#[allow(dead_code)] // P3(ribbon-w8): rb.A4
|
||||
pub(crate) fn design(app: &mut SlideApp, row: &mut craft::menu::ribbon::RibbonRow<'_>) {
|
||||
let _ = (app, row);
|
||||
todo!("rb.A4")
|
||||
}
|
||||
|
||||
/// Paints a theme tile through the content painter.
|
||||
#[allow(dead_code)] // P3(ribbon-w8): rb.A20
|
||||
pub fn paint_theme_tile(cx: &craft::ui::primitives::ContentPainterCx<'_>, r: Rect, th: &deckcraft_model::Theme) {
|
||||
let _ = (cx, r, th);
|
||||
todo!("rb.A20")
|
||||
/// Builds consecutive tile groups with header keys outside the tiles' index range.
|
||||
pub(super) fn tile_groups(sections: &[(&str, usize)]) -> Vec<TileGroup<usize>> {
|
||||
let tile_count: usize = sections.iter().map(|(_, count)| count).sum();
|
||||
let mut start = 0;
|
||||
sections
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i, (label, count))| {
|
||||
let group = TileGroup::new(tile_count + i, start, *count, *label);
|
||||
start += count;
|
||||
group
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
@@ -1,208 +1,215 @@
|
||||
use super::animations::marked_options;
|
||||
use super::{
|
||||
Align2, Color32, CornerRadius, Icon, Rect, Sense, SlideApp, Stroke, Tokens, Ui, Value, big, big_button, group, json, pos2, rows, run, theme,
|
||||
vec2, widgets,
|
||||
animations::marked_options,
|
||||
design::{grid_pick, tile_groups},
|
||||
};
|
||||
use crate::{SlideApp, icons::Icon};
|
||||
use craft::menu::ribbon::{Gallery, GalleryFace, GalleryItem, GalleryMore, RibbonGroup, RibbonRow};
|
||||
use craft::ui::buttons::{Arrangement, Button, ToggleButton};
|
||||
use craft::ui::choice::Checkbox;
|
||||
use craft::ui::contract::{Bind, BodyCx, Entry, PopupKind, Props as _, Show as _, ShowContainer as _, Trigger};
|
||||
use craft::ui::list::ThumbAspect;
|
||||
use craft::ui::menu::{Menu, MenuItem};
|
||||
use craft::ui::pickers::Select;
|
||||
use craft::ui::primitives::ContentPainterCx;
|
||||
use craft::ui::text::NumberField;
|
||||
use craft::ui::tile_grid::{CaptionPlace, Tile, TileGrid};
|
||||
use egui::{CornerRadius, Rect, Stroke, Ui, pos2, vec2};
|
||||
use serde_json::{Value, json};
|
||||
|
||||
// ---------- Transitions ----------
|
||||
#[derive(Clone, PartialEq)]
|
||||
enum SoundChoice {
|
||||
None,
|
||||
Stop,
|
||||
Builtin(&'static str),
|
||||
Other,
|
||||
Stored,
|
||||
}
|
||||
|
||||
/// Render transition preview, gallery, options, sound, and timing controls for the current
|
||||
/// slide.
|
||||
// P3(ribbon-w8): rb.A4
|
||||
pub(super) fn transitions_base(app: &mut SlideApp, ui: &mut Ui) {
|
||||
/// Opens the current slide's transition controls.
|
||||
pub(crate) fn transitions(app: &mut SlideApp, row: &mut RibbonRow<'_>) {
|
||||
let cur = app.session.active().and_then(|d| d.current_slide().and_then(|s| s.transition.clone()));
|
||||
let kind = cur.as_ref().map(|t| t.kind.clone()).unwrap_or_else(|| "none".into());
|
||||
group(ui, |ui| {
|
||||
row.group(RibbonGroup::new("preview", "Preview", Icon::Preview.id().into()), |ui| {
|
||||
let playing = app.show.as_ref().is_some_and(|s| s.preview_only);
|
||||
let (resp, _) = widgets::big_button_ex(ui, Icon::Preview, "Preview", true, false, playing);
|
||||
if resp.on_hover_text("Play this slide's transition").clicked() {
|
||||
let output = ToggleButton::new("Preview", Bind::given(playing))
|
||||
.icon(Icon::Preview.id())
|
||||
.arrangement(Arrangement::Stacked)
|
||||
.tooltip("Play this slide's transition")
|
||||
.show(ui);
|
||||
// PLAN: ToggleButtonOutput exposes activation through clicks; EditResponse has no clicked method.
|
||||
if output.clicks > 0 {
|
||||
let to = app.session.active().map(|d| d.selection.slide).unwrap_or(0);
|
||||
app.start_show(to, true);
|
||||
let now = ui.input(|i| i.time);
|
||||
if let (Some(s), Some(d)) = (app.show.as_mut(), app.session.active()) {
|
||||
s.start_transition_preview(&d.doc, now);
|
||||
if let (Some(show), Some(doc)) = (app.show.as_mut(), app.session.active()) {
|
||||
show.start_transition_preview(&doc.doc, now);
|
||||
}
|
||||
}
|
||||
});
|
||||
group(ui, |ui| {
|
||||
let list = deckcraft_model::anim::TRANSITIONS;
|
||||
let shown: Vec<_> = list.iter().take(12).collect();
|
||||
let sel = shown.iter().position(|x| x.0 == kind);
|
||||
if let Some(i) = widgets::gallery(
|
||||
ui,
|
||||
shown.len(),
|
||||
vec2(54.0, 56.0),
|
||||
sel,
|
||||
|p, r, i| paint_transition_tile(p, r, shown.get(i).map(|x| (x.0, x.1)).unwrap_or(("", ""))),
|
||||
|i| shown.get(i).map(|x| x.1.to_string()).unwrap_or_default(),
|
||||
) && let Some(x) = shown.get(i)
|
||||
{
|
||||
run(app, "transition.set", json!({"kind": x.0}));
|
||||
row.group(RibbonGroup::new("transitions", "Transition to This Slide", Icon::EffectOptions.id().into()), |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
let list = deckcraft_model::anim::TRANSITIONS;
|
||||
let shown: Vec<_> = list.iter().take(12).collect();
|
||||
let cats = ["Subtle", "Exciting", "Dynamic Content"];
|
||||
let all: Vec<_> = cats.iter().flat_map(|cat| list.iter().filter(move |x| x.2 == *cat)).collect();
|
||||
let selected = shown.iter().position(|x| x.0 == kind);
|
||||
let more_selected = all.iter().position(|x| x.0 == kind);
|
||||
let sections: Vec<_> = cats.iter().map(|cat| (*cat, all.iter().filter(|x| x.2 == *cat).count())).collect();
|
||||
let groups = tile_groups(§ions);
|
||||
let paints: Vec<Box<dyn Fn(&ContentPainterCx, Rect) + '_>> = shown
|
||||
.iter()
|
||||
.map(|x| Box::new(move |cx: &ContentPainterCx, r| paint_transition_tile(cx, r, x.0)) as Box<dyn Fn(&ContentPainterCx, Rect)>)
|
||||
.collect();
|
||||
let items: Vec<_> = shown
|
||||
.iter()
|
||||
.zip(&paints)
|
||||
.enumerate()
|
||||
.map(|(i, (x, paint))| GalleryItem { key: i, label: x.1.into(), face: GalleryFace::Paint(&**paint) })
|
||||
.collect();
|
||||
let mut more_pick = None;
|
||||
let mut more = |ui: &mut Ui, cx: &mut BodyCx<'_>| {
|
||||
if let Some(i) = grid_pick(ui, TileGrid::new("Transitions").groups(&groups).card_columns(8), all.len(), more_selected, |i| {
|
||||
let x = all[i];
|
||||
Tile::new(x.1).thumb(ThumbAspect::new(1, 1), move |cx, r| paint_transition_tile(cx, r, x.0))
|
||||
}) {
|
||||
more_pick = Some(all[i].0.to_string());
|
||||
cx.request_close();
|
||||
}
|
||||
};
|
||||
let output = Gallery::new("Transitions", &items, selected.as_ref())
|
||||
.tiles(8, 4)
|
||||
.caption(CaptionPlace::Below)
|
||||
.more(GalleryMore::Body(&mut more))
|
||||
.show(ui);
|
||||
if let Some(kind) = output.picked.and_then(|i| shown.get(i).map(|x| x.0.to_string())).or(more_pick) {
|
||||
let _ = app.run("transition.set", json!({"kind": kind}));
|
||||
}
|
||||
let options = transition_effect_rows(&kind, cur.as_ref().map(|t| t.option.as_str()));
|
||||
let button = Button::new("Effect\nOptions")
|
||||
.icon(Icon::EffectOptions.id())
|
||||
.arrangement(Arrangement::Stacked)
|
||||
.enabled(!options.is_empty())
|
||||
.popup(PopupKind::Menu)
|
||||
.show(ui);
|
||||
Menu::new("Effect Options").opened_by(&button.response, Trigger::Click).show(ui, |ui, _| {
|
||||
for &(option, on) in &options {
|
||||
if MenuItem::new(deckcraft_model::anim::transition_option_label(&kind, option)).radio_mark(on).show(ui).ran {
|
||||
let _ = app.run("transition.options", json!({"option": option}));
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
row.group(RibbonGroup::new("sound", "Sound", Icon::Sound.id().into()), |ui| {
|
||||
let stop = cur.as_ref().is_some_and(|t| t.stop_sound);
|
||||
let has_sound = cur.as_ref().is_some_and(|t| t.sound.is_some());
|
||||
let name = cur
|
||||
.as_ref()
|
||||
.and_then(|t| t.sound)
|
||||
.and_then(|m| app.session.active().and_then(|d| d.doc.media(m).map(|item| item.name.trim_end_matches(".wav").to_string())))
|
||||
.unwrap_or_else(|| if stop { "[Stop Previous Sound]".into() } else { "[No Sound]".into() });
|
||||
let value = if has_sound {
|
||||
SoundChoice::Stored
|
||||
} else if stop {
|
||||
SoundChoice::Stop
|
||||
} else {
|
||||
SoundChoice::None
|
||||
};
|
||||
let mut entries =
|
||||
vec![Entry::new(SoundChoice::None, "[No Sound]"), Entry::new(SoundChoice::Stop, "[Stop Previous Sound]"), Entry::separator()];
|
||||
entries.extend(deckcraft_engine::sounds::BUILTIN.into_iter().map(|(id, label)| Entry::new(SoundChoice::Builtin(id), label)));
|
||||
entries.push(Entry::separator());
|
||||
let other = Entry::new(SoundChoice::Other, "Other Sound…").stepped(false);
|
||||
entries.push(if app.host.files().can_pick() { other } else { other.disabled_reason("Choosing a sound file needs the desktop app") });
|
||||
let output = Select::new("Sound:", Bind::given(value), &entries).placeholder(name).show(ui);
|
||||
let looping = cur.as_ref().is_some_and(|t| t.sound_loop);
|
||||
if let Some(choice) = output.events.committed() {
|
||||
match choice {
|
||||
SoundChoice::None => {
|
||||
let _ = app.run("transition.sound", json!({"none": true}));
|
||||
}
|
||||
SoundChoice::Stop => {
|
||||
let _ = app.run("transition.sound", json!({"stopPrevious": true}));
|
||||
}
|
||||
SoundChoice::Builtin(id) => {
|
||||
let _ = app.run("transition.sound", json!({"builtin": id, "loop": looping}));
|
||||
}
|
||||
SoundChoice::Other => app.pick_transition_sound(),
|
||||
SoundChoice::Stored => {}
|
||||
}
|
||||
}
|
||||
let more = widgets::drop_button(ui, "", vec2(14.0, 52.0), true);
|
||||
egui::Popup::menu(&more).width(480.0).show(|ui| {
|
||||
for cat in ["Subtle", "Exciting", "Dynamic Content"] {
|
||||
ui.label(egui::RichText::new(cat).font(theme::bold(12.0)));
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
for x in list.iter().filter(|x| x.2 == cat) {
|
||||
let (r, resp) = ui.allocate_exact_size(vec2(56.0, 58.0), Sense::click());
|
||||
if resp.hovered() || x.0 == kind {
|
||||
ui.painter().rect_filled(r, CornerRadius::same(4), Tokens::get(ui.ctx()).hover);
|
||||
}
|
||||
paint_transition_tile(ui.painter(), r.shrink(3.0), (x.0, x.1));
|
||||
if resp.clicked() {
|
||||
run(app, "transition.set", json!({"kind": x.0}));
|
||||
ui.close();
|
||||
}
|
||||
}
|
||||
});
|
||||
let output = Checkbox::new(Bind::given(looping)).label("Loop Until Next Sound").enabled(has_sound).show(ui);
|
||||
if let Some(looping) = output.events.committed() {
|
||||
let _ = app.run("transition.sound", json!({"loop": looping}));
|
||||
}
|
||||
});
|
||||
row.group(RibbonGroup::new("timing", "Timing", Icon::Duration.id().into()), |ui| {
|
||||
let duration = cur.as_ref().map(|t| t.duration_ms as f64 / 1000.0).unwrap_or(1.0);
|
||||
let output = NumberField::new("Duration:", Bind::given(Some(duration))).range(0.0..=f64::MAX).step(0.25).unit("s").show(ui);
|
||||
if let Some(seconds) = output.events.committed().and_then(|value| *value) {
|
||||
let _ = app.run("transition.timing", json!({"duration": (seconds * 1000.0).round() as u64}));
|
||||
}
|
||||
let click = cur.as_ref().is_none_or(|t| t.advance_on_click);
|
||||
let output = Checkbox::new(Bind::given(click)).label("On Mouse Click").show(ui);
|
||||
if let Some(click) = output.events.committed() {
|
||||
let _ = app.run("transition.timing", json!({"onClick": click}));
|
||||
}
|
||||
ui.horizontal(|ui| {
|
||||
let after = cur.as_ref().and_then(|t| t.advance_after_ms);
|
||||
let output = Checkbox::new(Bind::given(after.is_some())).label("After:").show(ui);
|
||||
if let Some(on) = output.events.committed() {
|
||||
let _ = app.run("transition.timing", json!({"after": if *on { json!(after.unwrap_or(0)) } else { Value::Null }}));
|
||||
}
|
||||
let output =
|
||||
NumberField::new("After", Bind::given(Some(after.unwrap_or(0) as f64 / 1000.0))).range(0.0..=f64::MAX).step(1.0).unit("s").show(ui);
|
||||
if let Some(seconds) = output.events.committed().and_then(|value| *value) {
|
||||
let _ = app.run("transition.timing", json!({"after": (seconds * 1000.0).round() as u64}));
|
||||
}
|
||||
});
|
||||
});
|
||||
group(ui, |ui| {
|
||||
let selected = cur.as_ref().map(|t| t.option.as_str());
|
||||
let rows = transition_effect_rows(&kind, selected);
|
||||
let r = big_button(ui, Icon::EffectOptions, "Effect\nOptions", !rows.is_empty());
|
||||
egui::Popup::menu(&r).show(|ui| {
|
||||
for &(o, on) in &rows {
|
||||
if ui.selectable_label(on, deckcraft_model::anim::transition_option_label(&kind, o)).clicked() {
|
||||
run(app, "transition.options", json!({"option": o}));
|
||||
ui.close();
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
group(ui, |ui| {
|
||||
// Sound in its own column, so the timing column keeps its three rows.
|
||||
rows(ui, |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
let field = ui.label("Sound:");
|
||||
let stop = cur.as_ref().is_some_and(|t| t.stop_sound);
|
||||
let name = cur
|
||||
.as_ref()
|
||||
.and_then(|t| t.sound)
|
||||
.and_then(|m| app.session.active().and_then(|d| d.doc.media(m).map(|i| i.name.trim_end_matches(".wav").to_string())))
|
||||
.unwrap_or_else(|| if stop { "[Stop Previous Sound]".into() } else { "[No Sound]".into() });
|
||||
// P3(ribbon-w8): earlier framework ComboBox removal (no contract id)
|
||||
let combo = egui::ComboBox::from_id_salt("transition_sound").width(140.0).selected_text(name).show_ui(ui, |ui| {
|
||||
let none = cur.as_ref().is_none_or(|t| t.sound.is_none() && !t.stop_sound);
|
||||
if ui.selectable_label(none, "[No Sound]").clicked() {
|
||||
run(app, "transition.sound", json!({"none": true}));
|
||||
}
|
||||
if ui.selectable_label(stop, "[Stop Previous Sound]").clicked() {
|
||||
run(app, "transition.sound", json!({"stopPrevious": true}));
|
||||
}
|
||||
ui.separator();
|
||||
for (id, label) in deckcraft_engine::sounds::BUILTIN {
|
||||
if ui.button(label).clicked() {
|
||||
let lp = cur.as_ref().is_some_and(|t| t.sound_loop);
|
||||
run(app, "transition.sound", json!({"builtin": id, "loop": lp}));
|
||||
}
|
||||
}
|
||||
ui.separator();
|
||||
let can_pick = app.services.pick_open.is_some();
|
||||
let r = ui.add_enabled(can_pick, egui::Button::new("Other Sound…"));
|
||||
if r.clicked() {
|
||||
app.pick_transition_sound();
|
||||
}
|
||||
r.on_disabled_hover_text("Choosing a sound file needs the desktop app");
|
||||
ui.separator();
|
||||
let has = cur.as_ref().is_some_and(|t| t.sound.is_some());
|
||||
let mut lp = cur.as_ref().is_some_and(|t| t.sound_loop);
|
||||
if ui.add_enabled(has, egui::Checkbox::new(&mut lp, "Loop Until Next Sound")).changed() {
|
||||
run(app, "transition.sound", json!({"loop": lp}));
|
||||
}
|
||||
});
|
||||
let _ = combo.response.labelled_by(field.id);
|
||||
});
|
||||
});
|
||||
rows(ui, |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Duration:");
|
||||
let d = cur.as_ref().map(|t| t.duration_ms as f64 / 1000.0).unwrap_or(1.0);
|
||||
if let Some(v) = widgets::spinner(ui, "tdur", "Duration", d, 0.25, "", 46.0) {
|
||||
run(app, "transition.timing", json!({"duration": (v.max(0.0) * 1000.0).round() as u64}));
|
||||
}
|
||||
});
|
||||
ui.horizontal(|ui| {
|
||||
let mut click = cur.as_ref().is_none_or(|t| t.advance_on_click);
|
||||
if ui.checkbox(&mut click, "On Mouse Click").changed() {
|
||||
run(app, "transition.timing", json!({"onClick": click}));
|
||||
}
|
||||
});
|
||||
ui.horizontal(|ui| {
|
||||
let after = cur.as_ref().and_then(|t| t.advance_after_ms);
|
||||
let mut on = after.is_some();
|
||||
if ui.checkbox(&mut on, "After:").changed() {
|
||||
run(app, "transition.timing", json!({"after": if on { json!(after.unwrap_or(0)) } else { Value::Null }}));
|
||||
}
|
||||
if let Some(v) = widgets::spinner(ui, "tafter", "After", after.unwrap_or(0) as f64 / 1000.0, 1.0, "", 46.0) {
|
||||
run(app, "transition.timing", json!({"after": (v.max(0.0) * 1000.0).round() as u64}));
|
||||
}
|
||||
});
|
||||
});
|
||||
big(app, ui, Icon::ApplyToAll, "Apply\nTo All", "transition.applyAll", json!({}));
|
||||
row.group(RibbonGroup::new("apply", "Apply To All", Icon::ApplyToAll.id().into()), |ui| {
|
||||
Button::command("transition.applyAll").label("Apply\nTo All").icon(Icon::ApplyToAll.id()).arrangement(Arrangement::Stacked).show(ui);
|
||||
});
|
||||
}
|
||||
|
||||
pub(super) fn option_label(o: &str) -> String {
|
||||
match o {
|
||||
"l" => "From Left".into(),
|
||||
"r" => "From Right".into(),
|
||||
"u" => "From Top".into(),
|
||||
"d" => "From Bottom".into(),
|
||||
"horz" => "Horizontal".into(),
|
||||
"vert" => "Vertical".into(),
|
||||
"in" => "In".into(),
|
||||
"out" => "Out".into(),
|
||||
other => {
|
||||
let mut s = String::new();
|
||||
for (i, c) in other.chars().enumerate() {
|
||||
if i == 0 {
|
||||
s.extend(c.to_uppercase());
|
||||
} else if c.is_uppercase() {
|
||||
s.push(' ');
|
||||
s.push(c);
|
||||
} else {
|
||||
s.push(c);
|
||||
}
|
||||
}
|
||||
s
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn paint_transition_tile(p: &egui::Painter, r: Rect, (id, label): (&str, &str)) {
|
||||
let t = Tokens::get(p.ctx());
|
||||
let pic = Rect::from_min_size(r.min + vec2(4.0, 2.0), vec2(r.width() - 8.0, r.height() - 18.0));
|
||||
let blue = Color32::from_rgb(0x2E, 0x6F, 0xD8);
|
||||
let light = Color32::from_rgb(0xBF, 0xD4, 0xF5);
|
||||
p.rect_filled(pic, CornerRadius::same(2), light);
|
||||
fn paint_transition_tile(cx: &ContentPainterCx<'_>, r: Rect, id: &str) {
|
||||
let p = &cx.painter;
|
||||
let (accent, well, sunken, border, on_accent) = cx.with_draw(|draw| {
|
||||
(
|
||||
draw.role(|c| c.accent.solid).egui(),
|
||||
draw.role(|c| c.state.selected).egui(),
|
||||
draw.role(|c| c.surface.sunken).egui(),
|
||||
draw.role(|c| c.line.border).egui(),
|
||||
draw.role(|c| c.text.on_accent).egui(),
|
||||
)
|
||||
});
|
||||
let pic = Rect::from_min_size(r.min + vec2(4.0, 2.0), vec2(r.width() - 8.0, r.height() - 4.0));
|
||||
p.rect_filled(pic, CornerRadius::same(2), well);
|
||||
match id {
|
||||
"none" => {
|
||||
p.rect_filled(pic, CornerRadius::same(2), Color32::from_rgb(0xE6, 0xEC, 0xF5));
|
||||
p.rect_filled(pic, CornerRadius::same(2), sunken);
|
||||
}
|
||||
"fade" | "dissolve" | "flash" => {
|
||||
p.rect_filled(pic, CornerRadius::same(2), blue.gamma_multiply(0.5));
|
||||
p.rect_filled(pic, CornerRadius::same(2), accent.gamma_multiply(0.5));
|
||||
}
|
||||
"push" | "cover" | "uncover" | "pan" | "conveyor" => {
|
||||
p.rect_filled(Rect::from_min_max(pos2(pic.center().x, pic.min.y), pic.max), CornerRadius::same(2), blue);
|
||||
p.arrow(pos2(pic.center().x + 10.0, pic.center().y), vec2(-12.0, 0.0), Stroke::new(1.5, Color32::WHITE));
|
||||
p.rect_filled(Rect::from_min_max(pos2(pic.center().x, pic.min.y), pic.max), CornerRadius::same(2), accent);
|
||||
p.arrow(pos2(pic.center().x + 10.0, pic.center().y), vec2(-12.0, 0.0), Stroke::new(1.5, on_accent));
|
||||
}
|
||||
"wipe" | "reveal" => {
|
||||
p.rect_filled(Rect::from_min_max(pic.min, pos2(pic.center().x, pic.max.y)), CornerRadius::same(2), blue);
|
||||
p.rect_filled(Rect::from_min_max(pic.min, pos2(pic.center().x, pic.max.y)), CornerRadius::same(2), accent);
|
||||
}
|
||||
"split" | "doors" | "window" | "curtains" => {
|
||||
p.rect_filled(
|
||||
Rect::from_min_max(pos2(pic.min.x + pic.width() * 0.3, pic.min.y), pos2(pic.max.x - pic.width() * 0.3, pic.max.y)),
|
||||
CornerRadius::ZERO,
|
||||
blue,
|
||||
accent,
|
||||
);
|
||||
}
|
||||
"randomBar" | "blinds" | "comb" | "shred" => {
|
||||
for k in 0..5 {
|
||||
let x = pic.min.x + k as f32 * pic.width() / 5.0;
|
||||
p.rect_filled(Rect::from_min_size(pos2(x, pic.min.y), vec2(pic.width() / 10.0, pic.height())), CornerRadius::ZERO, blue);
|
||||
p.rect_filled(Rect::from_min_size(pos2(x, pic.min.y), vec2(pic.width() / 10.0, pic.height())), CornerRadius::ZERO, accent);
|
||||
}
|
||||
}
|
||||
"checker" | "honeycomb" | "glitter" | "fracture" => {
|
||||
@@ -210,19 +217,19 @@ pub fn paint_transition_tile(p: &egui::Painter, r: Rect, (id, label): (&str, &st
|
||||
if k % 2 == (k / 4) % 2 {
|
||||
let x = pic.min.x + (k % 4) as f32 * pic.width() / 4.0;
|
||||
let y = pic.min.y + (k / 4) as f32 * pic.height() / 3.0;
|
||||
p.rect_filled(Rect::from_min_size(pos2(x, y), vec2(pic.width() / 4.0, pic.height() / 3.0)), CornerRadius::ZERO, blue);
|
||||
p.rect_filled(Rect::from_min_size(pos2(x, y), vec2(pic.width() / 4.0, pic.height() / 3.0)), CornerRadius::ZERO, accent);
|
||||
}
|
||||
}
|
||||
}
|
||||
"shape" | "zoom" | "ripple" | "vortex" | "clock" => {
|
||||
p.circle_filled(pic.center(), pic.height() * 0.38, blue);
|
||||
p.circle_filled(pic.center(), pic.height() * 0.38, accent);
|
||||
}
|
||||
"morph" => {
|
||||
p.circle_filled(pos2(pic.min.x + pic.width() * 0.3, pic.center().y), pic.height() * 0.25, blue);
|
||||
p.circle_filled(pos2(pic.min.x + pic.width() * 0.3, pic.center().y), pic.height() * 0.25, accent);
|
||||
p.rect_filled(
|
||||
Rect::from_center_size(pos2(pic.max.x - pic.width() * 0.3, pic.center().y), vec2(pic.height() * 0.45, pic.height() * 0.45)),
|
||||
CornerRadius::same(2),
|
||||
blue.gamma_multiply(0.7),
|
||||
accent.gamma_multiply(0.7),
|
||||
);
|
||||
}
|
||||
_ => {
|
||||
@@ -233,11 +240,10 @@ pub fn paint_transition_tile(p: &egui::Painter, r: Rect, (id, label): (&str, &st
|
||||
pos2(pic.max.x - 3.0, pic.max.y - 1.0),
|
||||
pos2(pic.min.x + 6.0, pic.max.y - 4.0),
|
||||
];
|
||||
p.add(egui::Shape::convex_polygon(pts, blue, Stroke::NONE));
|
||||
p.add(egui::Shape::convex_polygon(pts, accent, Stroke::NONE));
|
||||
}
|
||||
}
|
||||
p.rect_stroke(pic, CornerRadius::same(2), Stroke::new(1.0, Color32::from_rgb(0x9B, 0xB4, 0xDB)), egui::StrokeKind::Inside);
|
||||
p.text(pos2(r.center().x, r.max.y - 7.0), Align2::CENTER_CENTER, label, theme::font(10.0), t.text);
|
||||
p.rect_stroke(pic, CornerRadius::same(2), Stroke::new(1.0, border), egui::StrokeKind::Inside);
|
||||
}
|
||||
|
||||
/// One row of Transitions ▸ Effect Options: the stored option and whether it is the current one.
|
||||
@@ -246,9 +252,3 @@ pub(super) fn transition_effect_rows(kind: &str, current: Option<&str>) -> Vec<(
|
||||
marked_options(opts, current)
|
||||
}
|
||||
|
||||
/// Opens this tab's ribbon groups.
|
||||
#[allow(dead_code)] // P3(ribbon-w8): rb.A4
|
||||
pub(crate) fn transitions(app: &mut SlideApp, row: &mut craft::menu::ribbon::RibbonRow<'_>) {
|
||||
let _ = (app, row);
|
||||
todo!("rb.A4")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user