mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-29 01:34:29 +01:00
Merge pull request #9976 from dotCooCoo/fix/symbols-empty-state-appearance-rows
Panels: Symbols shows its empty hint again; Appearance rows line up
This commit is contained in:
4 files changed
+115
-17
No files matched your search
@@ -30,10 +30,10 @@ use craft::ui::contract::{
|
||||
Bind, CollectionEvent, CollectionResponse, ColumnSpec, FieldLabelRole, ItemCx, ListDrag, MemoProps, PopupKind, Props as _, ReorderMove,
|
||||
ReorderRule, Show as _, ShowCollection as _, ShowContainer as _, SideLabel, ToggleColumn, Trigger, clicked,
|
||||
};
|
||||
use craft::ui::display::{Picture, Shade, Text};
|
||||
use craft::ui::display::{Elide, Picture, Shade, Text};
|
||||
use craft::ui::form::Field;
|
||||
use craft::ui::layout_components::Stack;
|
||||
use craft::ui::list::{List, ListRow, RowDragSpot, RowEvent, RowInk, ThumbAspect, ThumbSize, ThumbTarget, ToggleCell};
|
||||
use craft::ui::list::{List, ListRow, RowDragSpot, RowEvent, RowInk, ThumbAspect, ThumbSize, ThumbTarget, ToggleCell, TreeLeaves};
|
||||
use craft::ui::menu::{Menu, MenuItem, PanelRow};
|
||||
use craft::ui::patterns::form_dialogs::{DialogFields, Param, ParamRows};
|
||||
use craft::ui::patterns::presets::{
|
||||
@@ -403,6 +403,9 @@ const SWATCH_COLUMNS: u16 = 12;
|
||||
const SWATCH_ROWS: u16 = 12;
|
||||
/// The width and height of a stroke row's profile picture, as its aspect.
|
||||
const PROFILE_ASPECT: (u16, u16) = (14, 5);
|
||||
/// The most characters of a stroke's notes that set the notes' column width on every fill and stroke row; longer notes
|
||||
/// are cut at the end and show whole in a tooltip.
|
||||
const NOTES_SAMPLE_CHARS: usize = 16;
|
||||
|
||||
/// The eye column.
|
||||
const EYE: ColumnKey = ColumnKey::new("eye");
|
||||
@@ -543,6 +546,9 @@ fn show_list(
|
||||
let mut list = List::new(tl!("Appearance"))
|
||||
.id(list_id)
|
||||
.tree(true)
|
||||
// The top-level rows without a disclosure (Opacity, an object's effects) keep its column, so their labels
|
||||
// start where the Stroke and Fill labels do.
|
||||
.tree_leaves(TreeLeaves::Aligned)
|
||||
.columns(columns)
|
||||
.deletable(true)
|
||||
.selection(Bind::bound(selection))
|
||||
@@ -827,21 +833,36 @@ fn item_row<'r>(cx: &'r RowCx<'_>, key: RowKey, i: usize) -> ListRow<'r> {
|
||||
link_output(cx.pass, key),
|
||||
);
|
||||
// The first trailing part added is the outermost: the profile closes the row, the swatch sits
|
||||
// nearest the label.
|
||||
if let AppearanceItem::Stroke(st) = it {
|
||||
if let Some(points) = st.profile.as_ref().filter(|p| p.preset_id() != Some("uniform")).map(|p| p.points.clone()) {
|
||||
let aspect = ThumbAspect::new(PROFILE_ASPECT.0, PROFILE_ASPECT.1);
|
||||
let profile = Picture::painter(Label::Empty, aspect, move |painter, rect| stroke::paint_profile(painter, rect, Some(points.as_slice())));
|
||||
// nearest the label. Every fill and stroke row of the stack takes the same room for the profile, the notes and the
|
||||
// weight, kept empty where the row has none, so all their swatches stand in one column.
|
||||
let (any_profile, widest_notes) = trailing_room(stack.map_or(&[], |ap| ap.items.as_slice()));
|
||||
let stroke_layer = match it {
|
||||
AppearanceItem::Stroke(st) => Some(st),
|
||||
_ => None,
|
||||
};
|
||||
match stroke_layer.and_then(shown_profile) {
|
||||
Some(points) => {
|
||||
let profile =
|
||||
Picture::painter(Label::Empty, profile_aspect(), move |painter, rect| stroke::paint_profile(painter, rect, Some(points.as_slice())));
|
||||
row = row.trailing_field(profile, |_| {});
|
||||
}
|
||||
if let Some(notes) = stroke_notes(st) {
|
||||
row = row.trailing_field(Text::new(notes).shade(Shade::Muted), |_| {});
|
||||
}
|
||||
None if any_profile => row = row.trailing_space(Picture::painter(Label::Empty, profile_aspect(), |_, _| {})),
|
||||
None => {}
|
||||
}
|
||||
if let Some(widest) = widest_notes {
|
||||
row = match stroke_layer.and_then(stroke_notes) {
|
||||
Some(notes) => row.trailing_field(Text::new(notes).shade(Shade::Muted).sample(widest).elide(Elide::End), |_| {}),
|
||||
None => row.trailing_space(Text::new(Label::Empty).shade(Shade::Muted).sample(widest)),
|
||||
};
|
||||
}
|
||||
if let Some(st) = stroke_layer {
|
||||
let target = if new_art { WeightTarget::Shown } else { WeightTarget::Item(i) };
|
||||
let pass = cx.pass;
|
||||
row = row.trailing_field(stroke::weight_number(cx.app, Some(st.width)), move |out| {
|
||||
pass.borrow_mut().acts.push(Act::Weight(target, Box::new(out)))
|
||||
});
|
||||
} else {
|
||||
row = row.trailing_space(stroke::weight_number(cx.app, None));
|
||||
}
|
||||
let painted = if new_art { Painted::NewArt { fill } } else { Painted::Item(i) };
|
||||
let pass = cx.pass;
|
||||
@@ -874,6 +895,31 @@ fn stroke_notes(st: &vectorcraft_doc::StrokeLayer) -> Option<String> {
|
||||
(!notes.is_empty()).then(|| notes.join(", "))
|
||||
}
|
||||
|
||||
/// The points of a stroke's width profile, when it has one other than Uniform, which its row draws.
|
||||
fn shown_profile(st: &vectorcraft_doc::StrokeLayer) -> Option<Vec<(f64, f64, f64)>> {
|
||||
st.profile.as_ref().filter(|p| p.preset_id() != Some("uniform")).map(|p| p.points.clone())
|
||||
}
|
||||
|
||||
/// The shape of a stroke row's profile picture.
|
||||
fn profile_aspect() -> ThumbAspect {
|
||||
ThumbAspect::new(PROFILE_ASPECT.0, PROFILE_ASPECT.1)
|
||||
}
|
||||
|
||||
/// The trailing room every fill and stroke row of `items` keeps before its weight: whether a stroke there shows a
|
||||
/// profile, and the longest of the strokes' notes, up to [`NOTES_SAMPLE_CHARS`] characters, which sets the notes' width
|
||||
/// on every row.
|
||||
fn trailing_room(items: &[AppearanceItem]) -> (bool, Option<String>) {
|
||||
let strokes = || {
|
||||
items.iter().filter_map(|it| match it {
|
||||
AppearanceItem::Stroke(st) => Some(st),
|
||||
_ => None,
|
||||
})
|
||||
};
|
||||
let any_profile = strokes().any(|st| shown_profile(st).is_some());
|
||||
let widest = strokes().filter_map(stroke_notes).max_by_key(|notes| notes.chars().count());
|
||||
(any_profile, widest.map(|notes| notes.chars().take(NOTES_SAMPLE_CHARS).collect()))
|
||||
}
|
||||
|
||||
/// An Opacity row: of the object or, under it, of a fill/stroke. "Opacity:" opens the
|
||||
/// Transparency panel on it. A mixed selection whose objects' opacity or blend mode differ
|
||||
/// reads "Mixed".
|
||||
|
||||
@@ -1574,9 +1574,10 @@ mod tests {
|
||||
|
||||
let mut p = PanelHarness::new(app, appearance_and_styles);
|
||||
let hold = |p: &mut PanelHarness| {
|
||||
// The thumbnail is the first part of the object row, at its start.
|
||||
// The thumbnail is the first part of the object row, after the empty disclosure column that lines the row's
|
||||
// label up with the Stroke and Fill labels.
|
||||
let row = p.rect("Rectangle: Drop Target");
|
||||
let (from, to) = (row.left_center() + egui::vec2(14.0, 0.0), p.rect("Drop Target").center());
|
||||
let (from, to) = (row.left_center() + egui::vec2(34.0, 0.0), p.rect("Drop Target").center());
|
||||
p.drag_hold_between(from, to);
|
||||
let carried = drag::active::<PanelDrag>(p.ctx());
|
||||
assert!(
|
||||
|
||||
@@ -578,9 +578,14 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
// Art dropped anywhere on the list becomes a symbol; dropped on a symbol, the browser's
|
||||
// own target takes it.
|
||||
DropAction::<PanelDrag>::new(move |drag| art_of(drag, uid, reverts).is_some()).show(ui, |ui, _| {
|
||||
// With no symbols the body says how to make one, as the other panels' empty states do.
|
||||
if doc.symbols.is_empty() {
|
||||
super::empty_state(ui, "spray-can", tl!("No symbols in this document"), tl!("Select art and click New Symbol to make one."));
|
||||
return None;
|
||||
}
|
||||
let mut state = PresetState::new();
|
||||
state.zoom = zoom;
|
||||
PresetBrowser::new(tl!("Symbols"), Bind::bound(&mut state), &source)
|
||||
let shown = PresetBrowser::new(tl!("Symbols"), Bind::bound(&mut state), &source)
|
||||
.browser_id(browser_id)
|
||||
.selection(Bind::given(selection.clone()))
|
||||
.select(select)
|
||||
@@ -591,13 +596,13 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
.takes_drop(PresetDrop::new::<PanelDrag>(DropPlace::Onto, move |drag: &PanelDrag, _: &DropAt<SymbolKey>| {
|
||||
art_of(drag, uid, reverts).is_some()
|
||||
}))
|
||||
.empty(tl!("No symbols in this document"))
|
||||
.show(ui)
|
||||
.show(ui);
|
||||
Some(shown)
|
||||
})
|
||||
});
|
||||
let taken = shown.settle(|_, list| {
|
||||
let dropped = list.output.dropped.take().map(|drag| (drag, list.output.mods));
|
||||
(dropped, list.inner.take().map(|out| out.events).unwrap_or_default())
|
||||
(dropped, list.inner.take().flatten().map(|out| out.events).unwrap_or_default())
|
||||
});
|
||||
let footer = footer.into_inner();
|
||||
if let Some(opener) = footer.as_ref().and_then(|out| out.responses.get(AT_LIBRARY)) {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
//! Headless frames of panel rows that the framework lays out: controls side by side stay inside the panel's width.
|
||||
|
||||
use super::tests_appearance::app_with_rect;
|
||||
use serde_json::json;
|
||||
|
||||
use super::tests_appearance::{app_with_rect, run};
|
||||
use super::*;
|
||||
use crate::panel_docking::PANEL_MIN_WIDTH;
|
||||
use crate::tests::panel_harness::{Panel, Place, ROOM, floated};
|
||||
@@ -96,6 +98,50 @@ fn the_color_wheel_box_and_its_strip_stay_inside_the_panel() {
|
||||
assert!(field.right() <= ROOM.x && strip.right() <= ROOM.x, "the box {field:?} or its strip {strip:?} runs past the panel");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_symbols_panel_with_no_symbols_says_how_to_make_one() {
|
||||
let panel = Panel::new(app_with_rect(), symbols::show);
|
||||
assert!(panel.shows("No symbols in this document"));
|
||||
assert!(panel.shows("Select art and click New Symbol to make one."), "the empty panel has no hint");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_appearance_swatches_and_labels_line_up() {
|
||||
let panel = Panel::new(app_with_rect(), appearance::show);
|
||||
let (stroke, fill) = (panel.rect("Stroke swatch"), panel.rect("Fill swatch"));
|
||||
assert!((stroke.left() - fill.left()).abs() < 1.0, "the stroke swatch at {stroke:?} and the fill swatch at {fill:?} are in different columns");
|
||||
let opacity = panel.rect("Opacity:");
|
||||
for name in ["Stroke:", "Fill:"] {
|
||||
let at = panel.rect(name);
|
||||
assert!((at.left() - opacity.left()).abs() < 1.0, "Opacity: at {opacity:?} does not start where {name} at {at:?} does");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_fill_swatch_lines_up_with_a_dashed_stroke_that_has_a_profile() {
|
||||
let mut panel = Panel::new(app_with_rect(), appearance::show);
|
||||
run(&mut panel.app(), "stroke.set", json!({"dash": [4, 2], "profile": "lens"}));
|
||||
panel.frame();
|
||||
assert!(panel.shows("Dashed"), "the stroke row shows no notes");
|
||||
let (stroke, fill) = (panel.rect("Stroke swatch"), panel.rect("Fill swatch"));
|
||||
assert!((stroke.left() - fill.left()).abs() < 1.0, "the stroke swatch at {stroke:?} and the fill swatch at {fill:?} are in different columns");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn long_stroke_notes_stay_inside_a_narrow_appearance_panel() {
|
||||
let mut panel = Panel::new(app_with_rect(), appearance::show);
|
||||
let name = "A calligraphic brush with a very long name for the notes";
|
||||
run(&mut panel.app(), "brush.new", json!({"type": "calligraphic", "name": name}));
|
||||
run(&mut panel.app(), "brush.apply", json!({"name": name}));
|
||||
run(&mut panel.app(), "stroke.set", json!({"dash": [4, 2]}));
|
||||
panel.room(egui::vec2(PANEL_MIN_WIDTH, ROOM.y)).frame();
|
||||
let (stroke, fill) = (panel.rect("Stroke swatch"), panel.rect("Fill swatch"));
|
||||
assert!((stroke.left() - fill.left()).abs() < 1.0, "the stroke swatch at {stroke:?} and the fill swatch at {fill:?} are in different columns");
|
||||
for at in [stroke, fill] {
|
||||
assert!(at.right() <= PANEL_MIN_WIDTH, "the swatch at {at:?} runs past the {PANEL_MIN_WIDTH} pt panel");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn align_to_shares_the_distribute_spacing_line_inside_the_align_panel() {
|
||||
let panel = Panel::new(app_with_rect(), align::show);
|
||||
|
||||
Reference in new issue
Block a user