//! What the Tool Options dialogs share: their title, setting a tool's options, the reference point row and reading a //! length a dialog holds. // PLAN: ui-egui reaches the framework through `craft::..`; the crate's Cargo.toml needs the `craft` dependency // (hub-w1 owns the manifest). use craft::behavior::Anchor9; use craft::ui::contract::{Bind, Show as _}; use craft::ui::patterns::form_dialogs::{DialogFields, Param}; use craft::ui::pickers::{ReferencePoint, ReferencePointLook}; use craft::ui::runtime::env::Label; use serde_json::{Map, Value, json}; use vectorcraft_doc::Unit; use crate::VectorcraftApp; /// The title of `tool`'s options dialog: "{tool} Options". pub(crate) fn title(tool: &str) -> String { let label = vectorcraft_tools::tool_info(tool).map_or("", |t| t.label); crate::i18n::fmt(tl!("{tool} Options"), &[("tool", tl!(label))]) } /// Sets `tool`'s options to `values` (`tool.setOption`), the options its next drag and click use. pub(crate) fn set_options(app: &mut VectorcraftApp, tool: &str, values: Map) -> Result<(), String> { app.run("tool.setOption", json!({"tool": tool, "values": values})).map(|_| ()) } /// The reference point `key` holds as an index 0-8 into [`Anchor9::ALL`] (top left first, row by row); an /// index past 8 is 8 and a missing or negative one is 0. pub(crate) fn reference_index(fields: &DialogFields, key: &str) -> usize { fields.int(key).map_or(0, |n| n.clamp(0, 8) as usize) } /// A row of the nine-point reference picker over the index `key` holds ([`reference_index`]). pub(crate) fn reference_param(key: &str, label: impl Into