mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-28 09:21:55 +01:00
Dialogs: Artboard Options and the light editor space their groups with the gap tokens
Artboard Options put a fixed 8 pt between its groups, and the light editor a fixed 4 pt below the Move Light button, on top of the row gap. Artboard Options now stacks its groups a section gap apart, and the light editor shows the light list with its sphere and the Light Settings rows as two groups a stack gap apart. No add_space calls remain in the crate.
This commit is contained in:
1 parent
5d70217e0c
commit
da02049ce1
5 files changed
+167
-68
No files matched your search
@@ -23,10 +23,11 @@ use craft::color_ui::ui::{ChosenColor, ColorChoice, NamedColor};
|
||||
use craft::theme::Srgba;
|
||||
use craft::theme::variant::Tone;
|
||||
use craft::ui::choice::Checkbox;
|
||||
use craft::ui::contract::{Bind, Props as _, Show as _, ShowContainer as _};
|
||||
use craft::ui::contract::{Bind, Gap, Props as _, Show as _, ShowContainer as _};
|
||||
use craft::ui::dialog::{DialogId, DialogResult, DialogStack, FieldRefusal, HeldAnswer, HeldOk, StackDialog, dialog_id};
|
||||
use craft::ui::display::Text;
|
||||
use craft::ui::form::Field;
|
||||
use craft::ui::layout_components::Stack;
|
||||
use craft::ui::patterns::form_dialogs::HostRequests; // PLAN: assumed re-export of the host requests the form output carries
|
||||
use craft::ui::patterns::form_dialogs::{FormCx, FormDialog, ResetFooter, ResetPick};
|
||||
use craft::ui::pickers::{Anchor9, ReferencePoint, ReferencePointLook};
|
||||
@@ -391,20 +392,40 @@ fn color_row(
|
||||
/// the marks, the Video Ruler Pixel Aspect Ratio and, under Global, the two preferences. The reference
|
||||
/// point is the one the Transform panel shares (#1876); X and Y are where it lies on the rulers, counted
|
||||
/// from the ruler origin (#1212), and a new Width or Height keeps it where it was.
|
||||
///
|
||||
/// The groups are a section gap apart: the preset, the size and position, the colors, the marks and Global.
|
||||
fn body(ui: &mut Ui, cx: &mut FormCx<'_, '_>, v: &mut ArtboardOptionsValue, s: &Setup) {
|
||||
let lengths = s.lengths;
|
||||
let (was, w0, h0) = (v.placed(), v.width, v.height);
|
||||
let (choice, fit) = artboard_size_controls(ui, &s.presets, w0, h0, Some(s.fit_bounds.map(|b| b.is_some())));
|
||||
let mut refi = v.reference;
|
||||
let picked = choice.is_some();
|
||||
if let Some(choice) = choice {
|
||||
if let Some((w, h)) = choice.size_for(w0, h0) {
|
||||
v.set_rect(artboard_rect(was, refi, None, None, Some(w), Some(h), false));
|
||||
Stack::new().gap(Gap::Section).fill_width().show(ui, |ui, _| {
|
||||
let (was, w0, h0) = (v.placed(), v.width, v.height);
|
||||
let (choice, fit) = artboard_size_controls(ui, &s.presets, w0, h0, Some(s.fit_bounds.map(|b| b.is_some())));
|
||||
let picked = choice.is_some();
|
||||
if let Some(choice) = choice {
|
||||
if let Some((w, h)) = choice.size_for(w0, h0) {
|
||||
v.set_rect(artboard_rect(was, v.reference, None, None, Some(w), Some(h), false));
|
||||
}
|
||||
v.size_choice = Some(choice);
|
||||
(v.ref_x, v.ref_y, v.fit) = (v.reference % 3, v.reference / 3, false);
|
||||
}
|
||||
v.size_choice = Some(choice);
|
||||
(v.ref_x, v.ref_y, v.fit) = (refi % 3, refi / 3, false);
|
||||
}
|
||||
ui.add_space(8.0);
|
||||
Stack::new().fill_width().show(ui, |ui, _| place_rows(ui, v, s, (was, w0, h0), picked, fit));
|
||||
Stack::new().fill_width().show(ui, |ui, _| {
|
||||
background_row(ui, cx, v, s);
|
||||
guide_label_row(ui, cx, v);
|
||||
});
|
||||
Stack::new().fill_width().show(ui, |ui, _| mark_rows(ui, v));
|
||||
Stack::new().fill_width().show(ui, |ui, _| {
|
||||
Text::new(tl!("Global")).show(ui);
|
||||
check(ui, tl!("Fade Region Outside Artboard"), FADE, &mut v.fade);
|
||||
check(ui, tl!("Update While Dragging"), UPDATE_WHILE_DRAGGING, &mut v.update_while_dragging);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/// Name, Width and Height, the reference point with X and Y, and a Fit chosen from the Preset menu. `was`, `w0` and
|
||||
/// `h0` are the artboard's rectangle, width and height before this pass's edits; `picked` is whether a size was chosen
|
||||
/// this pass.
|
||||
fn place_rows(ui: &mut Ui, v: &mut ArtboardOptionsValue, s: &Setup, (was, w0, h0): (Rect, f64, f64), picked: bool, fit: Option<bool>) {
|
||||
let lengths = s.lengths;
|
||||
let mut refi = v.reference;
|
||||
let name = Label::from(tl!("Name:"));
|
||||
Field::new(name.clone()).id_salt("name").show(ui, |ui, _| {
|
||||
TextField::new(name.clone(), Bind::bound(&mut v.name)).show(ui);
|
||||
@@ -450,10 +471,10 @@ fn body(ui: &mut Ui, cx: &mut FormCx<'_, '_>, v: &mut ArtboardOptionsValue, s: &
|
||||
v.set_rect(bounds);
|
||||
(v.fit, v.size_choice) = (true, None);
|
||||
}
|
||||
ui.add_space(8.0);
|
||||
background_row(ui, cx, v, s);
|
||||
guide_label_row(ui, cx, v);
|
||||
ui.add_space(8.0);
|
||||
}
|
||||
|
||||
/// The marks and the Video Ruler Pixel Aspect Ratio.
|
||||
fn mark_rows(ui: &mut Ui, v: &mut ArtboardOptionsValue) {
|
||||
check(ui, tl!("Show Center Mark"), "showCenterMark", &mut v.show_center_mark);
|
||||
check(ui, tl!("Show Cross Hairs"), "showCrossHairs", &mut v.show_cross_hairs);
|
||||
check(ui, tl!("Show Video Safe Areas"), "showVideoSafeAreas", &mut v.show_video_safe_areas);
|
||||
@@ -471,10 +492,6 @@ fn body(ui: &mut Ui, cx: &mut FormCx<'_, '_>, v: &mut ArtboardOptionsValue, s: &
|
||||
v.pixel_aspect = n;
|
||||
}
|
||||
});
|
||||
ui.add_space(8.0);
|
||||
Text::new(tl!("Global")).show(ui);
|
||||
check(ui, tl!("Fade Region Outside Artboard"), FADE, &mut v.fade);
|
||||
check(ui, tl!("Update While Dragging"), UPDATE_WHILE_DRAGGING, &mut v.update_while_dragging);
|
||||
}
|
||||
|
||||
/// Background Color: None, White and Black (in the document's color mode), Custom and Select Custom Color….
|
||||
|
||||
@@ -9,9 +9,9 @@ use craft::behavior::{DisplayOrder, ItemSource, SelectionChange};
|
||||
use craft::theme::Srgba;
|
||||
use craft::ui::buttons::Button;
|
||||
use craft::ui::contract::Entry;
|
||||
use craft::ui::contract::{Bind, CollectionEvent, Props as _, Show as _, ShowCollection as _, ShowContainer as _, clicked};
|
||||
use craft::ui::layout_components::Row;
|
||||
use craft::ui::patterns::form_dialogs::{DialogFields, FieldValue, HostedParamDialog, Param, ParamKind, ParamRows};
|
||||
use craft::ui::contract::{Bind, CollectionEvent, Gap, Props as _, Show as _, ShowCollection as _, ShowContainer as _, clicked};
|
||||
use craft::ui::layout_components::{Row, Stack};
|
||||
use craft::ui::patterns::form_dialogs::{CustomContext, DialogFields, FieldValue, HostedParamDialog, Param, ParamKind, ParamRows};
|
||||
use craft::ui::pickers::Select;
|
||||
use craft::ui::runtime::env::LengthUnits;
|
||||
use craft::ui::runtime::env::UnitKind;
|
||||
@@ -727,51 +727,18 @@ pub(crate) fn light_editor(_data: &Data, place: Place, classic: bool) -> Param {
|
||||
fields.remove("__lightPick");
|
||||
set_light_value(fields, "lightColor", json!(hex));
|
||||
}
|
||||
// The list with its buttons and sphere, then the selected light's settings, a stack gap apart.
|
||||
super::form::stacked(ui, fields, |ui, fields| {
|
||||
let mut list = explicit_lights(fields).unwrap_or_else(|| vec![light_record(fields)]);
|
||||
let mut index = light_index(fields, list.len());
|
||||
let titles: Vec<String> = (1..=list.len()).map(|i| format!("{} {i}", c3("Light"))).collect();
|
||||
if let Some(next) = pick(ui, tl!("Lights"), &titles, Some(index), None) {
|
||||
index = next;
|
||||
}
|
||||
// Add Light is off while a setting of the single light is mixed.
|
||||
let mixed = explicit_lights(fields).is_none() && LIGHT_KEYS.iter().any(|(_, key)| fields.is_mixed(key));
|
||||
// The row's body may run more than once in a pass: it reports the presses, which apply after it.
|
||||
let (mut add, mut delete) = (false, false);
|
||||
Row::new().show(ui, |ui, _| {
|
||||
add = pressed(ui, tl!("Add Light"), list.len() < vectorcraft_three_d::MAX_LIGHTS && !mixed, None);
|
||||
delete = pressed(ui, tl!("Delete Light"), list.len() > 1, None);
|
||||
});
|
||||
if add {
|
||||
let mut added = selected_light(fields);
|
||||
let defaults = vectorcraft_effects::default_params(fields.text("__effect").unwrap_or_default()).unwrap_or(json!({}));
|
||||
for (_, key) in LIGHT_KEYS {
|
||||
if let Some(value) = defaults.get(key) {
|
||||
set_value(&mut added, key, value);
|
||||
}
|
||||
Stack::new().gap(Gap::Stack).show(ui, |ui, _| {
|
||||
Stack::new().show(ui, |ui, _| light_list(ui, fields, cx, place, classic));
|
||||
let mut selected = selected_light(fields);
|
||||
let before = light_record(&selected);
|
||||
let out = ParamRows::new(tl!("Light Settings"), &settings, Bind::bound(&mut selected)).show(ui);
|
||||
cx.gesture(&out.events);
|
||||
if light_record(&selected) != before {
|
||||
store_selected(fields, &selected);
|
||||
}
|
||||
set_value(&mut added, "lightRotation", &json!(0.0));
|
||||
set_value(&mut added, "lightHeight", &json!(90.0));
|
||||
list.push(light_record(&added));
|
||||
index = list.len() - 1;
|
||||
fields.set("lights", FieldValue::Json(Value::Array(list.clone())));
|
||||
}
|
||||
if delete && index < list.len() {
|
||||
list.remove(index);
|
||||
index = index.min(list.len().saturating_sub(1));
|
||||
fields.set("lights", FieldValue::Json(Value::Array(list.clone())));
|
||||
}
|
||||
fields.set("__light", i64::try_from(index).unwrap_or(0));
|
||||
if place == Place::Panel || classic {
|
||||
super::revolve_lights::sphere(ui, fields, cx, classic);
|
||||
}
|
||||
let mut selected = selected_light(fields);
|
||||
let before = light_record(&selected);
|
||||
let out = ParamRows::new(tl!("Light Settings"), &settings, Bind::bound(&mut selected)).show(ui);
|
||||
cx.gesture(&out.events);
|
||||
if light_record(&selected) != before {
|
||||
store_selected(fields, &selected);
|
||||
}
|
||||
});
|
||||
})
|
||||
})
|
||||
.companions(LIGHT_KEYS.iter().map(|(_, k)| *k).chain(["__light", "__lightPick"]))
|
||||
@@ -779,6 +746,47 @@ pub(crate) fn light_editor(_data: &Data, place: Place, classic: bool) -> Param {
|
||||
.full_width()
|
||||
}
|
||||
|
||||
/// The light list with Add Light and Delete Light, and the sphere where `place` and `classic` show it.
|
||||
fn light_list(ui: &mut egui::Ui, fields: &mut DialogFields, cx: &mut CustomContext, place: Place, classic: bool) {
|
||||
let mut list = explicit_lights(fields).unwrap_or_else(|| vec![light_record(fields)]);
|
||||
let mut index = light_index(fields, list.len());
|
||||
let titles: Vec<String> = (1..=list.len()).map(|i| format!("{} {i}", c3("Light"))).collect();
|
||||
if let Some(next) = pick(ui, tl!("Lights"), &titles, Some(index), None) {
|
||||
index = next;
|
||||
}
|
||||
// Add Light is off while a setting of the single light is mixed.
|
||||
let mixed = explicit_lights(fields).is_none() && LIGHT_KEYS.iter().any(|(_, key)| fields.is_mixed(key));
|
||||
// The row's body may run more than once in a pass: it reports the presses, which apply after it.
|
||||
let (mut add, mut delete) = (false, false);
|
||||
Row::new().show(ui, |ui, _| {
|
||||
add = pressed(ui, tl!("Add Light"), list.len() < vectorcraft_three_d::MAX_LIGHTS && !mixed, None);
|
||||
delete = pressed(ui, tl!("Delete Light"), list.len() > 1, None);
|
||||
});
|
||||
if add {
|
||||
let mut added = selected_light(fields);
|
||||
let defaults = vectorcraft_effects::default_params(fields.text("__effect").unwrap_or_default()).unwrap_or(json!({}));
|
||||
for (_, key) in LIGHT_KEYS {
|
||||
if let Some(value) = defaults.get(key) {
|
||||
set_value(&mut added, key, value);
|
||||
}
|
||||
}
|
||||
set_value(&mut added, "lightRotation", &json!(0.0));
|
||||
set_value(&mut added, "lightHeight", &json!(90.0));
|
||||
list.push(light_record(&added));
|
||||
index = list.len() - 1;
|
||||
fields.set("lights", FieldValue::Json(Value::Array(list.clone())));
|
||||
}
|
||||
if delete && index < list.len() {
|
||||
list.remove(index);
|
||||
index = index.min(list.len().saturating_sub(1));
|
||||
fields.set("lights", FieldValue::Json(Value::Array(list.clone())));
|
||||
}
|
||||
fields.set("__light", i64::try_from(index).unwrap_or(0));
|
||||
if place == Place::Panel || classic {
|
||||
super::revolve_lights::sphere(ui, fields, cx, classic);
|
||||
}
|
||||
}
|
||||
|
||||
/// The light editor's set-time rule: a light setting set from outside goes to the selected light, as its rows do.
|
||||
fn set_light_field(fields: &mut DialogFields, key: &str, value: Value) -> Result<(), String> {
|
||||
if LIGHT_KEYS.iter().any(|(_, k)| *k == key) {
|
||||
|
||||
@@ -432,7 +432,6 @@ pub(crate) fn sphere(ui: &mut egui::Ui, fields: &mut DialogFields, cx: &mut Cust
|
||||
moved.push(craft::behavior::EditEvent::set(craft::behavior::Mixed::Same(behind), !behind, text.into(), None));
|
||||
cx.gesture(&moved);
|
||||
}
|
||||
ui.add_space(4.0);
|
||||
out.edit.response
|
||||
}
|
||||
|
||||
|
||||
@@ -1222,3 +1222,44 @@ fn select_all_artboards_chooses_the_tool_and_needs_a_document() {
|
||||
let mut empty = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default()));
|
||||
assert_eq!(empty.run("artboard.selectAll", json!({})).unwrap_err(), "no document");
|
||||
}
|
||||
|
||||
thread_local! {
|
||||
/// The row and section gaps the last frame's interface resolved.
|
||||
static GAPS: std::cell::Cell<(f32, f32)> = const { std::cell::Cell::new((0.0, 0.0)) };
|
||||
}
|
||||
|
||||
/// Artboard Options shows its groups (the preset, the size and position, the colors, the marks and Global) a
|
||||
/// section gap apart, and the rows inside a group a row gap apart.
|
||||
#[test]
|
||||
fn artboard_options_groups_are_a_section_gap_apart() {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.session.execute("file.new", &json!({"width": 200, "height": 150})).unwrap();
|
||||
let mut panel = crate::tests::panel_harness::Panel::new(app, |app, ui| {
|
||||
let gap = craft::ui::runtime::env::Env::of(ui).tokens.space.gap;
|
||||
GAPS.with(|c| c.set((gap.row, gap.section)));
|
||||
crate::tests::picks::dialogs(app, ui);
|
||||
});
|
||||
panel.room(egui::vec2(800.0, 1200.0));
|
||||
panel.app().run("tool.options", json!({"tool": "artboard"})).unwrap();
|
||||
panel.frame();
|
||||
panel.frame();
|
||||
let (row, section) = GAPS.with(std::cell::Cell::get);
|
||||
assert!(row > 0.0 && section > row, "the interface resolved its gaps: row {row}, section {section}");
|
||||
let between = |upper: &str, lower: &str| panel.rect(lower).min.y - panel.rect(upper).max.y;
|
||||
let groups =
|
||||
[("Preset:", "Name:"), ("Y:", "Background Color:"), ("Guide Label:", "Show Center Mark"), ("Video Ruler Pixel Aspect Ratio:", "Global")];
|
||||
for (upper, lower) in groups {
|
||||
let gap = between(upper, lower);
|
||||
assert!((gap - section).abs() < 0.01, "{upper} to {lower}: {gap} apart, the section gap is {section}");
|
||||
}
|
||||
let rows = [
|
||||
("Name:", "Width:"),
|
||||
("Background Color:", "Guide Label:"),
|
||||
("Show Center Mark", "Show Cross Hairs"),
|
||||
("Global", "Fade Region Outside Artboard"),
|
||||
];
|
||||
for (upper, lower) in rows {
|
||||
let gap = between(upper, lower);
|
||||
assert!((gap - row).abs() < 0.01, "{upper} to {lower}: {gap} apart, the row gap is {row}");
|
||||
}
|
||||
}
|
||||
@@ -1109,6 +1109,40 @@ fn the_lighting_widget_selects_a_light_and_moves_it_behind_the_object() {
|
||||
assert_eq!(undo_len(&app.borrow()), history + 2);
|
||||
}
|
||||
|
||||
/// The lights' list, buttons and sphere are one group and the selected light's settings another, a stack gap apart;
|
||||
/// the rows inside the first group are a row gap apart.
|
||||
#[test]
|
||||
fn the_light_settings_are_a_stack_gap_below_the_sphere_and_its_button() {
|
||||
let gaps = Rc::new(std::cell::Cell::new((0.0, 0.0)));
|
||||
let seen = Rc::clone(&gaps);
|
||||
Fixture::new(move |ui| {
|
||||
let gap = craft::ui::runtime::env::Env::of(ui).tokens.space.gap;
|
||||
seen.set((gap.row, gap.stack));
|
||||
})
|
||||
.frame(vec![]);
|
||||
let (row, stack) = gaps.get();
|
||||
assert!(row > 0.0 && stack > row, "the interface resolved its gaps: row {row}, stack {stack}");
|
||||
let (_app, fixture) = lighting(json!({}));
|
||||
let tree = fixture.tree();
|
||||
let rect = |name: &str, role: craft::ui::contract::Role| {
|
||||
tree.keys()
|
||||
.into_iter()
|
||||
.find(|key| tree.name_of(*key) == Some(name) && tree.role_of(*key) == Some(role))
|
||||
.and_then(|key| fixture.target(key))
|
||||
.unwrap_or_else(|| panic!("the panel shows {name}"))
|
||||
.rect
|
||||
};
|
||||
let (sphere, button, settings) = (
|
||||
rect("Lights", craft::ui::contract::Role::GROUP),
|
||||
rect("Move Light to Back", craft::ui::contract::Role::BUTTON),
|
||||
rect("Light Settings", craft::ui::contract::Role::GROUP),
|
||||
);
|
||||
let below_button = settings.min.y - button.max.y;
|
||||
assert!((below_button - stack).abs() < 0.01, "the settings are {below_button} below the button, the stack gap is {stack}");
|
||||
let below_sphere = button.min.y - sphere.max.y;
|
||||
assert!((below_sphere - row).abs() < 0.01, "the button is {below_sphere} below the sphere, the row gap is {row}");
|
||||
}
|
||||
|
||||
/// A light the pointer took has the keyboard focus: the arrow keys raise and lower it and turn it
|
||||
/// around the object, 1° a press or 15° with Shift, changing only the setting each press moves, one
|
||||
/// undo step a frame, and a press at a limit records nothing.
|
||||
|
||||
Reference in new issue
Block a user