forked from 1b-agent/opencadstudio-upstream
feat(command): clickable option buttons in the command line (#304)
Commands now expose their step options as clickable buttons rendered inline beside the command-line prompt, so options need not be typed. Adds a CmdOption/options() API to CadCommand: each command returns the options for its current step; the command line renders them as uppercase buttons and a click feeds the keyword to the command exactly as if typed (an empty keyword submits like Enter). Construction commands become "central" — CIRCLE offers [3P/2P/TTR/TTT/ DIAMETER], ELLIPSE [ARC/AXIS], ARC [SCE/SCA/SEA/SER/CSA/3P], RECTANGLE [ROTATION/CENTER], POLYGON [CIRCUMSCRIBED/EDGE] — each keyword hands off to the existing dedicated variant command via CmdResult::Dispatch, instead of the variants only being reachable as isolated commands. Migrates the existing bracketed-option prompts (PLINE, PEDIT, SPLINE, SCALE, FILLET, CHAMFER, HATCH, GRADIENT, SOLID, POINT, RAY, XLINE, TRIM, EXTEND) to the same button API and strips the option text from the prompt strings, keeping value/coordinate hints. PEDIT's Width option now enters a value sub-step so the button acts on click. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
efa4bdd5e1
commit
31ac5372d6
18 files changed
+457
-28
No files matched your search
@@ -499,6 +499,37 @@ pub struct DynSpec {
|
||||
// ── Trait ─────────────────────────────────────────────────────────────────
|
||||
|
||||
/// An interactive CAD command that collects user input step-by-step.
|
||||
/// One clickable option a command step offers. Rendered as a button next to
|
||||
/// the command-line prompt; clicking it feeds `keyword` to the running command
|
||||
/// exactly as if the user had typed it (routed through `on_text_input`). An
|
||||
/// empty `keyword` submits the step like pressing Enter (the finish / default
|
||||
/// action). Lets every bracketed `[A=arc L=line …]` prompt become buttons so
|
||||
/// the option need not be typed. (#304)
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct CmdOption {
|
||||
/// Text shown on the button, e.g. `"3P"` or `"Close"`.
|
||||
pub label: String,
|
||||
/// Token fed to the command when clicked, e.g. `"3P"`. Empty = Enter.
|
||||
pub keyword: String,
|
||||
}
|
||||
|
||||
impl CmdOption {
|
||||
/// Button whose keyword is typed on click, e.g. `("Ttr", "TTR")`.
|
||||
pub fn new(label: &str, keyword: &str) -> Self {
|
||||
Self {
|
||||
label: label.to_string(),
|
||||
keyword: keyword.to_string(),
|
||||
}
|
||||
}
|
||||
/// A "finish" button that submits the step like Enter.
|
||||
pub fn enter(label: &str) -> Self {
|
||||
Self {
|
||||
label: label.to_string(),
|
||||
keyword: String::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub trait CadCommand: Send {
|
||||
/// Short name shown in the command line prompt, e.g. `"LINE"`.
|
||||
#[allow(dead_code)]
|
||||
@@ -506,6 +537,14 @@ pub trait CadCommand: Send {
|
||||
/// Current prompt string to display in the command line.
|
||||
fn prompt(&self) -> String;
|
||||
|
||||
/// Clickable keyword options for the current step, rendered as buttons in
|
||||
/// the command line next to the prompt. Default: none. A command returns
|
||||
/// different options per step; clicking a button feeds its keyword through
|
||||
/// the same path as typed command-line text (`on_text_input`). (#304)
|
||||
fn options(&self) -> Vec<CmdOption> {
|
||||
Vec::new()
|
||||
}
|
||||
|
||||
/// Push the active UCS into the command as a UCS→render(wire)-space affine
|
||||
/// (identity = plain WCS). Commands that build axis-aligned geometry (RECT,
|
||||
/// rectangular ARRAY, …) override this to store it and rotate their implicit
|
||||
|
||||
Reference in new issue
Block a user