Compare commits

..
Author SHA1 Message Date
Dylan M. Taylor 2c135484c1 Drop unused test-oracle GUID reexports 2026-11-17 11:50:07 -05:00
Dylan M. Taylor 352b1ee170 Pin table-style writer to merged shared implementation 2026-11-17 11:31:14 -05:00
Dylan M. Taylor 82fddc8ffd Use shared DrawingML table style XML writer
Preserve the former writer as a test-only byte oracle, including the original Brandon Thomas and Nikita Rakitin implementation history. Keep app XML admission and all existing table tests unchanged.
2026-11-17 08:37:55 -05:00
Dylan M. Taylor 1629e4d953 Tables: cap the grid and merge area before edits allocate or walk them (#1742) 2026-11-17 08:13:56 -05:00
Luis 497582406d Gradient stops: double-clicking a stop opens its colour menu (#2175) (#2196)
Double-clicking a stop marker in the Format pane's gradient editor did nothing. It now selects the stop and opens the colour menu of the selected stop, as in PowerPoint. The menu button is also named for screen readers.
2026-11-17 08:36:53 +00:00
Luis e1ca71495c Slide show: a slide's animations wait for its transition (#2089) (#2197)
A first step that starts With or After Previous began with the slide, so its effects played under the transition. Its clock now starts when the transition has finished, as in PowerPoint. Slides without a transition, and Show without animation, start the step at once as before.
2026-11-17 08:35:55 +00:00
8 changed files with 355 additions and 183 deletions
Generated
+25 -3
View File
@@ -891,6 +891,17 @@ dependencies = [
"serde",
]
[[package]]
name = "craft-drawingml"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=cff5af869dbf6926801c9ac63a927d155202ba3b#cff5af869dbf6926801c9ac63a927d155202ba3b"
dependencies = [
"craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=cff5af869dbf6926801c9ac63a927d155202ba3b)",
"kurbo",
"log",
"serde",
]
[[package]]
name = "craft-fonts-build"
version = "0.1.0"
@@ -1064,6 +1075,16 @@ dependencies = [
"thiserror 2.0.21",
]
[[package]]
name = "craft-xml"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=cff5af869dbf6926801c9ac63a927d155202ba3b#cff5af869dbf6926801c9ac63a927d155202ba3b"
dependencies = [
"quick-xml 0.41.0",
"serde",
"thiserror 2.0.21",
]
[[package]]
name = "craft-xml"
version = "0.1.0"
@@ -1209,7 +1230,7 @@ dependencies = [
name = "deckcraft-color"
version = "0.19.0"
dependencies = [
"craft-drawingml",
"craft-drawingml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=44d83fa8f635333dcb3c231f87381387a1f5631b)",
]
[[package]]
@@ -1266,7 +1287,7 @@ dependencies = [
name = "deckcraft-geom"
version = "0.19.0"
dependencies = [
"craft-drawingml",
"craft-drawingml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=44d83fa8f635333dcb3c231f87381387a1f5631b)",
"kurbo",
"serde",
]
@@ -1329,7 +1350,8 @@ name = "deckcraft-pptx"
version = "0.19.0"
dependencies = [
"craft-cfb",
"craft-drawingml",
"craft-drawingml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=44d83fa8f635333dcb3c231f87381387a1f5631b)",
"craft-drawingml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=cff5af869dbf6926801c9ac63a927d155202ba3b)",
"craft-opc",
"craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=ea24422ae9859dc5da398d0462bc87f8e02e0d10)",
"deckcraft-color",
+2
View File
@@ -18,6 +18,8 @@ craft-cfb = { git = "https://github.com/storytold/craft-libs", rev = "ea24422ae9
# XML writer primitives; parser admission and OOXML policy stay app-local.
craft-xml = { git = "https://github.com/storytold/craft-libs", rev = "ea24422ae9859dc5da398d0462bc87f8e02e0d10", version = "0.1.0" }
# DrawingML colours, themes and text (craft-libs#778, #792): the model DeckCraft reads and writes.
# Isolated table XML writer; existing DrawingML model/readers keep their revision.
craft-drawingml-table = { package = "craft-drawingml", git = "https://github.com/storytold/craft-libs", rev = "cff5af869dbf6926801c9ac63a927d155202ba3b" }
craft-drawingml = { git = "https://github.com/storytold/craft-libs", rev = "44d83fa8f635333dcb3c231f87381387a1f5631b", version = "0.1.0" }
# internal
deckcraft-geom = { path = "crates/geom" }
+1
View File
@@ -13,6 +13,7 @@ craft-opc.workspace = true
craft-xml.workspace = true
craft-cfb.workspace = true
craft-drawingml.workspace = true
craft-drawingml-table.workspace = true
deckcraft-model = { workspace = true }
deckcraft-geom = { workspace = true }
deckcraft-color = { workspace = true }
+42 -177
View File
@@ -1,190 +1,55 @@
//! Table styles: our style ids ↔ table style GUIDs, and `tableStyles.xml` definitions for the
//! styles we write (generated from theme accents, matching how DeckCraft draws them).
use crate::opc::NS_A;
use crate::xml::{A, W};
// Keep file-format identifiers in the shared DrawingML implementation. The local
// writer below still owns DeckCraft's table style definitions and XML policy.
//! Table style XML uses the shared writer; app XML admission remains unchanged.
pub use craft_drawingml::table::styles::{guid, guid_for_style, is_own_guid, style_from_guid};
pub fn table_styles_xml(used: &[String], defs: &[deckcraft_model::table::TableStyleDef]) -> Vec<u8> {
craft_drawingml_table::table::styles::table_styles_xml_with(used, defs.iter().map(|d| (d.id.as_str(), d.raw.as_str())), "DeckCraft", |raw| {
crate::xml::parse(raw.as_bytes()).is_ok_and(|x| x.root.is("tblStyle"))
})
}
#[cfg(test)]
#[path = "tables_legacy.rs"]
mod legacy;
#[cfg(test)]
fn own_guid(style: &str) -> String {
guid(&format!("deckcraft-table-style:{style}"))
}
fn clr(w: &mut W, slot: &str, mods: &[(&str, i32)]) {
if mods.is_empty() {
w.val("a:schemeClr", slot);
return;
}
w.open("a:schemeClr", A::new().a("val", slot));
for (n, v) in mods {
w.val(n, v);
}
w.close("a:schemeClr");
}
fn solid(w: &mut W, slot: &str, mods: &[(&str, i32)]) {
w.open0("a:fill");
w.open0("a:solidFill");
clr(w, slot, mods);
w.close("a:solidFill");
w.close("a:fill");
}
fn borders(w: &mut W, b: Option<(&str, &[(&str, i32)], i32)>) {
w.open0("a:tcBdr");
if let Some((slot, mods, width)) = b {
for side in ["a:left", "a:right", "a:top", "a:bottom", "a:insideH", "a:insideV"] {
w.open0(side);
w.open("a:ln", A::new().a("w", width).a("cmpd", "sng"));
w.open0("a:solidFill");
clr(w, slot, mods);
w.close("a:solidFill");
w.close("a:ln");
w.close(side);
}
}
w.close("a:tcBdr");
}
fn txt(w: &mut W, bold: bool, color: Option<&str>) {
w.open("a:tcTxStyle", A::new().o("b", bold.then_some("on")));
w.open("a:fontRef", A::new().a("idx", "minor"));
w.val("a:prstClr", "black");
w.close("a:fontRef");
match color {
Some(c) => w.val("a:schemeClr", c),
None => w.val("a:schemeClr", "dk1"),
}
w.close("a:tcTxStyle");
}
/// Write one `a:tblStyle` for our style id.
fn style_def(w: &mut W, id: &str, name: &str) {
let kind = id.split('-').next().unwrap_or("medium2");
let acc = match id.rsplit('-').next().unwrap_or("accent1") {
"tx1" => "dk1",
a if a.starts_with("accent") => a,
_ => "accent1",
};
let acc: &str = acc;
w.open("a:tblStyle", A::new().a("styleId", own_guid(id)).a("styleName", name));
let part =
|w: &mut W, tag: &str, bold: bool, text: Option<&str>, fill: Option<(&str, &[(&str, i32)])>, bdr: Option<(&str, &[(&str, i32)], i32)>| {
w.open0(tag);
if bold || text.is_some() {
txt(w, bold, text);
}
w.open0("a:tcStyle");
borders(w, bdr);
if let Some((s, m)) = fill {
solid(w, s, m);
}
w.close("a:tcStyle");
w.close(tag);
};
match kind {
"grid" => {
part(w, "a:wholeTbl", false, Some("dk1"), None, Some(("dk1", &[], 9525)));
}
"light1" => {
part(w, "a:wholeTbl", false, Some("dk1"), None, None);
part(w, "a:band1H", false, None, Some((acc, &[("a:tint", 20000)])), None);
part(w, "a:band1V", false, None, Some((acc, &[("a:tint", 20000)])), None);
part(w, "a:lastCol", true, None, None, None);
part(w, "a:firstCol", true, None, None, None);
part(w, "a:lastRow", true, None, None, None);
part(w, "a:firstRow", true, None, None, Some((acc, &[], 12700)));
}
"light2" => {
part(w, "a:wholeTbl", false, Some("dk1"), None, Some((acc, &[], 12700)));
// Schema order: … lastCol, firstCol, lastRow, …, firstRow.
part(w, "a:firstCol", true, None, None, None);
part(w, "a:lastRow", true, None, None, None);
part(w, "a:firstRow", true, Some("lt1"), Some((acc, &[])), Some((acc, &[], 12700)));
}
"dark1" => {
part(w, "a:wholeTbl", false, Some("lt1"), Some((acc, &[("a:shade", 75000)])), Some(("lt1", &[], 12700)));
part(w, "a:band1H", false, None, Some((acc, &[("a:shade", 60000)])), None);
part(w, "a:band1V", false, None, Some((acc, &[("a:shade", 60000)])), None);
part(w, "a:firstCol", true, None, None, None);
part(w, "a:lastRow", true, None, None, None);
part(w, "a:firstRow", true, Some("lt1"), Some(("dk1", &[])), None);
}
"medium4" => {
part(w, "a:wholeTbl", false, Some("dk1"), Some((acc, &[("a:tint", 20000)])), Some((acc, &[], 9525)));
part(w, "a:band1H", false, None, Some((acc, &[("a:tint", 40000)])), None);
part(w, "a:band1V", false, None, Some((acc, &[("a:tint", 40000)])), None);
part(w, "a:lastCol", true, None, None, None);
part(w, "a:firstCol", true, None, None, None);
part(w, "a:lastRow", true, None, None, None);
part(w, "a:firstRow", true, None, Some((acc, &[("a:tint", 40000)])), None);
}
_ => {
// medium2
part(w, "a:wholeTbl", false, Some("dk1"), Some((acc, &[("a:tint", 20000)])), Some(("lt1", &[], 12700)));
part(w, "a:band1H", false, None, Some((acc, &[("a:tint", 40000)])), None);
part(w, "a:band1V", false, None, Some((acc, &[("a:tint", 40000)])), None);
part(w, "a:lastCol", true, Some("lt1"), Some((acc, &[])), None);
part(w, "a:firstCol", true, Some("lt1"), Some((acc, &[])), None);
part(w, "a:lastRow", true, Some("lt1"), Some((acc, &[])), None);
part(w, "a:firstRow", true, Some("lt1"), Some((acc, &[])), None);
}
}
w.close("a:tblStyle");
}
/// `ppt/tableStyles.xml` with definitions for the styles in `used`: ours, generated, and those the
/// opened file defined (`defs`), written back as they were read.
pub fn table_styles_xml(used: &[String], defs: &[deckcraft_model::table::TableStyleDef]) -> Vec<u8> {
let mut w = W::new();
w.open("a:tblStyleLst", A::new().a("xmlns:a", NS_A).a("def", "{5C22544A-7EE6-4342-B048-85BDC9FD1C3A}"));
let names = deckcraft_model::table::table_styles();
// Indexes instead of scans: written ids (as given and ASCII lower-case), and the file's
// definitions by lower-case id (the first wins).
let mut done: std::collections::HashSet<&str> = std::collections::HashSet::new();
let mut done_lower: std::collections::HashSet<String> = std::collections::HashSet::new();
let mut def_of: std::collections::HashMap<String, &deckcraft_model::table::TableStyleDef> = std::collections::HashMap::new();
for d in defs {
def_of.entry(d.id.to_ascii_lowercase()).or_insert(d);
}
for s in used {
if !done.insert(s.as_str()) {
continue;
}
done_lower.insert(s.to_ascii_lowercase());
if let Some(d) = def_of.get(&s.to_ascii_lowercase())
&& crate::xml::parse(d.raw.as_bytes()).is_ok_and(|x| x.root.is("tblStyle"))
{
w.raw(&d.raw);
continue;
}
let (_, define) = guid_for_style(s);
if !define {
continue;
}
let name = names.iter().find(|(id, _)| id == s).map(|(_, n)| format!("DeckCraft {n}")).unwrap_or_else(|| s.clone());
style_def(&mut w, s, &name);
}
// Styles the file defined but no table uses still belong to the deck.
for d in defs {
if done_lower.contains(&d.id.to_ascii_lowercase()) {
continue;
}
if crate::xml::parse(d.raw.as_bytes()).is_ok_and(|x| x.root.is("tblStyle")) {
done_lower.insert(d.id.to_ascii_lowercase());
w.raw(&d.raw);
}
}
w.close("a:tblStyleLst");
w.finish()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn shared_writer_matches_legacy_bytes_and_admission() {
use deckcraft_model::table::TableStyleDef;
let mut used: Vec<String> = deckcraft_model::table::table_styles().into_iter().map(|(id, _)| id).collect();
used.extend(["unknown<&\"".into(), "Custom".into(), "Custom".into(), "CUSTOM".into()]);
for raw in [
"<a:tblStyle xmlns:a=\"urn:test\"/>",
"<tblStyle>", // Existing lenient partial-root policy.
"<tblStyle></other><trailing/>",
"<!--prefix--><tblStyle name=\"&amp;\"/>",
"<notAStyle/>",
"",
"<tblStyle><child/></tblStyle>",
] {
let defs = vec![
TableStyleDef { id: "custom".into(), raw: raw.into(), ..Default::default() },
TableStyleDef { id: "CUSTOM".into(), raw: "<tblStyle second=\"1\"/>".into(), ..Default::default() },
TableStyleDef { id: "unused".into(), raw: "<tblStyle unused=\"1\"/>".into(), ..Default::default() },
];
for selection in [&used[..], &[][..]] {
assert_eq!(table_styles_xml(selection, &defs), legacy::table_styles_xml(selection, &defs), "{raw:?}");
}
}
for depth in [255, 256, 257] {
let raw = format!("{}{}", "<tblStyle>".repeat(depth), "</tblStyle>".repeat(depth));
let defs = [TableStyleDef { id: "custom".into(), raw, ..Default::default() }];
assert_eq!(table_styles_xml(&used, &defs), legacy::table_styles_xml(&used, &defs));
}
}
#[test]
fn shared_style_catalog_matches_deckcraft() {
assert_eq!(deckcraft_model::table::table_styles(), craft_drawingml::table::table_styles());
+182
View File
@@ -0,0 +1,182 @@
//! Table styles: our style ids ↔ table style GUIDs, and `tableStyles.xml` definitions for the
//! styles we write (generated from theme accents, matching how DeckCraft draws them).
use crate::opc::NS_A;
use crate::xml::{A, W};
// Keep file-format identifiers in the shared DrawingML implementation. The local
// writer below still owns DeckCraft's table style definitions and XML policy.
pub use craft_drawingml::table::styles::{guid, guid_for_style};
fn own_guid(style: &str) -> String {
guid(&format!("deckcraft-table-style:{style}"))
}
fn clr(w: &mut W, slot: &str, mods: &[(&str, i32)]) {
if mods.is_empty() {
w.val("a:schemeClr", slot);
return;
}
w.open("a:schemeClr", A::new().a("val", slot));
for (n, v) in mods {
w.val(n, v);
}
w.close("a:schemeClr");
}
fn solid(w: &mut W, slot: &str, mods: &[(&str, i32)]) {
w.open0("a:fill");
w.open0("a:solidFill");
clr(w, slot, mods);
w.close("a:solidFill");
w.close("a:fill");
}
fn borders(w: &mut W, b: Option<(&str, &[(&str, i32)], i32)>) {
w.open0("a:tcBdr");
if let Some((slot, mods, width)) = b {
for side in ["a:left", "a:right", "a:top", "a:bottom", "a:insideH", "a:insideV"] {
w.open0(side);
w.open("a:ln", A::new().a("w", width).a("cmpd", "sng"));
w.open0("a:solidFill");
clr(w, slot, mods);
w.close("a:solidFill");
w.close("a:ln");
w.close(side);
}
}
w.close("a:tcBdr");
}
fn txt(w: &mut W, bold: bool, color: Option<&str>) {
w.open("a:tcTxStyle", A::new().o("b", bold.then_some("on")));
w.open("a:fontRef", A::new().a("idx", "minor"));
w.val("a:prstClr", "black");
w.close("a:fontRef");
match color {
Some(c) => w.val("a:schemeClr", c),
None => w.val("a:schemeClr", "dk1"),
}
w.close("a:tcTxStyle");
}
/// Write one `a:tblStyle` for our style id.
fn style_def(w: &mut W, id: &str, name: &str) {
let kind = id.split('-').next().unwrap_or("medium2");
let acc = match id.rsplit('-').next().unwrap_or("accent1") {
"tx1" => "dk1",
a if a.starts_with("accent") => a,
_ => "accent1",
};
let acc: &str = acc;
w.open("a:tblStyle", A::new().a("styleId", own_guid(id)).a("styleName", name));
let part =
|w: &mut W, tag: &str, bold: bool, text: Option<&str>, fill: Option<(&str, &[(&str, i32)])>, bdr: Option<(&str, &[(&str, i32)], i32)>| {
w.open0(tag);
if bold || text.is_some() {
txt(w, bold, text);
}
w.open0("a:tcStyle");
borders(w, bdr);
if let Some((s, m)) = fill {
solid(w, s, m);
}
w.close("a:tcStyle");
w.close(tag);
};
match kind {
"grid" => {
part(w, "a:wholeTbl", false, Some("dk1"), None, Some(("dk1", &[], 9525)));
}
"light1" => {
part(w, "a:wholeTbl", false, Some("dk1"), None, None);
part(w, "a:band1H", false, None, Some((acc, &[("a:tint", 20000)])), None);
part(w, "a:band1V", false, None, Some((acc, &[("a:tint", 20000)])), None);
part(w, "a:lastCol", true, None, None, None);
part(w, "a:firstCol", true, None, None, None);
part(w, "a:lastRow", true, None, None, None);
part(w, "a:firstRow", true, None, None, Some((acc, &[], 12700)));
}
"light2" => {
part(w, "a:wholeTbl", false, Some("dk1"), None, Some((acc, &[], 12700)));
// Schema order: … lastCol, firstCol, lastRow, …, firstRow.
part(w, "a:firstCol", true, None, None, None);
part(w, "a:lastRow", true, None, None, None);
part(w, "a:firstRow", true, Some("lt1"), Some((acc, &[])), Some((acc, &[], 12700)));
}
"dark1" => {
part(w, "a:wholeTbl", false, Some("lt1"), Some((acc, &[("a:shade", 75000)])), Some(("lt1", &[], 12700)));
part(w, "a:band1H", false, None, Some((acc, &[("a:shade", 60000)])), None);
part(w, "a:band1V", false, None, Some((acc, &[("a:shade", 60000)])), None);
part(w, "a:firstCol", true, None, None, None);
part(w, "a:lastRow", true, None, None, None);
part(w, "a:firstRow", true, Some("lt1"), Some(("dk1", &[])), None);
}
"medium4" => {
part(w, "a:wholeTbl", false, Some("dk1"), Some((acc, &[("a:tint", 20000)])), Some((acc, &[], 9525)));
part(w, "a:band1H", false, None, Some((acc, &[("a:tint", 40000)])), None);
part(w, "a:band1V", false, None, Some((acc, &[("a:tint", 40000)])), None);
part(w, "a:lastCol", true, None, None, None);
part(w, "a:firstCol", true, None, None, None);
part(w, "a:lastRow", true, None, None, None);
part(w, "a:firstRow", true, None, Some((acc, &[("a:tint", 40000)])), None);
}
_ => {
// medium2
part(w, "a:wholeTbl", false, Some("dk1"), Some((acc, &[("a:tint", 20000)])), Some(("lt1", &[], 12700)));
part(w, "a:band1H", false, None, Some((acc, &[("a:tint", 40000)])), None);
part(w, "a:band1V", false, None, Some((acc, &[("a:tint", 40000)])), None);
part(w, "a:lastCol", true, Some("lt1"), Some((acc, &[])), None);
part(w, "a:firstCol", true, Some("lt1"), Some((acc, &[])), None);
part(w, "a:lastRow", true, Some("lt1"), Some((acc, &[])), None);
part(w, "a:firstRow", true, Some("lt1"), Some((acc, &[])), None);
}
}
w.close("a:tblStyle");
}
/// `ppt/tableStyles.xml` with definitions for the styles in `used`: ours, generated, and those the
/// opened file defined (`defs`), written back as they were read.
pub fn table_styles_xml(used: &[String], defs: &[deckcraft_model::table::TableStyleDef]) -> Vec<u8> {
let mut w = W::new();
w.open("a:tblStyleLst", A::new().a("xmlns:a", NS_A).a("def", "{5C22544A-7EE6-4342-B048-85BDC9FD1C3A}"));
let names = deckcraft_model::table::table_styles();
// Indexes instead of scans: written ids (as given and ASCII lower-case), and the file's
// definitions by lower-case id (the first wins).
let mut done: std::collections::HashSet<&str> = std::collections::HashSet::new();
let mut done_lower: std::collections::HashSet<String> = std::collections::HashSet::new();
let mut def_of: std::collections::HashMap<String, &deckcraft_model::table::TableStyleDef> = std::collections::HashMap::new();
for d in defs {
def_of.entry(d.id.to_ascii_lowercase()).or_insert(d);
}
for s in used {
if !done.insert(s.as_str()) {
continue;
}
done_lower.insert(s.to_ascii_lowercase());
if let Some(d) = def_of.get(&s.to_ascii_lowercase())
&& crate::xml::parse(d.raw.as_bytes()).is_ok_and(|x| x.root.is("tblStyle"))
{
w.raw(&d.raw);
continue;
}
let (_, define) = guid_for_style(s);
if !define {
continue;
}
let name = names.iter().find(|(id, _)| id == s).map(|(_, n)| format!("DeckCraft {n}")).unwrap_or_else(|| s.clone());
style_def(&mut w, s, &name);
}
// Styles the file defined but no table uses still belong to the deck.
for d in defs {
if done_lower.contains(&d.id.to_ascii_lowercase()) {
continue;
}
if crate::xml::parse(d.raw.as_bytes()).is_ok_and(|x| x.root.is("tblStyle")) {
done_lower.insert(d.id.to_ascii_lowercase());
w.raw(&d.raw);
}
}
w.close("a:tblStyleLst");
w.finish()
}
+63 -1
View File
@@ -232,6 +232,8 @@ pub fn gradient_editor(ui: &mut Ui, id: &str, g: &Gradient, sc: &ColorScheme) ->
let (marks, _) = ui.allocate_exact_size(vec2(bar.width(), 14.0), Sense::hover());
let drag_id = ui.scope_id().with((id, "drag"));
let mut dragging: Option<(usize, f64)> = ui.data_mut(|d| d.get_temp(drag_id));
// A double-clicked stop opens its colour menu, as in PowerPoint (#2175).
let mut open_color = false;
for (i, s) in g.stops.iter().enumerate() {
let pos = dragging.filter(|d| d.0 == i).map_or(s.pos, |d| d.1);
let x = bar.min.x + pos as f32 * bar.width();
@@ -245,6 +247,10 @@ pub fn gradient_editor(ui: &mut Ui, id: &str, g: &Gradient, sc: &ColorScheme) ->
if resp.clicked() || resp.drag_started() {
sel = i;
}
if resp.double_clicked() {
sel = i;
open_color = true;
}
if resp.dragged()
&& let Some(p) = resp.interact_pointer_pos()
{
@@ -287,7 +293,12 @@ pub fn gradient_editor(ui: &mut Ui, id: &str, g: &Gradient, sc: &ColorScheme) ->
let (sw, _) = ui.allocate_exact_size(vec2(18.0, 18.0), Sense::hover());
ui.painter().rect(sw, CornerRadius::same(3), c32(&s.color, sc), Stroke::new(1.0, t.border), egui::StrokeKind::Inside);
let r = widgets::drop_button(ui, "", vec2(24.0, 20.0), true);
widgets::color_popup(&r).show(|ui| {
r.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Button, true, "Stop color"));
let mut popup = widgets::color_popup(&r);
if open_color {
popup = popup.open_memory(egui::SetOpenCommand::Bool(true));
}
popup.show(|ui| {
if let Some(Some(c)) = widgets::color_grid(ui, sc, None) {
let mut ng = g.clone();
ng.stops[sel].color = with_alpha(c, alpha_of(&s.color));
@@ -516,7 +527,58 @@ pub fn pattern_editor(ui: &mut Ui, pt: &PatternFill, sc: &ColorScheme) -> Option
#[cfg(test)]
mod tests {
#![allow(clippy::unwrap_used, clippy::expect_used)]
use super::*;
use egui_kittest::Harness;
use egui_kittest::kittest::Queryable;
/// #2175: double-clicking a gradient stop selects it and opens its colour menu; a colour
/// picked there colours that stop.
#[test]
fn double_clicking_a_stop_opens_its_color_menu() {
let sc = deckcraft_model::Theme::default().colors;
let start = Gradient {
stops: vec![
GradientStop { pos: 0.0, color: ColorRef::scheme(SchemeSlot::Accent1) },
GradientStop { pos: 1.0, color: ColorRef::scheme(SchemeSlot::Accent2) },
],
..default_gradient(ColorRef::scheme(SchemeSlot::Accent1), 90.0)
};
// The gradient, and whether the interface fonts are in (they apply from the next frame).
let mut h = Harness::builder().with_size(vec2(400.0, 700.0)).with_step_dt(1.0 / 60.0).build_ui_state(
move |ui, (g, fonts): &mut (Gradient, bool)| {
if !*fonts {
theme::install_fonts(ui.ctx());
*fonts = true;
return;
}
if let Some(ng) = gradient_editor(ui, "test-grad", &g.clone(), &sc) {
*g = ng;
}
},
(start, false),
);
h.run_steps(3);
assert!(h.query_by_label("Theme Colors").is_none(), "the menu starts closed");
let stop = h.get_by_label("Gradient stop 2").rect().center();
h.hover_at(stop);
h.run_steps(1);
for _ in 0..2 {
for pressed in [true, false] {
h.event(egui::Event::PointerButton { pos: stop, button: egui::PointerButton::Primary, pressed, modifiers: egui::Modifiers::NONE });
h.run_steps(1);
}
}
h.run_steps(2);
assert!(h.query_by_label("Theme Colors").is_some(), "the colour menu opened");
h.get_by_label(SchemeSlot::Accent6.label()).click();
h.run_steps(2);
let g = &h.state().0;
assert_eq!(g.stops.len(), 2, "no stop was added");
assert_eq!(g.stops[1].color, ColorRef::scheme(SchemeSlot::Accent6), "the double-clicked stop took the colour");
assert_eq!(g.stops[0].color, ColorRef::scheme(SchemeSlot::Accent1));
}
#[test]
fn gradient_json_retains_flip_mode() {
+5 -2
View File
@@ -552,7 +552,8 @@ impl Show {
true
}
/// On entering a slide: auto-play its first step when it begins With/After Previous.
/// On entering a slide: auto-play its first step when it begins With/After Previous, once the
/// slide's transition is over.
/// `ShowState` already starts such a step when it enters the slide (#631: asking it for the
/// next step again finished the step at once, so the slide appeared fully built), so only
/// its clock starts here. Autoplay previews start an On Click first step themselves.
@@ -568,7 +569,9 @@ impl Show {
None
};
if let Some(k) = started {
self.step_start = now;
// The slide's transition plays first; its animations start when it has finished, as
// in PowerPoint (#2089).
self.step_start = self.trans.as_ref().map_or(now, |t| now.max(t.start + t.dur));
self.media_clock = Some((k, f64::NEG_INFINITY));
}
}
+35
View File
@@ -516,6 +516,41 @@ fn a_transition_keeps_the_old_slide_in_its_own_texture() {
assert!(show.tex.is_none(), "the new slide gets a texture of its own instead of overwriting the old one");
}
/// #2089: a slide's With Previous entrance waits for the slide's transition to finish, as in
/// PowerPoint, instead of playing under it.
#[test]
fn animations_start_after_the_slides_transition() {
let mut s = deckcraft_engine::Session::with_new();
s.execute("slide.new", &json!({})).unwrap();
s.execute("transition.set", &json!({"kind": "fade", "index": 1, "duration": 400})).unwrap();
let id = s.active().unwrap().doc.slides[1].shapes[0].id;
s.execute("animation.add", &json!({"effect": "fade", "class": "entrance", "ids": [id.0], "start": "withPrevious", "duration": 500})).unwrap();
let doc = s.active().unwrap().doc.clone();
let mut show = Show::new(&doc, 0, false, false);
let a = show.state.next(&doc);
assert_eq!(a, ShowAction::Slide(1));
assert!(show.apply(a, &doc, 10.0));
assert!(show.trans.is_some(), "the fade plays");
assert!(show.state.playing, "the With Previous step is under way");
assert!((show.clock_snapshot().step_start - 10.4).abs() < 1e-9, "its clock starts when the 0.4 s fade ends");
let tl = ShowState::timeline(&doc, 1);
let at = |now: f64| state_for(&tl, id, show.state.step, now - show.clock_snapshot().step_start, &[], &[]);
assert!(!at(10.3).visible, "hidden while the transition plays");
assert!(at(10.6).visible && at(10.6).opacity < 1.0, "fading in after it");
// The step is not cut short by the time the transition took.
let mut actions = Vec::new();
assert!(show.queue_clock_actions(&doc, 10.8, &mut actions));
assert!(actions.is_empty(), "0.4 s into a 0.5 s step: still playing");
// Without a transition the step starts at once, as before.
s.execute("transition.set", &json!({"kind": "none", "index": 1})).unwrap();
let doc = s.active().unwrap().doc.clone();
let mut show = Show::new(&doc, 0, false, false);
let a = show.state.next(&doc);
assert!(show.apply(a, &doc, 10.0));
assert_eq!(show.clock_snapshot().step_start, 10.0);
}
#[test]
fn going_back_plays_the_left_slides_transition_reversed() {
// #1531: Back from B to A played A's own entrance transition. PowerPoint plays the one B came