Add Graphic Attributes palette toggle and persistence

This commit is contained in:
Marcel committed 2026-09-29 21:34:31 +02:00
1 parent 3b74c7e7ea
commit 3e45331de1
14 files changed
+220 -71

No files matched your search

+22 -9
View File
@@ -308,6 +308,10 @@ pub struct ValuePromptCommand {
prompt: &'static str,
}
fn dispatch_prompt_value(name: &str, text: &str) -> CmdResult {
CmdResult::Dispatch(format!("{name} {}", text.trim()))
}
impl ValuePromptCommand {
pub fn new(name: &'static str, prompt: &'static str) -> Self {
Self { name, prompt }
@@ -328,12 +332,7 @@ impl CadCommand for ValuePromptCommand {
}
fn on_text_input(&mut self, text: &str) -> Option<CmdResult> {
let t = text.trim();
if t.is_empty() {
Some(CmdResult::Dispatch(format!("{} ", self.name)))
} else {
Some(CmdResult::Dispatch(format!("{} {t}", self.name)))
}
Some(dispatch_prompt_value(self.name, text))
}
fn on_point(&mut self, _pt: DVec3) -> CmdResult {
@@ -343,7 +342,7 @@ impl CadCommand for ValuePromptCommand {
fn on_enter(&mut self) -> CmdResult {
// Bare Enter → report the current value via the inline handler.
CmdResult::Dispatch(format!("{} ", self.name))
dispatch_prompt_value(self.name, "")
}
}
@@ -375,7 +374,7 @@ impl CadCommand for FreeTextValuePromptCommand {
}
fn on_text_input(&mut self, text: &str) -> Option<CmdResult> {
Some(CmdResult::Dispatch(format!("{} {}", self.name, text.trim())))
Some(dispatch_prompt_value(self.name, text))
}
fn on_point(&mut self, _pt: DVec3) -> CmdResult {
@@ -383,7 +382,7 @@ impl CadCommand for FreeTextValuePromptCommand {
}
fn on_enter(&mut self) -> CmdResult {
CmdResult::Dispatch(format!("{} ", self.name))
dispatch_prompt_value(self.name, "")
}
}
@@ -3079,6 +3078,20 @@ mod constraint_registry_tests {
mod tests {
use super::*;
#[test]
fn prompt_dispatch_trims_values_and_preserves_empty_argument() {
let CmdResult::Dispatch(value) = dispatch_prompt_value("TEST", " value with spaces ")
else {
panic!("prompt input should dispatch a command");
};
assert_eq!(value, "TEST value with spaces");
let CmdResult::Dispatch(value) = dispatch_prompt_value("TEST", " ") else {
panic!("empty prompt input should dispatch a command");
};
assert_eq!(value, "TEST ");
}
#[test]
fn test_mid2point_command() {
let mut cmd = Mid2PointCommand::new();