Skip to content

EffectCraft: An open-source motion graphics and compositing tool written by scratch in pure Rust

Merge pull request #130 from storytold/fix/synthetic-modifiers

Brandon Thomas50a89c48e91c
diff --cc crates/ui-egui/src/lib.rs
index 2cc705244,3cd1d031a..746d917bc
--- a/crates/ui-egui/src/lib.rs
+++ b/crates/ui-egui/src/lib.rs
@@@ -543,23 -381,25 +543,42 @@@ impl EffectcraftApp
v
}
+ /// The workspaces the user saved under a new name (built-ins whose changes were saved are
+ /// not repeated), in name order.
+ pub fn saved_workspace_names(&self) -> Vec<String> {
+ self.ui.saved_workspaces.keys().filter(|k| !dock::WORKSPACES.contains(&k.as_str())).cloned().collect()
+ }
+
+ /// The open Gradient Editor's draft (`panels::gradient_editor`): what OK would set.
+ pub fn gradient_draft(&self) -> &panels::gradient_editor::Draft {
+ &self.dialog_state.gradient
+ }
+
+ /// The open Gradient Editor's draft, to edit (tests and automation; the editor's own fields
+ /// do the same).
+ pub fn gradient_draft_mut(&mut self) -> &mut panels::gradient_editor::Draft {
+ &mut self.dialog_state.gradient
+ }
+
+ /// Feed this frame's share of the queued synthetic input (control channel `ui.click`,
+ /// `ui.drag`…) into `raw_input`. Pointer events go one per frame so egui sees press → moves
+ /// → release as a real gesture.
+ pub fn feed_synthetic(&mut self, raw_input: &mut egui::RawInput) {
+ if !self.synthetic.is_empty() {
+ // Pointer events go one per frame so egui sees press → moves → release as a real drag.
+ let pointer = |e: &egui::Event| matches!(e, egui::Event::PointerMoved(_) | egui::Event::PointerButton { .. } | egui::Event::MouseWheel { .. });
+ let n = if pointer(&self.synthetic[0]) {
+ 1
+ } else {
+ self.synthetic
+ .iter()
+ .position(|e| pointer(e) || matches!(e, egui::Event::Key { pressed: false, .. }))
+ .map_or(self.synthetic.len(), |i| if pointer(&self.synthetic[i]) { i.max(1) } else { i + 1 })
+ };
+ raw_input.events.extend(self.synthetic.drain(..n));
+ }
+ }
+
/// Show panel `p` (opening it in its usual place if it is closed), bring it to the front and
/// give it the focus: Window ▸ <panel>.
pub fn show_panel(&mut self, p: PanelKind) {
@@@ -1806,32 -1407,12 +1825,20 @@@ impl EffectcraftApp
impl eframe::App for EffectcraftApp {
fn on_exit(&mut self) {
- // Clean exit: no crash recovery next launch.
- self.session.end_recovery();
+ self.save_workspace_state();
+ // Clean exit: no crash recovery next launch (unless the graphics device was lost with
+ // unsaved changes, which are in the auto-save it offers).
+ if self.device_lost_close != Some(true) {
+ self.session.end_recovery();
+ }
}
- fn raw_input_hook(&mut self, _ctx: &egui::Context, raw_input: &mut egui::RawInput) {
+ fn raw_input_hook(&mut self, ctx: &egui::Context, raw_input: &mut egui::RawInput) {
+ let injected = !self.synthetic.is_empty();
- if injected {
- // Pointer events go one per frame so egui sees press → moves → release as a real drag.
- let pointer = |e: &egui::Event| matches!(e, egui::Event::PointerMoved(_) | egui::Event::PointerButton { .. } | egui::Event::MouseWheel { .. });
- let n = if pointer(&self.synthetic[0]) {
- 1
- } else {
- self.synthetic
- .iter()
- .position(|e| pointer(e) || matches!(e, egui::Event::Key { pressed: false, .. }))
- .map_or(self.synthetic.len(), |i| if pointer(&self.synthetic[i]) { i.max(1) } else { i + 1 })
- };
- raw_input.events.extend(self.synthetic.drain(..n));
- }
+ self.feed_synthetic(raw_input);
+ if pointer_wrap::prepare_input(ctx, raw_input, injected) {
+ self.session.history.merge_key = None;
+ }
}
fn logic(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {