forked from 1b-agent/opencadstudio-upstream
feat: Implement in-place MText editor with formatting toolbar and live preview
- Added SVG icons for text formatting options (bold, italic, underline, overline, strike, uppercase, lowercase). - Introduced a new `MTextEditorState` struct to manage the state of the MText editor. - Implemented functionality to open the MText editor from the command line and edit existing MText entities. - Added message handling for various MText editor actions (formatting, height, style, font, justification, alignment, line spacing). - Created a dedicated preview area for MText rendering within the editor. - Updated the command structure to support opening the MText editor and handling text input. - Refactored existing MText command logic to integrate with the new editor.
This commit is contained in:
1 parent
e2507d5c54
commit
de08bd598c
20 files changed
+871
-36
No files matched your search
@@ -1,6 +1,3 @@
|
||||
use acadrust::types::Vector3;
|
||||
use acadrust::{EntityType, MText};
|
||||
|
||||
use crate::command::{CadCommand, CmdResult};
|
||||
use crate::modules::{IconKind, ModuleEvent, ToolDef};
|
||||
use crate::scene::wire_model::WireModel;
|
||||
@@ -19,7 +16,6 @@ pub fn tool() -> ToolDef {
|
||||
|
||||
enum Step {
|
||||
InsertPoint,
|
||||
WaitText(Vec3),
|
||||
}
|
||||
|
||||
pub struct MTextCommand {
|
||||
@@ -42,16 +38,17 @@ impl CadCommand for MTextCommand {
|
||||
fn prompt(&self) -> String {
|
||||
match &self.step {
|
||||
Step::InsertPoint => "MTEXT Specify insertion point:".into(),
|
||||
Step::WaitText(pos) => format!(
|
||||
"MTEXT Type text, press Enter [at {:.2},{:.2}]:",
|
||||
pos.x, pos.z
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
fn on_point(&mut self, pt: Vec3) -> CmdResult {
|
||||
self.step = Step::WaitText(pt);
|
||||
CmdResult::NeedPoint
|
||||
// Hand off to the in-place editor (toolbar + text area + live preview).
|
||||
CmdResult::OpenMTextEditor {
|
||||
pos: pt,
|
||||
handle: None,
|
||||
initial: String::new(),
|
||||
height: 0.25,
|
||||
}
|
||||
}
|
||||
|
||||
fn on_enter(&mut self) -> CmdResult {
|
||||
@@ -61,32 +58,6 @@ impl CadCommand for MTextCommand {
|
||||
CmdResult::Cancel
|
||||
}
|
||||
|
||||
fn wants_text_input(&self) -> bool {
|
||||
matches!(self.step, Step::WaitText(_))
|
||||
}
|
||||
|
||||
fn wants_text_with_spaces(&self) -> bool {
|
||||
matches!(self.step, Step::WaitText(_))
|
||||
}
|
||||
|
||||
fn on_text_input(&mut self, text: &str) -> Option<CmdResult> {
|
||||
if let Step::WaitText(pos) = &self.step {
|
||||
if text.trim().is_empty() {
|
||||
return Some(CmdResult::Cancel);
|
||||
}
|
||||
let mt = MText {
|
||||
insertion_point: Vector3::new(pos.x as f64, pos.y as f64, pos.z as f64),
|
||||
value: text.to_string(),
|
||||
height: 0.25,
|
||||
rectangle_width: text.len() as f64 * 0.15,
|
||||
..Default::default()
|
||||
};
|
||||
Some(CmdResult::CommitEntity(EntityType::MText(mt)))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
fn on_mouse_move(&mut self, _pt: Vec3) -> Option<WireModel> {
|
||||
None
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user