Files
figcraft/crates/ui-egui/src/resources_tests.rs
T
叶林橦 5f7aea91f9 ui: rebuild the toolbar pill on a 32 pt grid, without the Resources button
Brings #1210 onto main as it stands after #1019 and #1209, and keeps both:

- #1019's flyout caret keeps its 16 pt target, 2 pt clear of its tool (#988).
- #1209's narrow-window handling stays as it landed: the pill is never wider
  than the canvas less a margin and its buttons scroll inside it under a drag
  or the wheel, the help button lifts above it when they'd overlap, and the
  pill still clips to itself rather than floating over the panels.

The design itself, as #1210 proposed it:
- One grid for every state of the pill: 32 pt cells, 8 pt padding, 8 pt between
  top-level items (the divider included), a 1 pt divider as tall as the content,
  16 pt carets, 14 pt mode marks, and a 32 pt mode strip whose current mode is a
  plain inset with no outline.
- The Resources button goes; the left rail's Assets tab, Shift+I, Alt+2 and
  View > Panels > Assets remain the ways into the Assets panel (and the locale
  key, its test and the parity notes go with it).
- The vector edit and shape builder pills move onto the same grid, so a pill
  never changes its spacing as the tool changes.

main_width is now the same walk the pill draws, and a test walks it for the
design and board toolbars: the last item ends exactly PAD from the right edge.
That caught the board pill asking for 8 pt more than it drew.
2026-10-27 12:28:49 +08:00

67 lines
2.3 KiB
Rust

//! Shift+I opens the Assets panel (#710), from a collapsed sidebar and from the version history
//! too — and the toolbar has no Resources button for it any more (the left rail's Assets tab,
//! Shift+I, Alt+2 and View ▸ Panels ▸ Assets are the ways in).
use egui::accesskit::Role;
use egui::{Event, Key, Modifiers};
use figcraft_engine::Session;
use crate::LeftTab;
use crate::layers_drag_tests::Ui;
fn shift_i(u: &mut Ui) {
let modifiers = Modifiers::SHIFT;
u.frame(vec![
Event::Key { key: Key::I, physical_key: None, pressed: true, repeat: false, modifiers },
Event::Key { key: Key::I, physical_key: None, pressed: false, repeat: false, modifiers },
]);
u.frame(vec![]);
}
fn assets_shown(u: &Ui) -> bool {
u.app.ui.left_tab == LeftTab::Assets && !u.app.ui.left_collapsed && !u.app.ui.versions.open
}
/// The three states the sidebar can be in when Shift+I is pressed.
fn starts() -> Vec<(&'static str, Ui)> {
let shown = Ui::new(Session::new());
let mut collapsed = Ui::new(Session::new());
collapsed.app.ui.left_collapsed = true;
let mut versions = Ui::new(Session::new());
crate::versions::open(&mut versions.app);
vec![("layers", shown), ("collapsed", collapsed), ("version history", versions)]
}
#[test]
fn shift_i_opens_the_assets_panel() {
for (name, mut u) in starts() {
u.frame(vec![]);
shift_i(&mut u);
assert!(assets_shown(&u), "{name}: the Assets panel is open");
}
}
/// The toolbar's buttons, as screen readers get them.
fn toolbar_labels(u: &mut Ui) -> Vec<String> {
u.ctx.enable_accesskit();
u.frame(vec![]);
let out = u.frame_output(vec![]);
out.platform_output
.accesskit_update
.expect("an AccessKit update")
.nodes
.iter()
.filter(|(_, n)| n.role() == Role::Button)
.filter_map(|(_, n)| n.label().map(str::to_string))
.collect()
}
#[test]
fn the_toolbar_has_no_resources_button() {
let mut u = Ui::new(Session::new());
let labels = toolbar_labels(&mut u);
// Actions stays (the palette's button); Resources went (#1210).
assert!(labels.iter().any(|l| l == "Actions"), "Actions is in the toolbar: {labels:?}");
assert!(!labels.iter().any(|l| l == "Resources"), "no Resources button: {labels:?}");
}