mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-04 19:41:36 -05:00
plugins-w11: net change of 2 commits
- plugins-w11: written from its sheet - plugins-w11: repair 1
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
<!-- @license lucide-static v1.49.0 - ISC -->
|
||||
<svg
|
||||
class="lucide lucide-circle-off"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="24"
|
||||
height="24"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="2"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<path d="m2 2 20 20" />
|
||||
<path d="M8.35 2.69A10 10 0 0 1 21.3 15.65" />
|
||||
<path d="M19.08 19.08A10 10 0 1 1 4.92 4.92" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 414 B |
+216
-187
@@ -3,25 +3,41 @@
|
||||
//! when a shape tool (`rectangle`, `roundedRectangle`, `ellipse`, `polygon`, `star`, `spiral`,
|
||||
//! `box3d`) is active.
|
||||
|
||||
use std::ops::RangeInclusive;
|
||||
|
||||
use craft::behavior::{IconId, NumberCodec};
|
||||
use craft::keymap::CommandRef;
|
||||
use craft::ui::buttons::{Button, ToggleButton};
|
||||
use craft::ui::choice::Segmented;
|
||||
use craft::ui::contract::{Bind, EditResponse, Entry, Props as _, Show as _, ShowContainer as _, SideLabel};
|
||||
use craft::ui::display::Divider;
|
||||
use craft::ui::form::Field;
|
||||
use craft::ui::layout_components::Row;
|
||||
use craft::ui::runtime::env::{Env, LengthUnits, UnitKind};
|
||||
use craft::ui::text::NumberField;
|
||||
use egui::Ui;
|
||||
use serde_json::{Value, json};
|
||||
use vectorcraft_geom::shapes::EllipseMode;
|
||||
use vectorcraft_tools::addons::box3d::{self, CustomShape};
|
||||
|
||||
use crate::chrome::Fit;
|
||||
use crate::canvas::rulers::general_lengths;
|
||||
use crate::chrome::rank;
|
||||
// PLAN: assumed `crate::edits::{apply_edits, EditPath}` (wg.A16, widgets-w13).
|
||||
use crate::edits::{self, EditPath};
|
||||
use crate::menus::Item;
|
||||
use crate::theme::Tokens;
|
||||
use crate::{VectorcraftApp, widgets};
|
||||
use crate::VectorcraftApp;
|
||||
|
||||
/// A choice's value, its label and its icon name.
|
||||
type Choice = (&'static str, &'static str, &'static str);
|
||||
|
||||
pub fn menu() -> Vec<Item> {
|
||||
vec![Item::Cmd("3D Box Tool", "tool.select", json!({"tool": box3d::ID}))]
|
||||
}
|
||||
|
||||
/// Draw context-sensitive shape customization controls in the top Control bar when a shape tool is
|
||||
/// active. Returns `true` when a shape tool is active. Each button, and each label with its field,
|
||||
/// shows only while the row has room for it and `reserve` after it, and the controls after one left
|
||||
/// out are left out too.
|
||||
pub fn control_bar(app: &mut VectorcraftApp, ui: &mut Ui, reserve: f32) -> bool {
|
||||
/// active. Returns `true` when a shape tool is active. Every member is a ranked row, so a narrow bar
|
||||
/// leaves members out from the reading end, last first.
|
||||
pub fn control_bar(app: &mut VectorcraftApp, ui: &mut Ui) -> bool {
|
||||
let tool = app.session.tool_id().to_string();
|
||||
if !matches!(tool.as_str(), "rectangle" | "roundedRectangle" | "ellipse" | "polygon" | "star" | "spiral" | "box3d") {
|
||||
return false;
|
||||
@@ -32,58 +48,138 @@ pub fn control_bar(app: &mut VectorcraftApp, ui: &mut Ui, reserve: f32) -> bool
|
||||
st.selection.objects.iter().find_map(|&id| st.doc.node(id).and_then(|n| CustomShape::read_for_update(n, active_shape == "spiral")))
|
||||
});
|
||||
|
||||
let fit = &mut Fit::new(reserve);
|
||||
divider(ui);
|
||||
if tool == "box3d" {
|
||||
for (s_id, lbl, icon) in [
|
||||
("box3d", "3D Box", "box"),
|
||||
const SHAPES: [Choice; 6] = [
|
||||
("box3d", "3D Box", "web_colors"),
|
||||
("rectangle", "Rectangle", "square"),
|
||||
("ellipse", "Ellipse", "dc-ellipse"),
|
||||
("polygon", "Polygon", "dc-polygon"),
|
||||
("star", "Star", "star"),
|
||||
("spiral", "Spiral", "tornado"),
|
||||
] {
|
||||
if fit.room(ui, &[22.0]) && widgets::icon_button(ui, icon, tl!(lbl), active_shape == s_id, 22.0).clicked() {
|
||||
app.run("tool.setOption", json!({ "key": "shape", "value": s_id })).ok();
|
||||
}
|
||||
];
|
||||
if let Some(shape) = choice(ui, "Shape", &active_shape, &SHAPES) {
|
||||
app.run("tool.setOption", json!({ "key": "shape", "value": shape })).ok();
|
||||
}
|
||||
fit.separator(ui);
|
||||
divider(ui);
|
||||
}
|
||||
// The tools with live shape widgets: Hide/Show Shape Widgets first, so a narrow bar leaves out
|
||||
// the shape's fields before it.
|
||||
if vectorcraft_tools::shape::shows_shape_widgets(&tool) {
|
||||
shape_widgets_button(app, ui, fit);
|
||||
fit.separator(ui);
|
||||
// The command's own title is the label, and a click runs the command.
|
||||
member(ui, |ui| {
|
||||
Button::command(CommandRef::new("view.shapeWidgets")).show(ui);
|
||||
});
|
||||
divider(ui);
|
||||
}
|
||||
|
||||
match active_shape.as_str() {
|
||||
"ellipse" => draw_ellipse_controls(app, ui, fit, &opts, selected_custom),
|
||||
"rectangle" | "roundedRectangle" => draw_rectangle_controls(app, ui, fit, &opts, selected_custom),
|
||||
"polygon" | "star" => draw_polygon_controls(app, ui, fit, &opts, &active_shape, selected_custom),
|
||||
"spiral" => draw_spiral_controls(app, ui, fit, &opts, selected_custom),
|
||||
"box3d" => draw_box3d_controls(app, ui, fit, &opts, selected_custom),
|
||||
"ellipse" => draw_ellipse_controls(app, ui, &opts, selected_custom),
|
||||
"rectangle" | "roundedRectangle" => draw_rectangle_controls(app, ui, &opts, selected_custom),
|
||||
"polygon" | "star" => draw_polygon_controls(app, ui, &opts, &active_shape, selected_custom),
|
||||
"spiral" => draw_spiral_controls(app, ui, &opts, selected_custom),
|
||||
"box3d" => draw_box3d_controls(app, ui, &opts, selected_custom),
|
||||
_ => return false,
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
/// Hide Shape Widgets, or Show Shape Widgets while they are hidden (`view.shapeWidgets`), at least 52
|
||||
/// points wide and wider for a longer translated label, while `fit` has room for it.
|
||||
fn shape_widgets_button(app: &mut VectorcraftApp, ui: &mut Ui, fit: &mut Fit) {
|
||||
let label = if app.ui.view.shape_widgets { tl!("Hide Shape Widgets") } else { tl!("Show Shape Widgets") };
|
||||
if fit.room(ui, &[widgets::flat_button_fit_width(ui, label, 52.0)]) && widgets::flat_button_fit(ui, label, 52.0).clicked() {
|
||||
app.run("view.shapeWidgets", json!({})).ok();
|
||||
/// One ranked member of the group: the unit a narrow bar leaves out whole.
|
||||
fn member(ui: &mut Ui, add: impl FnOnce(&mut Ui)) {
|
||||
Row::new().fit_rank(rank::GROUP).show(ui, |ui, _| add(ui));
|
||||
}
|
||||
|
||||
/// The rule that starts a group of members.
|
||||
fn divider(ui: &mut Ui) {
|
||||
member(ui, |ui| {
|
||||
Divider::vertical().show(ui);
|
||||
});
|
||||
}
|
||||
|
||||
/// The translated `text` as an owned label.
|
||||
fn tr(text: &str) -> String {
|
||||
tl!(text).to_string()
|
||||
}
|
||||
|
||||
/// A member with one icon segment per choice over the current `current`; the value picked, if any.
|
||||
fn choice(ui: &mut Ui, caption: &'static str, current: &str, choices: &[Choice]) -> Option<&'static str> {
|
||||
let entries: Vec<Entry<&'static str>> = choices.iter().map(|&(value, label, icon)| Entry::new(value, tr(label)).icon(IconId::new(icon))).collect();
|
||||
let current = choices.iter().map(|c| c.0).find(|&value| value == current).unwrap_or("");
|
||||
let mut picked = None;
|
||||
member(ui, |ui| {
|
||||
picked = Segmented::new(tr(caption), Bind::given(current), &entries).show(ui).value().copied();
|
||||
});
|
||||
picked
|
||||
}
|
||||
|
||||
/// A member with a two-state icon button; the new state when it was clicked.
|
||||
fn link(ui: &mut Ui, on: bool, icon: IconId, on_icon: Option<IconId>) -> Option<bool> {
|
||||
let mut flipped = None;
|
||||
member(ui, |ui| {
|
||||
let mut button = ToggleButton::new(tr("Link"), Bind::given(on)).icon(icon).icon_only();
|
||||
if let Some(on_icon) = on_icon {
|
||||
button = button.on_icon(on_icon);
|
||||
}
|
||||
flipped = button.show(ui).value().copied();
|
||||
});
|
||||
flipped
|
||||
}
|
||||
|
||||
/// A member with the Reset button; whether it was clicked.
|
||||
fn reset(ui: &mut Ui) -> bool {
|
||||
let mut clicked = false;
|
||||
member(ui, |ui| clicked = Button::new(tr("Reset")).show(ui).clicks > 0);
|
||||
clicked
|
||||
}
|
||||
|
||||
/// The caption of a field without its colon: the form adds it.
|
||||
fn caption_of(caption: &str) -> String {
|
||||
tl!(caption).trim_end_matches(':').to_string()
|
||||
}
|
||||
|
||||
/// A number field of `kind` (none for a plain number) written with `decimals`, within `range` when given.
|
||||
fn plain(caption: &str, value: f64, kind: Option<UnitKind>, decimals: usize, range: Option<RangeInclusive<f64>>, ui: &Ui) -> NumberField<'static> {
|
||||
let codec = NumberCodec::new(Env::of(ui).units().reader(kind), decimals);
|
||||
let mut field = NumberField::new(caption_of(caption), Bind::given(Some(value))).codec(codec);
|
||||
if let Some(kind) = kind {
|
||||
field = field.unit_kind(kind);
|
||||
}
|
||||
match range {
|
||||
Some(range) => field.range(range),
|
||||
None => field,
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether `fit` has room in the row `ui` for the label `text` with a field `field` wide after it.
|
||||
fn field_room(ui: &Ui, fit: &mut Fit, text: &egui::RichText, field: f32) -> bool {
|
||||
fit.room(ui, &[widgets::text_width(ui, text.clone()), field])
|
||||
/// A length field keeping points, shown in the user's unit, that is never negative.
|
||||
fn length(caption: &str, value: f64, lengths: LengthUnits) -> NumberField<'static> {
|
||||
NumberField::length(caption_of(caption), Bind::given(Some(value)), lengths).range(0.0..=f64::MAX)
|
||||
}
|
||||
|
||||
/// The shape options' Reset button, at least 52 points wide and wider for a longer translated label,
|
||||
/// while `fit` has room for it. Whether it was clicked.
|
||||
fn reset_button(ui: &mut Ui, fit: &mut Fit) -> bool {
|
||||
fit.room(ui, &[widgets::flat_button_fit_width(ui, tl!("Reset"), 52.0)]) && widgets::flat_button_fit(ui, tl!("Reset"), 52.0).clicked()
|
||||
/// A member with `field` under a scrubbable side label. A committed or scrubbed value goes to `apply`
|
||||
/// as one live edit; an emptied field changes nothing.
|
||||
fn number(
|
||||
app: &mut VectorcraftApp,
|
||||
ui: &mut Ui,
|
||||
key: &'static str,
|
||||
caption: &str,
|
||||
field: NumberField<'static>,
|
||||
mut apply: impl FnMut(&mut VectorcraftApp, f64),
|
||||
) {
|
||||
member(ui, |ui| {
|
||||
let mut field = Some(field.scrub_by_label());
|
||||
let mut response: Option<EditResponse<Option<f64>>> = None;
|
||||
Field::new(caption_of(caption)).id_salt(("cb-shape", key)).side(SideLabel::new().scrub(true)).show(ui, |ui, _| {
|
||||
response = field.take().map(|field| field.show(ui));
|
||||
});
|
||||
if let Some(response) = response {
|
||||
let path = EditPath::Preview { label: "Live Shape".into(), cmd: "addon.shapes.configure".into() };
|
||||
edits::apply_edits(app, &response, path, |app, value| {
|
||||
if let Some(value) = *value {
|
||||
apply(app, value);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn apply_shape(app: &mut VectorcraftApp, tool_kvs: &[(&str, Value)], live_patch: Value) {
|
||||
@@ -95,59 +191,47 @@ fn apply_shape(app: &mut VectorcraftApp, tool_kvs: &[(&str, Value)], live_patch:
|
||||
}
|
||||
}
|
||||
|
||||
fn draw_arc_controls(app: &mut VectorcraftApp, ui: &mut Ui, fit: &mut Fit, start_deg: f64, end_deg: f64, mode: &str) {
|
||||
let t = Tokens::get(ui.ctx());
|
||||
let start = egui::RichText::new(tl!("Start:")).size(12.0).color(t.text_dim);
|
||||
if field_room(ui, fit, &start, 52.0) {
|
||||
widgets::field_label(ui, start);
|
||||
if let Some(v) = widgets::plain_field(ui, ("cb-shape", "arc-start"), start_deg, "°", 1, 52.0) {
|
||||
let next_mode = if mode == "whole" { "pie" } else { mode };
|
||||
apply_shape(app, &[("arcStart", json!(v)), ("arcMode", json!(next_mode))], json!({ "startAngle": v, "arcMode": next_mode }));
|
||||
}
|
||||
}
|
||||
let end = egui::RichText::new(tl!("End:")).size(12.0).color(t.text_dim);
|
||||
if field_room(ui, fit, &end, 52.0) {
|
||||
widgets::field_label(ui, end);
|
||||
if let Some(v) = widgets::plain_field(ui, ("cb-shape", "arc-end"), end_deg, "°", 1, 52.0) {
|
||||
let next_mode = if mode == "whole" { "pie" } else { mode };
|
||||
apply_shape(app, &[("arcEnd", json!(v)), ("arcMode", json!(next_mode))], json!({ "endAngle": v, "arcMode": next_mode }));
|
||||
}
|
||||
}
|
||||
for (m_id, tip_label, icon) in
|
||||
[("pie", "Slice", "circle-dot"), ("chord", "Closed", "circle-off"), ("arc", "Arc", "dc-arc"), ("whole", "Open", "dc-ellipse")]
|
||||
{
|
||||
if fit.room(ui, &[22.0]) && widgets::icon_button(ui, icon, tl!(tip_label), mode == m_id, 22.0).clicked() {
|
||||
let (s0, e0) = if m_id == "whole" {
|
||||
(0.0, 0.0)
|
||||
} else if (end_deg - start_deg).abs() < 1e-4 || ((end_deg - start_deg).abs() - 360.0).abs() < 1e-4 {
|
||||
(0.0, 270.0)
|
||||
} else {
|
||||
(start_deg, end_deg)
|
||||
};
|
||||
apply_shape(
|
||||
app,
|
||||
&[("arcMode", json!(m_id)), ("arcStart", json!(s0)), ("arcEnd", json!(e0))],
|
||||
json!({ "arcMode": m_id, "startAngle": s0, "endAngle": if m_id == "whole" { 360.0 } else { e0 } }),
|
||||
);
|
||||
}
|
||||
fn draw_arc_controls(app: &mut VectorcraftApp, ui: &mut Ui, start_deg: f64, end_deg: f64, mode: &str) {
|
||||
// A whole ellipse becomes a pie once an angle is typed.
|
||||
let next_mode = if mode == "whole" { "pie" } else { mode };
|
||||
let start = plain(tl!("Start:"), start_deg, Some(UnitKind::Degrees), 1, None, ui);
|
||||
number(app, ui, "arc-start", "Start:", start, |app, v| {
|
||||
apply_shape(app, &[("arcStart", json!(v)), ("arcMode", json!(next_mode))], json!({ "startAngle": v, "arcMode": next_mode }));
|
||||
});
|
||||
let end = plain(tl!("End:"), end_deg, Some(UnitKind::Degrees), 1, None, ui);
|
||||
number(app, ui, "arc-end", "End:", end, |app, v| {
|
||||
apply_shape(app, &[("arcEnd", json!(v)), ("arcMode", json!(next_mode))], json!({ "endAngle": v, "arcMode": next_mode }));
|
||||
});
|
||||
const MODES: [Choice; 4] = [("pie", "Slice", "target"), ("chord", "Closed", "circle-off"), ("arc", "Arc", "dc-arc"), ("whole", "Open", "dc-ellipse")];
|
||||
if let Some(m_id) = choice(ui, "Arc", mode, &MODES) {
|
||||
let (s0, e0) = if m_id == "whole" {
|
||||
(0.0, 0.0)
|
||||
} else if (end_deg - start_deg).abs() < 1e-4 || ((end_deg - start_deg).abs() - 360.0).abs() < 1e-4 {
|
||||
(0.0, 270.0)
|
||||
} else {
|
||||
(start_deg, end_deg)
|
||||
};
|
||||
apply_shape(
|
||||
app,
|
||||
&[("arcMode", json!(m_id)), ("arcStart", json!(s0)), ("arcEnd", json!(e0))],
|
||||
json!({ "arcMode": m_id, "startAngle": s0, "endAngle": if m_id == "whole" { 360.0 } else { e0 } }),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn draw_ellipse_controls(app: &mut VectorcraftApp, ui: &mut Ui, fit: &mut Fit, opts: &Value, selected_custom: Option<CustomShape>) {
|
||||
fn draw_ellipse_controls(app: &mut VectorcraftApp, ui: &mut Ui, opts: &Value, selected_custom: Option<CustomShape>) {
|
||||
let (start_deg, end_deg, mode) = match selected_custom {
|
||||
Some(CustomShape::Ellipse { pie: (a0, a1), arc_mode, .. }) => (a0, a1, mode_str(arc_mode)),
|
||||
_ => (opts["arcStart"].as_f64().unwrap_or(0.0), opts["arcEnd"].as_f64().unwrap_or(0.0), opts["arcMode"].as_str().unwrap_or("whole")),
|
||||
};
|
||||
draw_arc_controls(app, ui, fit, start_deg, end_deg, mode);
|
||||
if reset_button(ui, fit) {
|
||||
draw_arc_controls(app, ui, start_deg, end_deg, mode);
|
||||
if reset(ui) {
|
||||
apply_shape(app, &[("arcMode", json!("whole")), ("arcStart", json!(0.0)), ("arcEnd", json!(0.0))], json!({ "reset": true }));
|
||||
}
|
||||
fit.separator(ui);
|
||||
}
|
||||
|
||||
fn draw_rectangle_controls(app: &mut VectorcraftApp, ui: &mut Ui, fit: &mut Fit, opts: &Value, selected_custom: Option<CustomShape>) {
|
||||
let t = Tokens::get(ui.ctx());
|
||||
let unit = app.session.general_unit();
|
||||
fn draw_rectangle_controls(app: &mut VectorcraftApp, ui: &mut Ui, opts: &Value, selected_custom: Option<CustomShape>) {
|
||||
let lengths = general_lengths(app);
|
||||
let sym = opts["cornerSymmetry"].as_bool().unwrap_or(true);
|
||||
let mut radii = [opts["cornerRadius"].as_f64().unwrap_or(12.0); 4];
|
||||
if let Some(arr) = opts["cornerRadii"].as_array()
|
||||
@@ -165,36 +249,26 @@ fn draw_rectangle_controls(app: &mut VectorcraftApp, ui: &mut Ui, fit: &mut Fit,
|
||||
end_deg = a1;
|
||||
mode = mode_str(arc_mode);
|
||||
}
|
||||
if fit.room(ui, &[22.0]) && widgets::icon_button(ui, if sym { "link" } else { "unlink" }, tl!("Link"), sym, 22.0).clicked() {
|
||||
let next_sym = !sym;
|
||||
if let Some(next_sym) = link(ui, sym, IconId::new("unlink"), Some(IconId::new("link"))) {
|
||||
apply_shape(app, &[("cornerSymmetry", json!(next_sym))], if next_sym { json!({ "radius": radii[0] }) } else { json!({ "radii": radii }) });
|
||||
}
|
||||
if sym {
|
||||
let text = egui::RichText::new(tl!("Radius:")).size(12.0).color(t.text_dim);
|
||||
if field_room(ui, fit, &text, 54.0) {
|
||||
widgets::field_label(ui, text);
|
||||
if let Some(v) = widgets::num_field(ui, ("cb-shape", "rect-r"), Some(radii[0]), unit, 54.0) {
|
||||
let r = v.max(0.0);
|
||||
apply_shape(app, &[("cornerRadius", json!(r)), ("cornerRadii", json!([r, r, r, r]))], json!({ "radius": r }));
|
||||
}
|
||||
}
|
||||
number(app, ui, "rect-r", "Radius:", length("Radius:", radii[0], lengths), |app, v| {
|
||||
let r = v.max(0.0);
|
||||
apply_shape(app, &[("cornerRadius", json!(r)), ("cornerRadii", json!([r, r, r, r]))], json!({ "radius": r }));
|
||||
});
|
||||
} else {
|
||||
for (i, lbl) in [(0, "TL"), (1, "TR"), (2, "BR"), (3, "BL")] {
|
||||
let text = egui::RichText::new(lbl).size(11.0).color(t.text_dim);
|
||||
if !field_room(ui, fit, &text, 44.0) {
|
||||
break;
|
||||
}
|
||||
widgets::field_label(ui, text);
|
||||
if let Some(v) = widgets::num_field(ui, ("cb-shape-r", i), Some(radii[i]), unit, 44.0) {
|
||||
for (i, (key, caption)) in [("rect-tl", "TL"), ("rect-tr", "TR"), ("rect-br", "BR"), ("rect-bl", "BL")].into_iter().enumerate() {
|
||||
number(app, ui, key, caption, length(caption, radii[i], lengths), |app, v| {
|
||||
let mut next = radii;
|
||||
next[i] = v.max(0.0);
|
||||
apply_shape(app, &[("cornerRadii", json!(next))], json!({ "radii": next }));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
fit.separator(ui);
|
||||
draw_arc_controls(app, ui, fit, start_deg, end_deg, mode);
|
||||
if reset_button(ui, fit) {
|
||||
divider(ui);
|
||||
draw_arc_controls(app, ui, start_deg, end_deg, mode);
|
||||
if reset(ui) {
|
||||
apply_shape(
|
||||
app,
|
||||
&[
|
||||
@@ -207,18 +281,9 @@ fn draw_rectangle_controls(app: &mut VectorcraftApp, ui: &mut Ui, fit: &mut Fit,
|
||||
json!({ "reset": true }),
|
||||
);
|
||||
}
|
||||
fit.separator(ui);
|
||||
}
|
||||
|
||||
fn draw_polygon_controls(
|
||||
app: &mut VectorcraftApp,
|
||||
ui: &mut Ui,
|
||||
fit: &mut Fit,
|
||||
opts: &Value,
|
||||
active_shape: &str,
|
||||
selected_custom: Option<CustomShape>,
|
||||
) {
|
||||
let t = Tokens::get(ui.ctx());
|
||||
fn draw_polygon_controls(app: &mut VectorcraftApp, ui: &mut Ui, opts: &Value, active_shape: &str, selected_custom: Option<CustomShape>) {
|
||||
let mut is_star = if active_shape == "star" { true } else { opts["polyIsStar"].as_bool().unwrap_or(false) };
|
||||
let mut count = if is_star { opts["points"].as_u64().unwrap_or(5) } else { opts["sides"].as_u64().unwrap_or(6) } as u32;
|
||||
let mut spoke = opts["starRatio"].as_f64().unwrap_or(0.5);
|
||||
@@ -238,58 +303,43 @@ fn draw_polygon_controls(
|
||||
end_deg = a1;
|
||||
mode = mode_str(arc_mode);
|
||||
}
|
||||
if fit.room(ui, &[22.0]) && widgets::icon_button(ui, "dc-polygon", tl!("Polygon"), !is_star, 22.0).clicked() {
|
||||
apply_shape(app, &[("polyIsStar", json!(false))], json!({ "isStar": false }));
|
||||
const KINDS: [Choice; 2] = [("polygon", "Polygon", "dc-polygon"), ("star", "Star", "star")];
|
||||
match choice(ui, "Shape", if is_star { "star" } else { "polygon" }, &KINDS) {
|
||||
Some("star") => apply_shape(app, &[("polyIsStar", json!(true))], json!({ "isStar": true, "spokeRatio": spoke })),
|
||||
Some(_) => apply_shape(app, &[("polyIsStar", json!(false))], json!({ "isStar": false })),
|
||||
None => {}
|
||||
}
|
||||
if fit.room(ui, &[22.0]) && widgets::icon_button(ui, "star", tl!("Star"), is_star, 22.0).clicked() {
|
||||
apply_shape(app, &[("polyIsStar", json!(true))], json!({ "isStar": true, "spokeRatio": spoke }));
|
||||
}
|
||||
let text = egui::RichText::new(if is_star { tl!("Points:") } else { tl!("Sides:") }).size(12.0).color(t.text_dim);
|
||||
if field_room(ui, fit, &text, 44.0) {
|
||||
widgets::field_label(ui, text);
|
||||
if let Some(v) = widgets::plain_field(ui, ("cb-shape", "poly-corners"), f64::from(count), "", 0, 44.0) {
|
||||
let c = (v.round() as i64).clamp(3, 1000) as u32;
|
||||
apply_shape(app, &[("sides", json!(c)), ("points", json!(c))], json!({ "sides": c }));
|
||||
}
|
||||
}
|
||||
let text = egui::RichText::new(tl!("Ratio")).size(12.0).color(t.text_dim);
|
||||
if is_star && field_room(ui, fit, &text, 46.0) {
|
||||
widgets::field_label(ui, text);
|
||||
if let Some(v) = widgets::plain_field(ui, ("cb-shape", "poly-spoke"), spoke, "", 2, 46.0) {
|
||||
let corners = if is_star { "Points:" } else { "Sides:" };
|
||||
number(app, ui, "poly-corners", corners, plain(corners, f64::from(count), None, 0, Some(3.0..=1000.0), ui), |app, v| {
|
||||
let c = (v.round() as i64).clamp(3, 1000) as u32;
|
||||
apply_shape(app, &[("sides", json!(c)), ("points", json!(c))], json!({ "sides": c }));
|
||||
});
|
||||
if is_star {
|
||||
number(app, ui, "poly-spoke", "Ratio", plain("Ratio", spoke, None, 2, Some(0.01..=1.0), ui), |app, v| {
|
||||
let sr = v.clamp(0.01, 1.0);
|
||||
apply_shape(app, &[("starRatio", json!(sr))], json!({ "spokeRatio": sr }));
|
||||
}
|
||||
});
|
||||
}
|
||||
let text = egui::RichText::new(tl!("Round")).size(12.0).color(t.text_dim);
|
||||
if field_room(ui, fit, &text, 46.0) {
|
||||
widgets::field_label(ui, text);
|
||||
if let Some(v) = widgets::plain_field(ui, ("cb-shape", "poly-round"), rounded, "", 2, 46.0) {
|
||||
let rnd = v.clamp(-10.0, 10.0);
|
||||
apply_shape(app, &[("rounded", json!(rnd))], json!({ "rounded": rnd }));
|
||||
}
|
||||
}
|
||||
let text = egui::RichText::new(tl!("Random")).size(12.0).color(t.text_dim);
|
||||
if field_room(ui, fit, &text, 46.0) {
|
||||
widgets::field_label(ui, text);
|
||||
if let Some(v) = widgets::plain_field(ui, ("cb-shape", "poly-rand"), randomized, "", 2, 46.0) {
|
||||
let rand = v.clamp(-10.0, 10.0);
|
||||
apply_shape(app, &[("randomized", json!(rand))], json!({ "randomized": rand }));
|
||||
}
|
||||
}
|
||||
fit.separator(ui);
|
||||
draw_arc_controls(app, ui, fit, start_deg, end_deg, mode);
|
||||
if reset_button(ui, fit) {
|
||||
number(app, ui, "poly-round", "Round", plain("Round", rounded, None, 2, Some(-10.0..=10.0), ui), |app, v| {
|
||||
let rnd = v.clamp(-10.0, 10.0);
|
||||
apply_shape(app, &[("rounded", json!(rnd))], json!({ "rounded": rnd }));
|
||||
});
|
||||
number(app, ui, "poly-rand", "Random", plain("Random", randomized, None, 2, Some(-10.0..=10.0), ui), |app, v| {
|
||||
let rand = v.clamp(-10.0, 10.0);
|
||||
apply_shape(app, &[("randomized", json!(rand))], json!({ "randomized": rand }));
|
||||
});
|
||||
divider(ui);
|
||||
draw_arc_controls(app, ui, start_deg, end_deg, mode);
|
||||
if reset(ui) {
|
||||
apply_shape(
|
||||
app,
|
||||
&[("rounded", json!(0.0)), ("randomized", json!(0.0)), ("arcMode", json!("whole")), ("arcStart", json!(0.0)), ("arcEnd", json!(0.0))],
|
||||
json!({ "reset": true }),
|
||||
);
|
||||
}
|
||||
fit.separator(ui);
|
||||
}
|
||||
|
||||
fn draw_spiral_controls(app: &mut VectorcraftApp, ui: &mut Ui, fit: &mut Fit, opts: &Value, selected_custom: Option<CustomShape>) {
|
||||
let t = Tokens::get(ui.ctx());
|
||||
fn draw_spiral_controls(app: &mut VectorcraftApp, ui: &mut Ui, opts: &Value, selected_custom: Option<CustomShape>) {
|
||||
let (mut turns, mut divergence, mut inner_r) =
|
||||
(opts["turns"].as_f64().unwrap_or(3.0), opts["divergence"].as_f64().unwrap_or(1.0), opts["innerRadius"].as_f64().unwrap_or(0.0));
|
||||
if let Some(CustomShape::Spiral { turns: t_v, divergence: div_v, inner_radius: ir_v, .. }) = selected_custom {
|
||||
@@ -297,38 +347,24 @@ fn draw_spiral_controls(app: &mut VectorcraftApp, ui: &mut Ui, fit: &mut Fit, op
|
||||
divergence = div_v;
|
||||
inner_r = ir_v;
|
||||
}
|
||||
let text = egui::RichText::new(tl!("Segments")).size(12.0).color(t.text_dim);
|
||||
if field_room(ui, fit, &text, 50.0) {
|
||||
widgets::field_label(ui, text);
|
||||
if let Some(v) = widgets::plain_field(ui, ("cb-shape", "spiral-turns"), turns, "", 2, 50.0) {
|
||||
let tv = v.clamp(0.01, 1024.0);
|
||||
apply_shape(app, &[("turns", json!(tv))], json!({ "turns": tv }));
|
||||
}
|
||||
}
|
||||
let text = egui::RichText::new(tl!("Ratio")).size(12.0).color(t.text_dim);
|
||||
if field_room(ui, fit, &text, 50.0) {
|
||||
widgets::field_label(ui, text);
|
||||
if let Some(v) = widgets::plain_field(ui, ("cb-shape", "spiral-div"), divergence, "", 2, 50.0) {
|
||||
let dv = v.clamp(0.0, 1000.0);
|
||||
apply_shape(app, &[("divergence", json!(dv))], json!({ "divergence": dv }));
|
||||
}
|
||||
}
|
||||
let text = egui::RichText::new(tl!("Inner Radius:")).size(12.0).color(t.text_dim);
|
||||
if field_room(ui, fit, &text, 50.0) {
|
||||
widgets::field_label(ui, text);
|
||||
if let Some(v) = widgets::plain_field(ui, ("cb-shape", "spiral-inner"), inner_r, "", 2, 50.0) {
|
||||
let iv = v.clamp(0.0, 0.999);
|
||||
apply_shape(app, &[("innerRadius", json!(iv))], json!({ "innerRadius": iv }));
|
||||
}
|
||||
}
|
||||
if reset_button(ui, fit) {
|
||||
number(app, ui, "spiral-turns", "Segments", plain("Segments", turns, None, 2, Some(0.01..=1024.0), ui), |app, v| {
|
||||
let tv = v.clamp(0.01, 1024.0);
|
||||
apply_shape(app, &[("turns", json!(tv))], json!({ "turns": tv }));
|
||||
});
|
||||
number(app, ui, "spiral-div", "Ratio", plain("Ratio", divergence, None, 2, Some(0.0..=1000.0), ui), |app, v| {
|
||||
let dv = v.clamp(0.0, 1000.0);
|
||||
apply_shape(app, &[("divergence", json!(dv))], json!({ "divergence": dv }));
|
||||
});
|
||||
number(app, ui, "spiral-inner", "Inner Radius:", plain("Inner Radius:", inner_r, None, 2, Some(0.0..=0.999), ui), |app, v| {
|
||||
let iv = v.clamp(0.0, 0.999);
|
||||
apply_shape(app, &[("innerRadius", json!(iv))], json!({ "innerRadius": iv }));
|
||||
});
|
||||
if reset(ui) {
|
||||
apply_shape(app, &[("turns", json!(3.0)), ("divergence", json!(1.0)), ("innerRadius", json!(0.0))], json!({ "reset": true }));
|
||||
}
|
||||
fit.separator(ui);
|
||||
}
|
||||
|
||||
fn draw_box3d_controls(app: &mut VectorcraftApp, ui: &mut Ui, fit: &mut Fit, opts: &Value, selected_custom: Option<CustomShape>) {
|
||||
let t = Tokens::get(ui.ctx());
|
||||
fn draw_box3d_controls(app: &mut VectorcraftApp, ui: &mut Ui, opts: &Value, selected_custom: Option<CustomShape>) {
|
||||
let (mut ax, mut ay, mut az) =
|
||||
(opts["angleX"].as_f64().unwrap_or(30.0), opts["angleY"].as_f64().unwrap_or(30.0), opts["angleZ"].as_f64().unwrap_or(0.0));
|
||||
let (mut px, mut py, mut pz) =
|
||||
@@ -344,20 +380,14 @@ fn draw_box3d_controls(app: &mut VectorcraftApp, ui: &mut Ui, fit: &mut Fit, opt
|
||||
for (lbl, a_key, p_key, a_val, p_val) in
|
||||
[("X:", "angleX", "parallelX", ax, px), ("Y:", "angleY", "parallelY", ay, py), ("Angle:", "angleZ", "parallelZ", az, pz)]
|
||||
{
|
||||
let text = egui::RichText::new(tl!(lbl)).size(12.0).color(t.text_dim);
|
||||
if !field_room(ui, fit, &text, 52.0) {
|
||||
break;
|
||||
}
|
||||
widgets::field_label(ui, text);
|
||||
if let Some(v) = widgets::plain_field(ui, ("cb-box3d", a_key), a_val, "°", 1, 52.0) {
|
||||
number(app, ui, a_key, lbl, plain(lbl, a_val, Some(UnitKind::Degrees), 1, None, ui), |app, v| {
|
||||
apply_shape(app, &[(a_key, json!(v))], json!({ a_key: v }));
|
||||
}
|
||||
if fit.room(ui, &[20.0]) && widgets::icon_button(ui, "dc-line", tl!("Link"), p_val, 20.0).clicked() {
|
||||
let next = !p_val;
|
||||
});
|
||||
if let Some(next) = link(ui, p_val, IconId::new("dc-line"), None) {
|
||||
apply_shape(app, &[(p_key, json!(next))], json!({ p_key: next }));
|
||||
}
|
||||
}
|
||||
if reset_button(ui, fit) {
|
||||
if reset(ui) {
|
||||
apply_shape(
|
||||
app,
|
||||
&[
|
||||
@@ -371,7 +401,6 @@ fn draw_box3d_controls(app: &mut VectorcraftApp, ui: &mut Ui, fit: &mut Fit, opt
|
||||
json!({ "reset": true }),
|
||||
);
|
||||
}
|
||||
fit.separator(ui);
|
||||
}
|
||||
|
||||
fn mode_str(m: EllipseMode) -> &'static str {
|
||||
|
||||
Reference in New Issue
Block a user