Skip to content

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

Merge main into #1339; keep both sides of effects_presets.rs, settings.rs

vangel76ea5bd7d171ec
diff --cc crates/ui-egui/src/panels/effects_presets.rs
index 48e6ad43e,8eecfd091..17bfda59c
--- a/crates/ui-egui/src/panels/effects_presets.rs
+++ b/crates/ui-egui/src/panels/effects_presets.rs
@@@ -8,8 -8,8 +8,9 @@@
use crate::i18n::tr;
use egui::{Align2, Color32, Rect, Sense, Stroke, pos2, vec2};
use serde_json::json;
+ use std::sync::Arc;
+use crate::a11y;
use crate::icons::{self, Icon};
use crate::panels::DragPayload;
use crate::theme::Tokens;
@@@ -366,132 -245,13 +367,132 @@@ fn preset_row
icons::paint(lp, Rect::from_center_size(pos2(r.min.x + 58.0, r.center().y), vec2(12.0, 12.0)), Icon::Keyframe, t.text_dim);
highlighted(lp, pos2(r.min.x + 70.0, r.center().y), name, query, &t);
app.auto.add(auto_id, r, name);
+ a11y::tree_item(&resp, name, selected, 3, None);
+ row_focus(app, ui, lp, &resp, r, id);
+ if resp.clicked() {
+ nav_click(ui.ctx(), app, id);
+ }
if resp.double_clicked() {
- *apply = Some(on_apply);
+ *apply = Some(on_apply());
}
}
+/// The list's keys. With a row focused (Tab, a screen reader): Up / Down move between rows,
+/// Home / End go to the first / last, Page Up / Page Down a page, Right opens a folder (then steps
+/// into it) and Left closes it (then steps out to it), Enter and Space apply the row or open /
+/// close the folder. With the mouse's last click in the panel and no widget focused, the arrows
+/// and Enter work the same, so the list is operable without a mouse either way. The focus follows
+/// the cursor, so a screen reader reads each row as it is reached. Returns what to apply.
+fn list_keys(app: &mut EffectcraftApp, ctx: &egui::Context, nav: &Nav, list: Rect) -> Option<Apply> {
+ use egui::Key;
+ // A cursor whose row is gone (a search hid it): the first row is the Tab stop again.
+ if let Some(c) = nav.cursor
+ && !nav.rows.iter().any(|r| r.id == c)
+ {
+ ctx.data_mut(|d| d.remove::<egui::Id>(cursor_id()));
+ ctx.request_repaint();
+ }
+ let focused = ctx.memory(|m| m.focused());
+ let on_row = focused.is_some_and(|f| nav.rows.iter().any(|r| r.id == f || r.star == Some(f)));
+ let by_mouse = focused.is_none() && app.ui.focused == crate::dock::PanelKind::EffectsPresets;
+ if (!on_row && !by_mouse) || app.dialog.is_some() || widgets::any_menu_open(ctx) {
+ return None;
+ }
+ let keys: Vec<Key> = ctx.input(|i| {
+ i.events
+ .iter()
+ .filter_map(|e| match e {
+ egui::Event::Key { key, pressed: true, modifiers, .. } if !modifiers.any() => Some(*key),
+ _ => None,
+ })
+ .collect()
+ });
+ let page = ((list.height() / ROW_H).floor() as usize).saturating_sub(1).max(1);
+ // The row with the keyboard focus is where the keys start (the first Tab lands on a row
+ // before anything is selected); otherwise the cursor.
+ let focus_row = focused.and_then(|f| nav.rows.iter().find(|r| r.id == f || r.star == Some(f))).map(|r| r.id);
+ let mut cursor = focus_row.or_else(|| nav.cursor.filter(|c| nav.rows.iter().any(|r| r.id == *c)));
+ let mut apply = None;
+ let mut moved = false;
+ for key in keys {
+ let at = cursor.and_then(|c| nav.rows.iter().position(|r| r.id == c));
+ let last = nav.rows.len().checked_sub(1)?;
+ let to = match key {
+ Key::ArrowDown => Some(at.map_or(0, |a| a.saturating_add(1).min(last))),
+ Key::ArrowUp => Some(at.map_or(last, |a| a.saturating_sub(1))),
+ Key::Home if on_row => Some(0),
+ Key::End if on_row => Some(last),
+ Key::PageDown if on_row => Some(at.map_or(0, |a| a.saturating_add(page).min(last))),
+ Key::PageUp if on_row => Some(at.map_or(last, |a| a.saturating_sub(page))),
+ Key::ArrowRight | Key::ArrowLeft | Key::Enter | Key::Space if at.is_some() => {
+ let row = at.and_then(|a| nav.rows.get(a))?;
+ let toggle = |app: &mut EffectcraftApp, open: bool| {
+ if let Some((k, _, forced)) = &row.folder
+ && !forced
+ {
+ if open {
+ app.ui.effects_open.insert(k.clone());
+ } else {
+ app.ui.effects_open.remove(k);
+ }
+ }
+ };
+ match (key, &row.folder) {
+ (Key::ArrowRight, Some((_, false, _))) => {
+ toggle(app, true);
+ None
+ }
+ (Key::ArrowRight, Some((_, true, _))) => at.map(|a| a.saturating_add(1).min(last)),
+ (Key::ArrowLeft, Some((_, true, false))) => {
+ toggle(app, false);
+ None
+ }
+ (Key::ArrowLeft, _) => row.parent.and_then(|p| nav.rows.iter().position(|r| r.id == p)),
+ (Key::Enter, Some((_, open, _))) | (Key::Space, Some((_, open, _))) if on_row || key == Key::Enter => {
+ toggle(app, !*open);
+ None
+ }
+ (Key::Enter, None) => {
+ apply = row.apply.clone();
+ None
+ }
+ (Key::Space, None) if on_row => {
+ apply = row.apply.clone();
+ None
+ }
+ _ => None,
+ }
+ }
+ _ => None,
+ };
+ if let Some(to) = to
+ && let Some(row) = nav.rows.get(to)
+ {
+ cursor = Some(row.id);
+ moved = true;
+ }
+ }
+ if moved && let Some(c) = cursor {
+ ctx.data_mut(|d| d.insert_temp(cursor_id(), c));
+ // Scroll the row into view.
+ if let Some(row) = nav.rows.iter().find(|r| r.id == c) {
+ widgets::PanelScroll::reveal(ctx, egui::Id::new("fx-scroll"), row.top, row.top + ROW_H, list.height());
+ }
+ app.ui.focused = crate::dock::PanelKind::EffectsPresets;
+ if on_row {
+ a11y::focus_next_pass(ctx, "fx", c);
+ }
+ ctx.request_repaint();
+ }
+ // The arrows are the list's, not egui's spatial focus moves.
+ if on_row {
+ ctx.memory_mut(|m| m.move_focus(egui::FocusDirection::None));
+ }
+ apply
+}
+
/// User preset files, rescanned every few seconds (and on Refresh List).
- fn user_presets(ctx: &egui::Context, force: bool) -> Vec<PresetFile> {
+ fn user_presets(ctx: &egui::Context, force: bool, scan: impl FnOnce() -> Vec<PresetFile>) -> Arc<Vec<PresetFile>> {
let id = egui::Id::new("fx-user-presets");
let now = ctx.input(|i| i.time);
if !force
@@@ -559,13 -316,7 +561,13 @@@ pub fn show(app: &mut EffectcraftApp, u
ui.separator();
} else {
let resp = ui.selectable_label(false, label);
+ // The ✓ and the padding are the menu's drawing: say it as a state.
+ let checkable = matches!(i, 0 | 1 | 2 | 4 | 6 | 7);
+ a11y::menu_item(&resp, label.trim_start_matches('✓').trim(), checkable.then(|| label.starts_with('✓')));
+ if i == 0 {
+ widgets::focus_when_opened(ui, mpop, &resp);
+ }
- if i == 12 {
+ if label == &copy_label {
app.auto.add("effects.copyPresetsFolderPath", resp.rect, "Copy Presets Folder Path");
}
if resp.clicked() {
@@@ -579,11 -330,13 +581,16 @@@
None
};
if let Some(i) = choice {
+ if widgets::by_keyboard(ui) {
+ menu_resp.request_focus();
+ }
let v = &mut app.ui.effects_view;
match i {
+ i if menu.get(i) == Some(&copy_label) => {
+ if let Err(e) = crate::menus::invoke(app, &ctx, "effects.copyPresetsFolderPath", json!({})) {
+ app.ui.status = e;
+ }
+ }
0 => v.depth = "all".into(),
1 => v.depth = "32".into(),
2 => v.depth = "gpu".into(),
@@@ -644,25 -391,13 +646,25 @@@
categories.push(c);
}
}
- let files: Vec<PresetFile> =
- user_presets(&ctx, force_scan).into_iter().filter(|f| query.is_empty() || f.name.to_lowercase().contains(&query)).collect();
+ let user = user_presets(&ctx, force_scan, || presets_dir().map(|d| scan_presets(&d)).unwrap_or_default());
+ let files: Vec<&PresetFile> = user.iter().filter(|f| query.is_empty() || f.name.to_lowercase().contains(&query)).collect();
let any = !text.is_empty() || !builtin.is_empty() || !files.is_empty();
- if any && folder_row(app, ui, &lp, list, &mut y, "presets", "* Animation Presets", 0.0, searching, None) {
- if !text.is_empty() && folder_row(app, ui, &lp, list, &mut y, "presets/Text", "Text", 14.0, searching, None) {
+ if any && folder_row(app, ui, &lp, list, &mut y, &mut nav, "presets", "* Animation Presets", 1, 0.0, searching, None) {
+ if !text.is_empty() && folder_row(app, ui, &lp, list, &mut y, &mut nav, "presets/Text", "Text", 2, 14.0, searching, None) {
for (id, name) in text {
- preset_row(app, ui, &lp, list, &mut y, &name, &format!("effects.preset.text.{id}"), &query, || Apply::TextPreset(id.clone()), &mut apply);
+ preset_row(
+ app,
+ ui,
+ &lp,
+ list,
+ &mut y,
+ &mut nav,
+ &name,
+ &format!("effects.preset.text.{id}"),
+ &query,
- Apply::TextPreset(id.clone()),
++ || Apply::TextPreset(id.clone()),
+ &mut apply,
+ );
}
}
for cat in &categories {
@@@ -670,22 -405,10 +672,22 @@@
continue;
}
for (id, name, _) in builtin.iter().filter(|(_, _, c)| c == cat) {
- preset_row(app, ui, &lp, list, &mut y, name, &format!("effects.preset.builtin.{id}"), &query, || Apply::Builtin(id.clone()), &mut apply);
+ preset_row(
+ app,
+ ui,
+ &lp,
+ list,
+ &mut y,
+ &mut nav,
+ name,
+ &format!("effects.preset.builtin.{id}"),
+ &query,
- Apply::Builtin(id.clone()),
++ || Apply::Builtin(id.clone()),
+ &mut apply,
+ );
}
}
- if !files.is_empty() && folder_row(app, ui, &lp, list, &mut y, "presets/User", "User Presets", 14.0, searching, None) {
+ if !files.is_empty() && folder_row(app, ui, &lp, list, &mut y, &mut nav, "presets/User", "User Presets", 2, 14.0, searching, None) {
for f in files {
preset_row(
app,
diff --cc crates/ui-egui/src/panels/settings.rs
index 8020dfd3a,28a7c0142..0af1b9d0f
--- a/crates/ui-egui/src/panels/settings.rs
+++ b/crates/ui-egui/src/panels/settings.rs
@@@ -686,19 -664,11 +686,21 @@@ pub fn show(app: &mut EffectcraftApp, c
ui.vertical(|ui| {
ui.set_width(180.0);
egui::ScrollArea::vertical().id_salt("settings-pages").max_height(body_h).auto_shrink([false, false]).show(ui, |ui| {
+ // One Tab stop for the list (the open page); Up / Down / Home / End move
+ // between the pages and the focus goes with them.
+ // The rows touch, so the pointer never falls between two of them.
+ ui.spacing_mut().item_spacing.y = 0.0;
- for p in &all {
- let (r, resp) = ui.allocate_exact_size(vec2(176.0, 24.0), egui::Sense::click());
+ let ctx = ui.ctx().clone();
+ let page_item = |id: &str| egui::Id::new(("settings-page", id.to_string()));
+ let on_list = all.iter().any(|q| ctx.memory(|m| m.has_focus(page_item(q.id))));
+ for (n, p) in all.iter().enumerate() {
let sel = page == p.id;
+ let r = ui.allocate_space(vec2(176.0, 24.0)).1;
+ let resp = ui.interact(r, page_item(p.id), if sel { egui::Sense::click() } else { egui::Sense::CLICK });
+ a11y::list_item(&resp, tr(p.title), sel, n + 1, all.len());
+ if a11y::take_pending_focus(&ctx, "settings", resp.id) {
+ resp.request_focus();
+ }
if sel {
ui.painter().rect_filled(r, 3.0, t.accent);
} else if resp.hovered() {