mirror of
https://github.com/storytold/deckcraft.git
synced 2026-12-02 02:36:14 -06:00
Merge branch 'port/deckcraft/cfix/app-r2' into port/deckcraft/area/app
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
use super::{Mods, SlideApp, qat};
|
||||
use craft::keymap::{Chord, Key, Mods as KeyMods};
|
||||
// PLAN: assumed craft::ui::runtime::focus::has_focus(ctx: &egui::Context) -> bool (shell-w2)
|
||||
use craft::ui::runtime::focus;
|
||||
use craft::ui::runtime::keys::{Intent, with_window_intents};
|
||||
|
||||
@@ -55,14 +54,14 @@ impl SlideApp {
|
||||
qat::run_index(self, index);
|
||||
continue;
|
||||
}
|
||||
if focus::has_focus(ctx) {
|
||||
if focus::has_any(ctx) {
|
||||
continue;
|
||||
}
|
||||
if let Err(error) = self.session.key(key_name(key), mods) {
|
||||
self.set_status(error.to_string());
|
||||
}
|
||||
}
|
||||
egui::Event::Text(text) if !focus::has_focus(ctx) => {
|
||||
egui::Event::Text(text) if !focus::has_any(ctx) => {
|
||||
if self.session.active().is_some_and(|d| d.selection.text.is_some() || d.selection.shapes.len() == 1)
|
||||
&& let Err(error) = self.session.type_text(&text)
|
||||
{
|
||||
|
||||
@@ -18,7 +18,7 @@ use crate::icons::Icon;
|
||||
|
||||
mod files;
|
||||
mod info;
|
||||
mod print;
|
||||
pub(crate) mod print;
|
||||
|
||||
pub use files::split_path;
|
||||
use files::{home, new_page, open_page};
|
||||
|
||||
@@ -662,7 +662,7 @@ fn set_pane_state(app: &mut SlideApp, ctx: &egui::Context, params: &Value) -> Re
|
||||
.map(|index| {
|
||||
index
|
||||
.map(|index| {
|
||||
sections.get(index).map(|section| (uid, index, section.name.clone())).ok_or_else(|| format!("no section {index}"))
|
||||
sections.get(index).map(|_| index).ok_or_else(|| format!("no section {index}"))
|
||||
})
|
||||
.transpose()
|
||||
})
|
||||
|
||||
@@ -174,9 +174,8 @@ pub struct SlideApp {
|
||||
pub ruler_tab_kind: craft::text::ui::ruler::TabAlign,
|
||||
/// The open canvas context menu.
|
||||
pub canvas_menu: Option<canvas::context_menu::CanvasMenu>,
|
||||
/// Motion requested for the editor; absence inherits the window policy.
|
||||
// PLAN: assumed SlideApp::editor_motion: Option<craft::behavior::MotionMode> (canvas-w8)
|
||||
pub(crate) editor_motion: Option<craft::behavior::MotionMode>,
|
||||
/// Optional motion-mode request for the text editor host: `Some(false)` turns the caret blink off.
|
||||
pub(crate) caret_blink: Option<bool>,
|
||||
/// Shape Fill's last command colour, initially Accent 1.
|
||||
pub last_fill: Value,
|
||||
/// Shape Outline's last command colour, initially Text 1.
|
||||
|
||||
@@ -15,7 +15,7 @@ use crate::state::ViewMode;
|
||||
pub mod animation;
|
||||
mod background;
|
||||
pub(crate) mod color_row;
|
||||
mod comments;
|
||||
pub(crate) mod comments;
|
||||
mod designer;
|
||||
mod effect_presets;
|
||||
pub mod format_shape;
|
||||
|
||||
@@ -323,6 +323,7 @@ mod tests {
|
||||
|
||||
use super::*;
|
||||
use crate::Services;
|
||||
use crate::test_harness::Framed;
|
||||
|
||||
fn slides(count: usize) -> Result<Session, String> {
|
||||
let mut session = Session::with_new();
|
||||
@@ -333,30 +334,32 @@ mod tests {
|
||||
Ok(session)
|
||||
}
|
||||
|
||||
fn editor(session: Session, height: f32) -> Harness<'static, SlideApp> {
|
||||
let mut h = Harness::builder().with_size(vec2(1200.0, height)).with_step_dt(1.0 / 60.0).build_ui_state(
|
||||
|ui, app: &mut SlideApp| {
|
||||
fn editor(session: Session, height: f32) -> Harness<'static, Framed> {
|
||||
let mut h = crate::test_harness::harness_framed(
|
||||
session,
|
||||
Services::default(),
|
||||
Harness::builder().with_size(vec2(1200.0, height)).with_step_dt(1.0 / 60.0),
|
||||
|app, ui| {
|
||||
app.logic(ui.ctx());
|
||||
app.ui(ui);
|
||||
if ui.ctx().current_pass_index() == 0 {
|
||||
ui.ctx().request_discard("exercise the editor with two passes in a frame");
|
||||
}
|
||||
},
|
||||
SlideApp::new_base(session, Services::default()),
|
||||
);
|
||||
h.run_steps(3);
|
||||
h
|
||||
}
|
||||
|
||||
fn deck<'a>(h: &'a Harness<'_, SlideApp>) -> Result<&'a DocState, String> {
|
||||
fn deck<'a>(h: &'a Harness<'_, Framed>) -> Result<&'a DocState, String> {
|
||||
h.state().session.active().ok_or_else(|| "the editor has no presentation".into())
|
||||
}
|
||||
|
||||
fn tile(h: &Harness<'_, SlideApp>, number: usize) -> Rect {
|
||||
fn tile(h: &Harness<'_, Framed>, number: usize) -> Rect {
|
||||
h.get_by_role_and_label(Role::ListItem, &number.to_string()).rect()
|
||||
}
|
||||
|
||||
fn view(h: &Harness<'_, SlideApp>) -> Rect {
|
||||
fn view(h: &Harness<'_, Framed>) -> Rect {
|
||||
h.get_by_role_and_label(Role::ListBox, ThumbWords::english().slides.as_str()).rect()
|
||||
}
|
||||
|
||||
|
||||
@@ -259,9 +259,6 @@ mod drawtable_tests;
|
||||
#[cfg(test)]
|
||||
mod inktoshape_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
mod picture_styles_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
mod feature_name_tests {
|
||||
use deckcraft_engine::Session;
|
||||
|
||||
@@ -58,8 +58,7 @@ fn header() -> Stack<'static> {
|
||||
}
|
||||
|
||||
fn rooms(ctx: &egui::Context, env: &Env, room: Rect, note: bool) -> (Rect, Rect) {
|
||||
// PLAN: assumed Stack::measure_with(&self, ctx: &egui::Context, env: &Env, proposal: Proposal, content: impl FnOnce(&mut Ui, &Env)) -> Vec2 (panels-w2)
|
||||
let height = header().measure_with(ctx, env, Proposal::Ideal, |ui, _| heading(ui, note)).y.min(room.height().max(0.0));
|
||||
let height = header().measure_with_env(ctx, env, Proposal::Ideal, |ui, _| heading(ui, note)).y.min(room.height().max(0.0));
|
||||
let head = Rect::from_min_size(room.min, egui::vec2(room.width(), height));
|
||||
let body = Rect::from_min_max(head.left_bottom(), room.max);
|
||||
(head, body)
|
||||
|
||||
@@ -115,7 +115,7 @@ impl Show {
|
||||
});
|
||||
if self.grid {
|
||||
let slides = grid_indices(n_slides);
|
||||
let cells = super::grid::cells(ctx, full, n_slides, aspect);
|
||||
let cells = super::grid::cells(ctx, &craft::ui::runtime::env::Env::of_root(ctx), full, n_slides, aspect);
|
||||
value["cells"] = serde_json::Value::Array(
|
||||
slides.iter().zip(cells).map(|(i, rect)| json!({"slide": i, "x": rect.center().x, "y": rect.center().y})).collect(),
|
||||
);
|
||||
|
||||
@@ -50,6 +50,8 @@ craft::ui::words! {
|
||||
pub struct State {
|
||||
/// Fold keys follow a section's first slide across section moves; empty sections stay open.
|
||||
pub collapsed: HashSet<(u64, u32)>,
|
||||
/// A section whose title the next pass opens for editing, set by the automation interface.
|
||||
pub renaming: Option<usize>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
@@ -171,6 +173,9 @@ pub fn show(app: &mut SlideApp, ui: &mut Ui) {
|
||||
});
|
||||
app.ui.sorter_zoom = zoom as f32;
|
||||
let opener = &out.response.response;
|
||||
if let Some(index) = app.sorter.renaming.take() {
|
||||
craft::ui::contract::request_rename(ui.ctx(), opener.id, &Key::Section(index));
|
||||
}
|
||||
// PLAN: plan error: panels-w2 must retain pointer GroupMenu requests in CollectionResponse::menu; grid.rs emits them outside the collection menu lifecycle.
|
||||
if let Some(request) = &out.response.menu {
|
||||
match request.key {
|
||||
|
||||
@@ -8,9 +8,10 @@ use egui_kittest::Harness;
|
||||
use egui_kittest::kittest::Queryable;
|
||||
use serde_json::json;
|
||||
|
||||
use crate::{Services, SlideApp};
|
||||
use crate::Services;
|
||||
use crate::test_harness::Framed;
|
||||
|
||||
fn harness(with_sections: bool) -> Harness<'static, SlideApp> {
|
||||
fn harness(with_sections: bool) -> Harness<'static, Framed> {
|
||||
let mut s = Session::with_new();
|
||||
for _ in 0..3 {
|
||||
s.execute("slide.new", &json!({})).unwrap();
|
||||
@@ -19,10 +20,11 @@ fn harness(with_sections: bool) -> Harness<'static, SlideApp> {
|
||||
s.execute("section.add", &json!({"name": "Alpha", "at": 0})).unwrap();
|
||||
s.execute("section.add", &json!({"name": "Beta", "at": 2})).unwrap();
|
||||
}
|
||||
let mut app = SlideApp::new_base(s, Services::default());
|
||||
app.ui.view = crate::ViewMode::Sorter;
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).with_step_dt(1.0 / 60.0).build_ui_state(
|
||||
|ui, app: &mut SlideApp| {
|
||||
let mut h = crate::test_harness::harness_framed(
|
||||
s,
|
||||
Services::default(),
|
||||
Harness::builder().with_size(egui::vec2(1400.0, 900.0)).with_step_dt(1.0 / 60.0),
|
||||
|app, ui| {
|
||||
let rerun = ui.input(|input| !input.events.is_empty());
|
||||
app.logic(ui.ctx());
|
||||
let _ = inspect::record(ui, egui::Id::new("sorter-trial"), |ui| app.ui(ui));
|
||||
@@ -31,21 +33,21 @@ fn harness(with_sections: bool) -> Harness<'static, SlideApp> {
|
||||
craft::ui::runtime::frame::discard_pass(ui.ctx(), "exercise the input frame's second pass");
|
||||
}
|
||||
},
|
||||
app,
|
||||
);
|
||||
h.state_mut().ui.view = crate::ViewMode::Sorter;
|
||||
h.run_steps(3);
|
||||
h
|
||||
}
|
||||
|
||||
fn section_names(h: &Harness<'_, SlideApp>) -> Vec<String> {
|
||||
fn section_names(h: &Harness<'_, Framed>) -> Vec<String> {
|
||||
h.state().session.active().unwrap().doc.sections.iter().map(|s| s.name.clone()).collect()
|
||||
}
|
||||
|
||||
fn section_slides(h: &Harness<'_, SlideApp>) -> Vec<Vec<u32>> {
|
||||
fn section_slides(h: &Harness<'_, Framed>) -> Vec<Vec<u32>> {
|
||||
h.state().session.active().unwrap().doc.sections.iter().map(|s| s.slides.iter().map(|id| id.0).collect()).collect()
|
||||
}
|
||||
|
||||
fn double_click(h: &mut Harness<'_, SlideApp>, p: Pos2) {
|
||||
fn double_click(h: &mut Harness<'_, Framed>, p: Pos2) {
|
||||
h.hover_at(p);
|
||||
h.run_steps(1);
|
||||
for _ in 0..2 {
|
||||
@@ -58,7 +60,7 @@ fn double_click(h: &mut Harness<'_, SlideApp>, p: Pos2) {
|
||||
}
|
||||
|
||||
/// Presses at `from`, moves to `to` in a few steps and releases there.
|
||||
pub(crate) fn drag(h: &mut Harness<'_, SlideApp>, from: Pos2, to: Pos2) {
|
||||
pub(crate) fn drag(h: &mut Harness<'_, Framed>, from: Pos2, to: Pos2) {
|
||||
h.hover_at(from);
|
||||
h.run_steps(1);
|
||||
h.drag_at(from);
|
||||
@@ -72,7 +74,7 @@ pub(crate) fn drag(h: &mut Harness<'_, SlideApp>, from: Pos2, to: Pos2) {
|
||||
h.run_steps(3);
|
||||
}
|
||||
|
||||
fn fold(h: &mut Harness<'_, SlideApp>, group: usize) {
|
||||
fn fold(h: &mut Harness<'_, Framed>, group: usize) {
|
||||
let record = inspect::recorded(&h.ctx, egui::Id::new("sorter-trial")).unwrap();
|
||||
let disclosure = record.hits.iter().find(|hit| hit.part == Some(PartKey::new("group_toggle").at(group as u64))).unwrap().rect.center();
|
||||
h.hover_at(disclosure);
|
||||
@@ -84,7 +86,7 @@ fn fold(h: &mut Harness<'_, SlideApp>, group: usize) {
|
||||
h.run_steps(2);
|
||||
}
|
||||
|
||||
fn header_rect(h: &Harness<'_, SlideApp>, index: usize) -> egui::Rect {
|
||||
fn header_rect(h: &Harness<'_, Framed>, index: usize) -> egui::Rect {
|
||||
let names = section_names(h);
|
||||
let record = inspect::recorded(&h.ctx, egui::Id::new("sorter-trial")).unwrap();
|
||||
let label = record
|
||||
@@ -97,15 +99,15 @@ fn header_rect(h: &Harness<'_, SlideApp>, index: usize) -> egui::Rect {
|
||||
h.get_by_role_and_label(Role::Heading, label).rect()
|
||||
}
|
||||
|
||||
fn slide_order(h: &Harness<'_, SlideApp>) -> Vec<u32> {
|
||||
fn slide_order(h: &Harness<'_, Framed>) -> Vec<u32> {
|
||||
h.state().session.active().unwrap().doc.slides.iter().map(|s| s.id.0).collect()
|
||||
}
|
||||
|
||||
fn selected_slides(h: &Harness<'_, SlideApp>) -> Vec<u32> {
|
||||
fn selected_slides(h: &Harness<'_, Framed>) -> Vec<u32> {
|
||||
h.state().session.active().unwrap().selection.slides.iter().map(|s| s.0).collect()
|
||||
}
|
||||
|
||||
fn selected(h: &Harness<'_, SlideApp>) -> Vec<usize> {
|
||||
fn selected(h: &Harness<'_, Framed>) -> Vec<usize> {
|
||||
let st = h.state().session.active().unwrap();
|
||||
let mut v: Vec<usize> = st.selection.slides.iter().filter_map(|id| st.doc.slide_index(*id)).collect();
|
||||
v.sort_unstable();
|
||||
@@ -222,7 +224,7 @@ fn ctrl_a_selects_every_slide() {
|
||||
fn shift_and_ctrl_shift_clicks_select_ranges() {
|
||||
use egui::Modifiers;
|
||||
let mut h = harness(false);
|
||||
let click = |h: &mut Harness<'_, SlideApp>, n: usize, modifiers: Modifiers| {
|
||||
let click = |h: &mut Harness<'_, Framed>, n: usize, modifiers: Modifiers| {
|
||||
h.get_by_label(&n.to_string()).click_modifiers(modifiers);
|
||||
h.run_steps(2);
|
||||
};
|
||||
@@ -270,15 +272,11 @@ fn the_outline_view_leaves_footer_date_and_slide_number_out() {
|
||||
.map(|text| text.text())
|
||||
.filter(|text| !text.is_empty())
|
||||
.collect();
|
||||
let mut app = SlideApp::new_base(s, Services::default());
|
||||
app.ui.view = crate::ViewMode::Outline;
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).build_ui_state(
|
||||
|ui, app: &mut SlideApp| {
|
||||
app.logic(ui.ctx());
|
||||
crate::panels::show_editor(app, ui);
|
||||
},
|
||||
app,
|
||||
);
|
||||
let mut h = crate::test_harness::harness_framed(s, Services::default(), Harness::builder().with_size(egui::vec2(1400.0, 900.0)), |app, ui| {
|
||||
app.logic(ui.ctx());
|
||||
crate::panels::show_editor(app, ui);
|
||||
});
|
||||
h.state_mut().ui.view = crate::ViewMode::Outline;
|
||||
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();
|
||||
|
||||
@@ -12,6 +12,46 @@ pub(crate) fn harness(session: Session, services: Services) -> egui_kittest::Har
|
||||
)
|
||||
}
|
||||
|
||||
/// The production window with the trial's own frame body, for trials that wrap the window's pass
|
||||
/// (inspection records, a discarded first pass). Derefs to the window.
|
||||
pub(crate) struct Framed {
|
||||
app: SlideApp,
|
||||
frame: Box<dyn FnMut(&mut SlideApp, &mut egui::Ui)>,
|
||||
}
|
||||
|
||||
impl std::ops::Deref for Framed {
|
||||
type Target = SlideApp;
|
||||
fn deref(&self) -> &SlideApp {
|
||||
&self.app
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::DerefMut for Framed {
|
||||
fn deref_mut(&mut self) -> &mut SlideApp {
|
||||
&mut self.app
|
||||
}
|
||||
}
|
||||
|
||||
impl eframe::App for Framed {
|
||||
fn raw_input_hook(&mut self, ctx: &egui::Context, raw: &mut egui::RawInput) {
|
||||
SlideApp::raw_input_hook(&mut self.app, ctx, raw);
|
||||
}
|
||||
|
||||
fn ui(&mut self, ui: &mut egui::Ui, _frame: &mut eframe::Frame) {
|
||||
(self.frame)(&mut self.app, ui);
|
||||
}
|
||||
}
|
||||
|
||||
/// Builds the production window on the harness's own context, running `frame` as each pass.
|
||||
pub(crate) fn harness_framed(
|
||||
session: Session,
|
||||
services: Services,
|
||||
builder: egui_kittest::HarnessBuilder<Framed>,
|
||||
frame: impl FnMut(&mut SlideApp, &mut egui::Ui) + 'static,
|
||||
) -> egui_kittest::Harness<'static, Framed> {
|
||||
builder.build_eframe(move |cc| Framed { app: window(cc, session, services, |_| {}), frame: Box::new(frame) })
|
||||
}
|
||||
|
||||
/// Builds on the caller's size and clock, allowing shared file scripts or control services.
|
||||
pub(crate) fn harness_with(
|
||||
session: Session,
|
||||
@@ -19,7 +59,11 @@ pub(crate) fn harness_with(
|
||||
builder: egui_kittest::HarnessBuilder<SlideApp>,
|
||||
adjust: impl FnOnce(&mut Platform),
|
||||
) -> egui_kittest::Harness<'static, SlideApp> {
|
||||
builder.build_eframe(move |cc| {
|
||||
builder.build_eframe(move |cc| window(cc, session, services, adjust))
|
||||
}
|
||||
|
||||
fn window(cc: &mut eframe::CreationContext<'_>, session: Session, services: Services, adjust: impl FnOnce(&mut Platform)) -> SlideApp {
|
||||
{
|
||||
let host = craft::host::Host::builder(craft::host::AppInfo {
|
||||
id: "deckcraft",
|
||||
name: crate::flavor::app_name().into(),
|
||||
@@ -49,7 +93,7 @@ pub(crate) fn harness_with(
|
||||
app.catalog = catalog;
|
||||
app.catalog_generation = generation;
|
||||
app
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl eframe::App for SlideApp {
|
||||
|
||||
Reference in New Issue
Block a user