mirror of
https://github.com/storytold/deckcraft.git
synced 2026-12-01 10:47:56 +01:00
Merge branch 'port/deckcraft/red/app-r2-4' into port/deckcraft/area/app
# Conflicts: # crates/ui-egui/src/app.rs
This commit is contained in:
commit
650f4b9ff1
12 files changed
+46
-29
No files matched your search
@@ -38,7 +38,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
cmd!(noundo "slide.first", "First Slide", [], Some("Home"), "{}", has_slide, first),
|
||||
cmd!(noundo "slide.last", "Last Slide", [], Some("End"), "{}", has_slide, last),
|
||||
cmd!(noundo "slide.selectRange", "Select Slide Range", [], None, "{to: index, from?: index (default the current slide), add?: bool (keep the slides already selected)}", has_slide, select_range),
|
||||
cmd!(noundo "slide.selectSlides", "Select Slides", [], None, "{ids?: [slide id], indices?: [index], add?: bool}", has_slide, select_slides),
|
||||
cmd!(noundo "slide.selectSlides", "Select Slides", [], None, "{ids?: [slide id], indices?: [index], add?: bool, anchor?: slide id (the range anchor of a grid selection)}", has_slide, select_slides),
|
||||
cmd!("slide.hide", "Hide Slide", ["Slide Show", "Set Up"], None, "{index?, hidden?: bool}", has_slide, hide),
|
||||
cmd!("slide.layout", "Layout", ["Home", "Slides"], None, "{layout: name or kind, index?}", has_slide, set_layout),
|
||||
cmd!("slide.reset", "Reset", ["Home", "Slides"], None, "{index?}", has_slide, reset),
|
||||
@@ -394,6 +394,7 @@ fn last(s: &mut Session, _p: &Value) -> Result<Value> {
|
||||
|
||||
fn select_slides(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let add = bool_or(p, "add", false);
|
||||
let anchor = p.get("anchor").and_then(Value::as_u64).and_then(|x| u32::try_from(x).ok()).map(SlideId);
|
||||
let ids: Vec<SlideId> = {
|
||||
let st = s.doc()?;
|
||||
let mut v: Vec<SlideId> = p
|
||||
@@ -422,7 +423,8 @@ fn select_slides(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
}
|
||||
sel.shapes.clear();
|
||||
sel.text = None;
|
||||
sel.range_anchor = None;
|
||||
let current = doc.slides.get(sel.slide).map(|x| x.id);
|
||||
sel.range_anchor = anchor.filter(|a| doc.slide_index(*a).is_some()).zip(current);
|
||||
})?;
|
||||
Ok(json!({"selected": s.doc()?.selection.slides}))
|
||||
}
|
||||
|
||||
@@ -989,11 +989,12 @@ mod tests {
|
||||
|_| {},
|
||||
);
|
||||
let listener = std::net::TcpListener::bind(("127.0.0.1", 0))?;
|
||||
let (receiver, listening) = server::serve(listener, "token".into(), WindowHost::of(&harness.ctx))?;
|
||||
let token = craft::automation::security::generate_token()?;
|
||||
let (receiver, listening) = server::serve(listener, token.clone(), WindowHost::of(&harness.ctx))?;
|
||||
harness.state_mut().control = Some(ControlChannel::new(receiver));
|
||||
let addr = listening.addr;
|
||||
let notice = "A notice sent over the socket";
|
||||
let client = std::thread::spawn(move || ControlClient::connect(addr, "token").map_err(|e| format!("{e:?}"))?.call("ui.notify", json!({"text": notice})));
|
||||
let client = std::thread::spawn(move || ControlClient::connect(addr, &token).map_err(|e| format!("{e:?}"))?.call("ui.notify", json!({"text": notice})));
|
||||
let mut frames = 0;
|
||||
while !client.is_finished() && frames < 600 {
|
||||
harness.run_steps(1);
|
||||
|
||||
@@ -74,7 +74,7 @@ fn lock_aspect_from_the_dialog_scales_height() {
|
||||
h.run_steps(1);
|
||||
h.key_press(egui::Key::Enter);
|
||||
h.run_steps(2);
|
||||
dialog(&mut h, "ui.dialog.confirm", json!({"dialog": "top"}));
|
||||
assert!(super::open_keys(&h.ctx).is_empty(), "Enter in the width field is OK");
|
||||
let after = box_of(h.state(), id);
|
||||
let width = 4.0 * 72.0;
|
||||
assert_eq!(after, (before.0, before.1, width, before.3 * width / before.2, before.4));
|
||||
|
||||
@@ -16,14 +16,18 @@ fn harness(n: usize) -> egui_kittest::Harness<'static, SlideApp> {
|
||||
crate::test_harness::harness(s, Services::default())
|
||||
}
|
||||
|
||||
/// A root frame with two uploads and two passes contributes two uploads, not four.
|
||||
/// Thumbnails rendered since the harness began: each one is a held entry or an evicted one. The store's per-frame
|
||||
/// `uploads` count is rolled over when a frame ends, so it reads zero between harness steps.
|
||||
fn renders(h: &egui_kittest::Harness<'_, SlideApp>) -> usize {
|
||||
let stats = crate::thumb_source::thumbnails(&h.ctx).cache().statistics(&h.ctx);
|
||||
stats.entries + stats.evicted
|
||||
}
|
||||
|
||||
/// The thumbnails rendered by `frames` more frames.
|
||||
fn step_uploads(h: &mut egui_kittest::Harness<'_, SlideApp>, frames: usize) -> usize {
|
||||
let mut uploads = 0;
|
||||
for _ in 0..frames {
|
||||
h.run_steps(1);
|
||||
uploads += crate::thumb_source::thumbnails(&h.ctx).cache().statistics(&h.ctx).uploads;
|
||||
}
|
||||
uploads
|
||||
let before = renders(h);
|
||||
h.run_steps(frames);
|
||||
renders(h) - before
|
||||
}
|
||||
|
||||
/// Outline view of 2000 slides lays out the slides in view (and the current one), not all 2000
|
||||
@@ -84,7 +88,7 @@ fn the_sorter_of_a_huge_deck_renders_only_the_slides_in_view() {
|
||||
#[test]
|
||||
fn a_settled_thumbnail_pane_renders_nothing_more() {
|
||||
let mut h = harness(800);
|
||||
let initial = crate::thumb_source::thumbnails(&h.ctx).cache().statistics(&h.ctx).uploads;
|
||||
let initial = renders(&h);
|
||||
let rendered = initial + step_uploads(&mut h, 60);
|
||||
let held = crate::thumb_source::thumbnails(&h.ctx).cache().statistics(&h.ctx).entries;
|
||||
// Every thumbnail held was rendered, and the pane did not render many it then threw away:
|
||||
@@ -122,7 +126,7 @@ fn a_settled_thumbnail_pane_renders_nothing_more() {
|
||||
fn a_settled_sorter_renders_nothing_more() {
|
||||
let mut h = harness(800);
|
||||
h.state_mut().ui.view = crate::ViewMode::Sorter;
|
||||
let initial = crate::thumb_source::thumbnails(&h.ctx).cache().statistics(&h.ctx).uploads;
|
||||
let initial = renders(&h);
|
||||
let rendered = initial + step_uploads(&mut h, 60);
|
||||
let held = crate::thumb_source::thumbnails(&h.ctx).cache().statistics(&h.ctx).entries;
|
||||
assert!(rendered >= held && rendered < held * 2, "{rendered} renders for {held} thumbnails");
|
||||
|
||||
@@ -364,7 +364,7 @@ mod tests {
|
||||
fn names_round_trip_and_are_unique() {
|
||||
assert!(
|
||||
geometry::text_face().is_some(),
|
||||
"icon coverage requires CRAFT_FONTS_DIR to embed a parseable Inter Regular face"
|
||||
"icon coverage requires the framework's parseable Inter Regular face"
|
||||
);
|
||||
register();
|
||||
register();
|
||||
|
||||
@@ -175,12 +175,14 @@ pub(super) fn tf(c: P2, ang: f32, pts: &[P2]) -> Vec<P2> {
|
||||
pub(super) fn text_face() -> Option<&'static ttf_parser::Face<'static>> {
|
||||
static FACE: OnceLock<Option<ttf_parser::Face<'static>>> = OnceLock::new();
|
||||
FACE.get_or_init(|| {
|
||||
let face = deckcraft_fonts::CRAFT_FONTS
|
||||
.iter()
|
||||
.find(|font| font.family == "Inter" && font.style == "Regular")
|
||||
.and_then(|font| ttf_parser::Face::parse(font.bytes, 0).ok());
|
||||
// The suite's interface face ships with the framework's default faces; its bytes live for the process.
|
||||
let face = craft::ui::fonts::deflated_default_definitions()
|
||||
.font_data
|
||||
.get("Inter-Regular")
|
||||
.map(|data| &*Box::leak(data.font.to_vec().into_boxed_slice()))
|
||||
.and_then(|bytes| ttf_parser::Face::parse(bytes, 0).ok());
|
||||
if face.is_none() {
|
||||
log::warn!("DeckCraft icon text omitted: embedded Inter Regular is missing or invalid; supply CRAFT_FONTS_DIR");
|
||||
log::warn!("DeckCraft icon text omitted: the framework's Inter Regular is missing or invalid");
|
||||
}
|
||||
face
|
||||
})
|
||||
|
||||
@@ -22,6 +22,7 @@ pub(crate) fn preset_grid<K: Clone + Eq + std::hash::Hash + Send + Sync + 'stati
|
||||
.natural_height(true)
|
||||
.caption(CaptionPlace::None)
|
||||
.select(SelectMode::Single)
|
||||
.natural_height(true)
|
||||
.thumb_size(ThumbSize::Small)
|
||||
.natural_height(true)
|
||||
.selection(Bind::given(selection))
|
||||
|
||||
@@ -181,6 +181,7 @@ pub fn show(app: &mut SlideApp, ui: &mut Ui) {
|
||||
.rename(true)
|
||||
.rename_column(NAME)
|
||||
.header(false)
|
||||
.natural_height(true)
|
||||
.columns(vec![
|
||||
ColumnSpec::new(NAME, "", craft::behavior::ColumnWidth::fill(1.0)),
|
||||
ColumnSpec::toggle(EYE, "", ToggleColumn::default()).icon(Icon::Eye.id()),
|
||||
|
||||
@@ -26,7 +26,7 @@ fn text_pane_types_adds_and_demotes() {
|
||||
let mut h = harness(s, Services::default());
|
||||
h.state_mut().ui.pane = Some("smartart".into());
|
||||
h.run_steps(3);
|
||||
assert!(h.query_by_label("Text Pane").is_some());
|
||||
assert!(h.query_all_by_label("Text Pane").any(|n| n.accesskit_node().role() != egui::accesskit::Role::Button), "the pane is titled");
|
||||
let initial = levels(&h);
|
||||
|
||||
line(&h, "Build").click();
|
||||
@@ -113,7 +113,7 @@ fn home_convert_to_smartart_gallery_converts_the_text() {
|
||||
h.get_by_label("Convert to Diagram").click();
|
||||
h.run_steps(3);
|
||||
let layout = deckcraft_engine::cmd::smartart::LAYOUTS.iter().find(|(kind, _)| *kind == "blockList").unwrap();
|
||||
h.get_by_role_and_label(egui::accesskit::Role::Button, layout.1).click();
|
||||
h.get_by_role_and_label(egui::accesskit::Role::ListItem, layout.1).click();
|
||||
h.run_steps(3);
|
||||
let st = h.state().session.active().unwrap();
|
||||
let (_, d) = deckcraft_engine::cmd::smartart::selected(st).expect("the text became a Diagram graphic");
|
||||
@@ -135,12 +135,12 @@ fn layout_gallery_shows_cached_pictures_and_previews_on_hover() {
|
||||
);
|
||||
h.state_mut().ui.tab = "SmartArt Design".into();
|
||||
h.run_steps(3);
|
||||
h.get_by_label("Layouts").click();
|
||||
h.get_by_role_and_label(egui::accesskit::Role::Button, "Layouts").click();
|
||||
h.run_steps(3);
|
||||
let first = crate::ribbon::diagram_thumbs::thumbnails(&h.ctx).cache().statistics(&h.ctx);
|
||||
assert!(first.entries > 0, "gallery pictures were drawn");
|
||||
let layout = deckcraft_engine::cmd::smartart::LAYOUTS.iter().find(|(kind, _)| *kind == "verticalBoxList").unwrap();
|
||||
h.get_by_role_and_label(egui::accesskit::Role::Button, layout.1).hover();
|
||||
h.get_by_role_and_label(egui::accesskit::Role::ListItem, layout.1).hover();
|
||||
// The tile's rich tip opens after the pointer rests; each harness step advances 1/60 s.
|
||||
h.run_steps(60);
|
||||
let hovered = crate::ribbon::diagram_thumbs::thumbnails(&h.ctx).cache().statistics(&h.ctx);
|
||||
@@ -148,7 +148,7 @@ fn layout_gallery_shows_cached_pictures_and_previews_on_hover() {
|
||||
h.run_steps(60);
|
||||
let settled = crate::ribbon::diagram_thumbs::thumbnails(&h.ctx).cache().statistics(&h.ctx);
|
||||
assert_eq!(settled.entries, hovered.entries, "pictures are cached, not redrawn every frame");
|
||||
h.get_by_role_and_label(egui::accesskit::Role::Button, layout.1).click();
|
||||
h.get_by_role_and_label(egui::accesskit::Role::ListItem, layout.1).click();
|
||||
h.run_steps(3);
|
||||
let st = h.state().session.active().unwrap();
|
||||
assert_eq!(deckcraft_engine::cmd::smartart::selected(st).unwrap().1.kind, layout.0);
|
||||
|
||||
@@ -122,6 +122,9 @@ mod tests {
|
||||
);
|
||||
h.get_by_role_and_label(Role::Tab, "View").click();
|
||||
h.run_steps(3);
|
||||
for node in h.query_all_by_role(Role::Button).chain(h.query_all_by_role(Role::CheckBox)) {
|
||||
eprintln!("DIAG a_toggle_shows_checked_while_the_state_it_changes_holds: {:?} {:?}", node.accesskit_node().role(), node.accesskit_node().label());
|
||||
}
|
||||
let off = h.get_by_role_and_label(Role::Button, "Slide Master").accesskit_node().toggled();
|
||||
assert_eq!(off, Some(Toggled::False));
|
||||
h.get_by_role_and_label(Role::Button, "Slide Master").click();
|
||||
|
||||
@@ -92,7 +92,6 @@ pub fn show(app: &mut SlideApp, ui: &mut Ui) {
|
||||
let Some(st) = app.session.active() else { return };
|
||||
let (uid, doc, cur) = (st.uid, st.doc.clone(), st.selection.slide);
|
||||
let lead = doc.slides.get(cur).map(|slide| Key::Slide(slide.id));
|
||||
// PLAN: plan error: slide.selectSlides clears range_anchor; shell-w4 must preserve the grid anchor and a deselected lead in its command interface.
|
||||
let anchor = st.selection.range_anchor.map(|(first, _)| Key::Slide(first)).or(lead);
|
||||
let mut selection = Selection::new(st.selection.slides.iter().copied().map(Key::Slide).collect(), lead, anchor);
|
||||
let mut keys = Vec::with_capacity(doc.slides.len());
|
||||
@@ -253,7 +252,11 @@ fn select_slides(app: &mut SlideApp, doc: &Presentation, selection: &Selection<K
|
||||
ids.remove(at);
|
||||
ids.push(lead.0);
|
||||
}
|
||||
let _ = app.run("slide.selectSlides", json!({"ids": ids, "add": false}));
|
||||
let anchor = match selection.anchor {
|
||||
Some(Key::Slide(anchor)) => Some(anchor.0),
|
||||
_ => None,
|
||||
};
|
||||
let _ = app.run("slide.selectSlides", json!({"ids": ids, "add": false, "anchor": anchor}));
|
||||
}
|
||||
|
||||
fn section_menu(app: &mut SlideApp, ui: &mut Ui, index: usize, opener: &egui::Response, words: &SorterWords) {
|
||||
|
||||
@@ -280,8 +280,8 @@ fn the_outline_view_leaves_footer_date_and_slide_number_out() {
|
||||
h.run_steps(3);
|
||||
let words = craft::ui::runtime::env::Env::of_root(&h.ctx).words::<super::SorterWords>();
|
||||
let values: Vec<_> = h.query_all_by_role(Role::TextInput).filter_map(|node| node.value()).collect();
|
||||
assert!(h.query_by_role_and_label(Role::TextInput, words.slide_title.as_str()).is_some());
|
||||
assert!(h.query_by_role_and_label(Role::TextInput, words.slide_text.as_str()).is_some());
|
||||
assert!(h.query_all_by_role_and_label(Role::TextInput, words.slide_title.as_str()).next().is_some());
|
||||
assert!(h.query_all_by_role_and_label(Role::TextInput, words.slide_text.as_str()).next().is_some());
|
||||
for text in included {
|
||||
assert!(values.contains(&text), "title and body belong in the Outline");
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user