G2: improve editing reliability and Windows rendering fidelity

This commit is contained in:
Dexter
2026-10-06 00:00:31 -05:00
parent b46be83ab4
commit 39e6907b5f
101 changed files with 1727 additions and 351 deletions
@@ -19,6 +19,24 @@ pub struct LayerStyleState {
pub layer: u64,
pub selected: String,
pub undo_mark: usize,
checkpoint: Option<Checkpoint>,
}
#[derive(Clone)]
struct Checkpoint {
project: std::sync::Arc<effectcraft_engine::project::Project>,
history: effectcraft_engine::history::History,
}
impl std::fmt::Debug for Checkpoint {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Checkpoint").field("undo_steps", &self.history.undo.len()).finish_non_exhaustive()
}
}
fn checkpoint(app: &mut EffectcraftApp) -> Checkpoint {
app.session.history.merge_key = None;
Checkpoint { project: app.session.project.clone(), history: app.session.history.clone() }
}
/// Open the dialog on the first selected (or given) layer, showing `style` (a style id;
@@ -35,7 +53,8 @@ pub fn open(app: &mut EffectcraftApp, params: &Value) -> Result<(), String> {
if style != BLENDING && !STYLES.iter().any(|s| s.0 == style) {
return Err(format!("unknown layer style `{style}`"));
}
app.dialog_state.layer_style = LayerStyleState { layer, selected: style, undo_mark: app.session.history.undo.len() };
let checkpoint = checkpoint(app);
app.dialog_state.layer_style = LayerStyleState { layer, selected: style, undo_mark: app.session.history.undo.len(), checkpoint: Some(checkpoint) };
app.dialog = Some(Dialog::LayerStyles);
Ok(())
}
@@ -48,10 +67,12 @@ pub fn route(app: &mut EffectcraftApp, id: &str, params: &Value) -> Result<bool,
return Ok(false);
}
let mark = app.session.history.undo.len();
let checkpoint = checkpoint(app);
app.session.execute(id, json!({})).map_err(|e| e.to_string())?;
open(app, &json!({"style": style}))?;
// Cancel also removes the style just added.
app.dialog_state.layer_style.undo_mark = mark;
app.dialog_state.layer_style.checkpoint = Some(checkpoint);
Ok(true)
}
@@ -214,13 +235,17 @@ pub fn select(app: &mut EffectcraftApp, style: &str) {
/// Close the dialog: OK keeps the edits, Cancel undoes everything done since it opened.
pub fn finish(app: &mut EffectcraftApp, ok: bool) {
if !ok {
let mark = app.dialog_state.layer_style.undo_mark;
while app.session.history.undo.len() > mark {
if !app.session.undo() {
break;
}
if let Some(checkpoint) = app.dialog_state.layer_style.checkpoint.take()
&& !ok
{
let changed = !std::sync::Arc::ptr_eq(&app.session.project, &checkpoint.project);
app.session.project = checkpoint.project;
app.session.history = checkpoint.history;
app.session.sanitize_state();
if changed {
app.session.bump();
}
}
app.session.history.merge_key = None;
app.dialog = None;
}