Merge look-fix-ribbon-row app work

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Dylan M. Taylor
2026-11-28 18:44:23 +00:00
co-authored by Claude Opus 5.5
7 changed files with 73 additions and 29 deletions
+2 -2
View File
@@ -1,6 +1,6 @@
//! Title bar, ribbon tabs and the ribbon card with every tab's groups.
use craft::menu::ribbon::{RibbonBody, RibbonLook};
use craft::menu::ribbon::{RibbonBody, RibbonFit, RibbonLook};
use craft::menu::{Ribbon, RibbonMenuRequest, RibbonTab};
use craft::ui::contract::{Bind, BodyCx, Show as _};
use craft::ui::menu::MenuItem;
@@ -198,7 +198,7 @@ pub fn show(app: &mut SlideApp, ui: &mut Ui) {
let mut menu = |ui: &mut Ui, request: &RibbonMenuRequest, cx: &mut BodyCx<'_>| qat_menu(ui, request, cx, &qat_items, &mut pick);
let output = Ribbon::new("Ribbon", &tabs, Bind::given(current))
.id(ribbon_id())
.look(RibbonLook::new(30, 17).tabs(3).row(22).arrow(10).one_line(8).body(RibbonBody::Card).untitled())
.look(RibbonLook::new(30, 17).tabs(3).row(22).arrow(10).one_line(8).body(RibbonBody::Card).untitled().fit(RibbonFit::Scroll))
.minimised(Bind::bound(&mut collapsed))
.context_menu(&mut menu)
.show(ui, |row, key| match key {
+40 -16
View File
@@ -4,11 +4,13 @@ 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::form::Field;
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::layout_components::Stack;
use craft::ui::text::{NumberField, StepArrows};
use craft::ui::tile_grid::{CaptionPlace, Tile, TileGrid};
use deckcraft_model::AnimClass;
use egui::{Rect, Ui, pos2, vec2};
@@ -83,7 +85,9 @@ pub(crate) fn animations(app: &mut SlideApp, row: &mut RibbonRow<'_>) {
}
};
let output = Gallery::new("Animations", &items, selected.as_ref())
.tiles(8, 4)
.tiles(13, 4)
// Tiles as wide as the old ribbon's (50 by 56 points), so the effect names under them read whole.
.aspect(ThumbAspect::new(7, 5))
.caption(CaptionPlace::Below)
.enabled(has_sel)
.more(GalleryMore::Body(&mut more))
@@ -166,7 +170,7 @@ pub(crate) fn animations(app: &mut SlideApp, row: &mut RibbonRow<'_>) {
super::home::painter_toggle(
app,
ui,
Icon::AnimationPainter,
(Icon::AnimationPainter, Arrangement::Stacked),
"Animation\nPainter",
"animation.painter",
armed,
@@ -189,22 +193,42 @@ pub(crate) fn animations(app: &mut SlideApp, row: &mut RibbonRow<'_>) {
})
.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}));
}
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}));
}
}
// Start, Duration and Delay stand in three rows, as the old ribbon stacked them.
Stack::new().show(ui, |ui, _| timing(app, ui, cur.as_ref(), &starts, &start));
});
}
/// The Timing group's labelled Start, Duration and Delay fields over the current animation `cur`.
fn timing(app: &mut SlideApp, ui: &mut Ui, cur: Option<&deckcraft_model::Animation>, starts: &[Entry<String>], start: &str) {
let mut field = Field::new("Start:")
.id_salt("start")
.show(ui, |ui, _| Select::new("Start:", Bind::given(start.to_owned()), starts).enabled(cur.is_some()).show(ui).events.committed().cloned());
if let Some(start) = field.settle(|_, value| value.take()).flatten() {
let _ = app.run("animation.timing", json!({"start": start}));
}
for (label, key, seconds) in [
("Duration:", "duration", cur.map(|c| c.duration_ms as f64 / 1000.0).unwrap_or(0.5)),
("Delay:", "delay", cur.map(|c| c.delay_ms as f64 / 1000.0).unwrap_or(0.0)),
] {
let mut field = Field::new(label).id_salt(key).show(ui, |ui, _| {
NumberField::new(label, Bind::given(Some(seconds)))
.range(0.0..=f64::MAX)
.step(0.25)
.unit("s")
.step_arrows(StepArrows::Trailing)
.enabled(cur.is_some())
.show(ui)
.events
.committed()
.copied()
.flatten()
});
if let Some(seconds) = field.settle(|_, value| value.take()).flatten() {
let _ = app.run("animation.timing", json!({(key): (seconds * 1000.0).round() as u64}));
}
}
}
fn paint_anim_tile(cx: &ContentPainterCx<'_>, r: Rect, class: AnimClass) {
let icon = match class {
AnimClass::Entrance => Icon::AnimEntrance,
+14 -4
View File
@@ -4,12 +4,13 @@ use craft::ui::buttons::{Arrangement, Button, SplitButton, SplitMenu, SplitMenuE
use craft::ui::contract::{Bind, BodyCx, Entry, PopupKind, Props as _, Show as _, ShowContainer as _, Trigger};
use craft::ui::controls::disclosure::DisclosureGlyph;
use craft::ui::display::Divider;
use craft::ui::form::Field;
use craft::ui::layout_components::Stack;
use craft::ui::menu::{Menu, MenuItem};
use craft::ui::primitives::IconSpec;
use craft::ui::runtime::commands::{self, CommandRef};
use craft::ui::runtime::env::{LengthUnits, UnitKind};
use craft::ui::text::NumberField;
use craft::ui::text::{NumberField, StepArrows};
use deckcraft_model::ShapeId;
const GROUP: [(&str, &str, Icon); 3] =
@@ -173,9 +174,18 @@ pub(crate) fn size_group(app: &mut SlideApp, row: &mut RibbonRow<'_>) {
let lengths = LengthUnits::new(UnitKind::Points, shown, 72.0);
row.group(RibbonGroup::new("size", "Size", IconSpec::from(Icon::SlideSize.id())), |ui| {
Stack::new().show(ui, |ui, _| {
for (label, param, initial) in [("Height", "h", bx.map(|x| x.h)), ("Width", "w", bx.map(|x| x.w))] {
let out = NumberField::length(label, Bind::given(initial), lengths).enabled(bx.is_some()).show(ui);
if let Some(value) = out.events.committed().and_then(|value| *value) {
for (label, param, initial) in [("Height:", "h", bx.map(|x| x.h)), ("Width:", "w", bx.map(|x| x.w))] {
let mut field = Field::new(label).id_salt(param).show(ui, |ui, _| {
NumberField::length(label, Bind::given(initial), lengths)
.step_arrows(StepArrows::Trailing)
.enabled(bx.is_some())
.show(ui)
.events
.committed()
.copied()
.flatten()
});
if let Some(value) = field.settle(|_, value| value.take()).flatten() {
let _ = app.run("shape.resize", json!({(param): value.max(0.0)}));
}
}
+3 -2
View File
@@ -29,9 +29,10 @@ const SHAPE_FILL_KEY: &str = "ribbon.home.shapeFill";
const SHAPE_OUTLINE_KEY: &str = "ribbon.home.shapeOutline";
/// Shows a painter whose single click toggles and whose double click keeps it armed.
pub(super) fn painter_toggle(app: &mut SlideApp, ui: &mut Ui, icon: Icon, label: &str, cmd: &str, armed: bool, tooltip: &str) {
pub(super) fn painter_toggle(app: &mut SlideApp, ui: &mut Ui, (icon, arrangement): (Icon, Arrangement), label: &str, cmd: &str, armed: bool, tooltip: &str) {
let output = ToggleButton::new(label.to_owned(), Bind::given(armed))
.icon(icon.id())
.arrangement(arrangement)
.enabled(commands::resolve(ui.ctx(), cmd).enabled)
.tooltip(TooltipSpec::new(tooltip.to_owned()))
.show(ui);
@@ -65,7 +66,7 @@ fn clipboard(app: &mut SlideApp, ui: &mut Ui) {
Button::command("edit.copy").label(Word::plain("Copy")).icon(Icon::Copy.id()).show(ui);
let armed = app.session.painter.is_some();
let tooltip = Env::of(ui).view().resolve(&Word::plain("Format Painter (double-click to keep it on)").into());
painter_toggle(app, ui, Icon::FormatPainter, "Format", "format.painter", armed, tooltip.as_str());
painter_toggle(app, ui, (Icon::FormatPainter, Arrangement::Inline), "Format","format.painter", armed, tooltip.as_str());
});
}
+8 -3
View File
@@ -4,7 +4,7 @@ use craft::keymap::CommandRef;
use craft::theme::Variant;
use craft::ui::buttons::{Button, IconButton, ToggleButton};
use craft::ui::contract::{BodyCx, Props as _, Show as _};
use craft::ui::shell::{Title, TitleBar};
use craft::ui::shell::{Title, TitleBar, UnsavedMark};
use serde_json::json;
use crate::SlideApp;
@@ -14,15 +14,17 @@ use crate::icons::Icon;
pub fn title_bar(app: &mut SlideApp, ui: &mut egui::Ui, _cx: &mut BodyCx<'_>) {
let text = app.session.active().map(|doc| doc.title().to_string()).unwrap_or_else(|| "DeckCraft".into());
let dirty = app.session.active().is_some_and(|doc| doc.is_dirty());
let title = if dirty { Title::unsaved(text) } else { Title::new(text) };
let title = if dirty { Title::unsaved(text).mark(UnsavedMark::Edited) } else { Title::new(text) };
let dark = app.ui.brightness == crate::state::Brightness::Dark;
let mut switch_appearance = false;
// The bar under the OS frame still carries the document's title, centred.
TitleBar::new().title_when_native().show_titled(
ui,
title,
|ui, _| super::qat::bar(app, ui),
|ui, _| {
IconButton::command(if dark { Icon::Sparkle } else { Icon::Palette }.id(), "view.dark").label("Light/Dark appearance").show(ui);
// The icon names the appearance, so the button rests flat in both, as the old title bar's did: no on plate.
switch_appearance = IconButton::new(if dark { Icon::Sparkle } else { Icon::Palette }.id()).label("Light/Dark appearance").show(ui).clicked();
ToggleButton::command(CommandRef::with_params("view.pane", json!({"pane": "comments", "toggle": true})))
.label("Comments")
.icon(Icon::CommentsBubble.id())
@@ -32,4 +34,7 @@ pub fn title_bar(app: &mut SlideApp, ui: &mut egui::Ui, _cx: &mut BodyCx<'_>) {
IconButton::command(Icon::Search.id(), "app.palette").label("Search commands").show(ui);
},
);
if switch_appearance {
let _ = app.run("view.dark", json!({}));
}
}
+1 -1
View File
@@ -74,7 +74,7 @@ pub fn status_bar(app: &mut SlideApp, ui: &mut Ui) {
|scope| {
scope.values.set(LinkLook::Plain);
},
|ui| Link::new(language.clone()).tooltip(words.language.clone()).show(ui),
|ui| Link::new(language.clone()).shade(Shade::Muted).tooltip(words.language.clone()).show(ui),
);
open_language |= link.clicked();
if let Some(message) = &message {
+5 -1
View File
@@ -273,10 +273,14 @@ pub fn app_sizes() -> std::sync::Arc<craft::theme::AppSizes> {
SIZES.clone()
}
/// The app's root values before the frame's own: [`RootEnv`](craft::ui::runtime::env::RootEnv) with DeckCraft's sizes.
/// The app's root values before the frame's own: [`RootEnv`](craft::ui::runtime::env::RootEnv) with DeckCraft's sizes,
/// and number fields that write their number and unit as one run at their start, to two decimals ("1.39 in", "0.75 pt")
/// and whole percents, as the old app's fields did.
pub fn root_env() -> craft::ui::runtime::env::RootEnv {
let mut root = craft::ui::runtime::env::RootEnv::new();
root.sizes = app_sizes();
root.values.set(craft::ui::text::NumberLook::Inline);
root.values.set(craft::ui::text::NumberPrecision::Hundredths);
root
}