Swatches: thumbnails at production's sizes and the footer split as production

The thumbnail views give the browser zooms of 1/4, 1/3 and 2/3 on the large
thumbnail: 12, 16 and 32 point tiles, production's 11, 15.5 and 30. The
library panels' saved view follows the new zooms. Swatch Libraries, Show
Swatch Kinds and the edit action stand at the footer's start edge; New Color
Group, New Swatch and Delete at its end edge.
This commit is contained in:
bflatastic
2026-11-25 15:21:43 +07:00
parent 4bb9412a03
commit 8414552bc9
3 changed files with 39 additions and 19 deletions
+2 -2
View File
@@ -588,8 +588,8 @@ pub(crate) fn show_window(app: &mut VectorcraftApp, ctx: &egui::Context) {
// PLAN: the zoom slider can set a zoom the five views do not name; it saves as the nearest of them.
fn saved_view(view: PresetView, zoom: f64) -> View {
match (view == PresetView::List, zoom) {
(false, z) if z < 0.625 => View::SmallThumb,
(false, z) if z < 0.875 => View::MediumThumb,
(false, z) if z < 7.0 / 24.0 => View::SmallThumb,
(false, z) if z < 0.5 => View::MediumThumb,
(false, _) => View::LargeThumb,
(true, z) if z < 0.75 => View::SmallList,
(true, _) => View::LargeList,
@@ -76,6 +76,16 @@ pub(crate) fn menu_library_ids<K: LibraryKind>(app: &VectorcraftApp) -> Vec<Stri
out
}
/// A view picked in the browser saves as the view it is: the thresholds of `saved_view` lie between the zooms
/// `View::preset` gives, so retuning one without the other would save another view.
#[test]
fn every_view_saves_as_itself() {
for (view, _) in View::ALL {
let (shown, zoom) = view.preset();
assert_eq!(saved_view(shown, zoom), view);
}
}
fn undo_len(app: &VectorcraftApp) -> usize {
app.session.doc().unwrap().history.undo.len()
}
+27 -17
View File
@@ -65,12 +65,13 @@ impl View {
(View::SmallList, "Small List View"),
(View::LargeList, "Large List View"),
];
/// The browser's view and thumbnail zoom this mode stands for.
/// The browser's view and thumbnail zoom this mode stands for: thumbnails of about 12, 16 and 32 points on the
/// 48-point large thumbnail, the 11, 15.5 and 30 point tiles of production.
pub(crate) fn preset(self) -> (PresetView, f64) {
match self {
View::SmallThumb => (PresetView::Grid, 0.5),
View::MediumThumb => (PresetView::Grid, 0.75),
View::LargeThumb => (PresetView::Grid, 1.0),
View::SmallThumb => (PresetView::Grid, 0.25),
View::MediumThumb => (PresetView::Grid, 1.0 / 3.0),
View::LargeThumb => (PresetView::Grid, 2.0 / 3.0),
View::SmallList => (PresetView::List, 0.5),
View::LargeList => (PresetView::List, 1.0),
}
@@ -751,6 +752,14 @@ fn popup(ui: &mut Ui, label: &'static str, opener: Option<&Response>, mut body:
}
}
// The footer's actions, in order.
const LIBRARIES: usize = 0;
const KINDS: usize = 1;
const EDIT: usize = 2;
const DELETE: usize = 3;
const NEW: usize = 4;
const NEW_GROUP: usize = 5;
/// The panel's footer: Swatch Libraries, Show Swatch Kinds, Edit Color Group or Swatch Options, New Color Group, New
/// Swatch and Delete. Alt-click on Delete deletes without asking; Cmd/Ctrl-click on New Swatch makes a spot color, and
/// Cmd/Ctrl+Shift-click a global process color. Swatches dragged from the list and dropped on New Swatch are
@@ -763,31 +772,32 @@ fn footer(app: &mut VectorcraftApp, ui: &mut Ui) {
let group = actions::selected_group(app, &sel).filter(|_| opts.is_none());
let icon = |id: &'static str| IconSpec::svg(IconId::new(id));
let rows_drag = |d: &PanelDrag| matches!(d, PanelDrag::Paint { rows: Some(_), .. });
// The first action sits at the end edge.
let edit = if group.is_some() {
FooterAction::new(icon("palette"), tl!("Edit or Apply Color Group"))
} else {
FooterAction::new(icon("dc-options"), tl!("Swatch Options")).enabled(opts.is_some())
};
// Libraries, Show Swatch Kinds and the edit action sit at the start edge; Delete at the end edge, then New Swatch
// and New Color Group before it.
let actions = [
FooterAction::new(icon("library"), SwatchLibraries::MENU).pressed(library_panel::any_open::<SwatchLibraries>(&app.ui)),
FooterAction::new(icon("dc-swatch-kinds"), tl!("Show Swatch Kinds")).pressed(kind != Kind::All),
edit,
FooterAction::new(icon("trash-2"), tl!("Delete Swatch"))
.enabled(!del.is_empty())
.takes_drops_disabled(del.is_empty())
.accepts_drops::<PanelDrag>(rows_drag),
FooterAction::new(icon("dc-new-item"), tl!("New Swatch")).accepts_drops::<PanelDrag>(rows_drag),
FooterAction::new(icon("dc-folder"), tl!("New Color Group")),
edit,
FooterAction::new(icon("dc-swatch-kinds"), tl!("Show Swatch Kinds")).pressed(kind != Kind::All),
FooterAction::new(icon("library"), SwatchLibraries::MENU).pressed(library_panel::any_open::<SwatchLibraries>(&app.ui)),
];
let out = FooterBar::actions(actions).show_footer(ui);
let out = FooterBar::actions(actions).at_start(EDIT + 1).show_footer(ui);
match out.picked {
Some(0) if !del.is_empty() => actions::delete(app, del, out.mods.alt),
Some(1) => actions::new_swatch(app, &sel, out.mods),
Some(2) => {
Some(DELETE) if !del.is_empty() => actions::delete(app, del, out.mods.alt),
Some(NEW) => actions::new_swatch(app, &sel, out.mods),
Some(NEW_GROUP) => {
app.run("ui.newColorGroup", json!({"swatches": del})).ok();
}
Some(3) => match (group, opts) {
Some(EDIT) => match (group, opts) {
(Some(g), _) => actions::edit_group(app, &g),
(None, Some(n)) => {
app.run("ui.swatchOptions", json!({"name": n})).ok();
@@ -800,19 +810,19 @@ fn footer(app: &mut VectorcraftApp, ui: &mut Ui) {
&& let Some(drag) = drop.payload::<PanelDrag>()
{
match drop.index {
0 => dnd::on_footer_drop(app, dnd::FooterTarget::Delete, drag),
1 => dnd::on_footer_drop(app, dnd::FooterTarget::New, drag),
DELETE => dnd::on_footer_drop(app, dnd::FooterTarget::Delete, drag),
NEW => dnd::on_footer_drop(app, dnd::FooterTarget::New, drag),
_ => {}
}
}
popup(ui, tl!("Show Swatch Kinds"), out.responses.get(4), |ui| {
popup(ui, tl!("Show Swatch Kinds"), out.responses.get(KINDS), |ui| {
for (k, label) in Kind::ALL {
if item(ui, label, true, Some(k == kind)) {
app.ui.swatches_panel.kind = k;
}
}
});
popup(ui, tl!("Swatch Libraries"), out.responses.get(5), |ui| {
popup(ui, tl!("Swatch Libraries"), out.responses.get(LIBRARIES), |ui| {
ui.set_min_width(200.0);
library_panel::library_menu::<SwatchLibraries>(app, ui);
});