mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-06 05:53:08 -05:00
Merge pull request #10796
Co-authored-by: autocraft-bot[bot] <354215646+autocraft-bot[bot]@users.noreply.github.com>
This commit is contained in:
commit
12b9b654ca
2 files changed
+36
No files matched your search
@@ -32,6 +32,7 @@ use craft::ui::primitives::{ContentPainterCx, IconSpec};
|
||||
use craft::ui::runtime::access::PopupKind;
|
||||
use craft::ui::runtime::commands::{CommandRef, CommandState, CommandStates};
|
||||
use craft::ui::sections::{FooterAction, FooterBar, FooterOutput, Panel};
|
||||
use craft::ui::tile_grid::TileZoom;
|
||||
use egui::{Rect, Ui};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::{Value, json};
|
||||
@@ -736,6 +737,7 @@ fn body<K: LibraryKind>(app: &mut VectorcraftApp, ui: &mut Ui, id: &str) {
|
||||
.footer(|ui, _| *footer_out.borrow_mut() = Some(footer_bar::<K>(any).show_footer(ui)))
|
||||
.show(ui, |ui, _| {
|
||||
PresetBrowser::new(title.clone(), Bind::bound(&mut state), &source)
|
||||
.thumb_range(TileZoom::bounded(View::SmallThumb.preset().1, 5.0, 1.0 / 12.0, 1.0))
|
||||
.toolbar(true)
|
||||
.search(!hide_find)
|
||||
.select(SelectMode::Multi)
|
||||
|
||||
@@ -101,6 +101,40 @@ fn every_view_saves_as_itself() {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn library_menu_views_survive_redraw_and_reopening() {
|
||||
let mut app = app();
|
||||
let ctx = context();
|
||||
let panel = panel_of(app.run("window.swatchLibrary", json!({"library": "pastels"})).unwrap());
|
||||
let draw = |app: &mut VectorcraftApp, ui: &mut Ui| show(app, ui, &panel);
|
||||
for (view, label) in View::ALL.into_iter().rev() {
|
||||
let command = menu_entries(&app, &panel)
|
||||
.into_iter()
|
||||
.find_map(|row| match row {
|
||||
MenuEntry::Row { command, label: name, .. } if name == label => Some(command),
|
||||
_ => None,
|
||||
})
|
||||
.expect("library view menu row");
|
||||
app.run(&command.id, command.params).unwrap();
|
||||
draw_frame(&mut app, &ctx, &draw, vec![]);
|
||||
draw_frame(&mut app, &ctx, &draw, vec![]);
|
||||
assert_eq!(settings(&app.ui, "swatches", "pastels").unwrap().view, Some(view), "{label}");
|
||||
if matches!(view, View::SmallThumb | View::MediumThumb) {
|
||||
app.run("window.panel.close", json!({"panel": panel})).unwrap();
|
||||
assert!(!is_open(&app.ui, &panel));
|
||||
let reopened = panel_of(app.run("window.swatchLibrary", json!({"library": "pastels"})).unwrap());
|
||||
assert_eq!(reopened, panel);
|
||||
// A fresh context excludes browser state cached before the close.
|
||||
let reopened_ctx = context();
|
||||
draw_frame(&mut app, &reopened_ctx, &draw, vec![]);
|
||||
assert_eq!(settings(&app.ui, "swatches", "pastels").unwrap().view, Some(view), "{label} after reopening");
|
||||
let state_id = egui::Id::unique(("library-panel-state", &panel));
|
||||
let browser = reopened_ctx.data(|d| d.get_temp::<PresetState<LibraryKey>>(state_id)).expect("the reopened Pastels browser drew");
|
||||
assert_eq!(saved_view(browser.view, browser.zoom), view, "{label} in the reopened browser");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn undo_len(app: &VectorcraftApp) -> usize {
|
||||
app.session.doc().unwrap().history.undo.len()
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user