refactor(styles): replace cycle buttons with dropdowns

The enum/handle pickers in the MLeader, Table and Dimension style
editors used "Cycle" buttons, which were awkward. Replace them with
pick_list dropdowns:
- MLeader: path type, content type, text angle, text alignment.
- Table per-cell: alignment (9 anchors).
- Dimension: arrowhead blocks (DIMBLK/1/2/LDRBLK) and ext-line linetypes
  (DIMLTYPE/LTEX1/LTEX2), options resolved from block_records/line_types.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
This commit is contained in:
Hakan SevenandClaude Opus 4.8 committed 2026-06-03 20:44:37 +03:00
1 parent 1b7edf6cae
commit bd120ca307
6 files changed
+161 -102

No files matched your search

+15 -6
View File
@@ -1026,8 +1026,11 @@ pub enum Message {
},
/// Toggle background fill on a cell style.
TableStyleCellToggleFill(u8),
/// Cycle the alignment of a cell style.
TableStyleCellCycleAlign(u8),
/// Set the alignment of a cell style from the dropdown.
TableStyleCellSetAlign {
row: u8,
value: String,
},
/// Write a cell's edit buffers back into the selected table style.
TableStyleCellApply(u8),
// ── MLineStyle Dialog ─────────────────────────────────────────────────
@@ -1051,7 +1054,10 @@ pub enum Message {
value: String,
},
MLeaderStyleToggle(&'static str),
MLeaderStyleCycle(&'static str),
MLeaderStyleSetEnum {
field: &'static str,
value: String,
},
MLeaderStyleApply,
// ── DimStyle Dialog ───────────────────────────────────────────────────
DimStyleDialogOpen,
@@ -1071,9 +1077,12 @@ pub enum Message {
// Field edit messages:
DsEdit(DsField, String),
DsToggle(DsField),
/// Cycle a block/linetype Handle field on the selected dim style to the
/// next available block-record / linetype.
DsCycleHandle(&'static str),
/// Set a block/linetype Handle field on the selected dim style from a
/// dropdown of available block-records / linetypes (by name).
DsSetHandle {
field: &'static str,
value: String,
},
// ── Raster Image ──────────────────────────────────────────────────────
/// Open file-picker dialog for IMAGE command (async).
ImagePick,
+50 -61
View File
@@ -5810,21 +5810,21 @@ impl OpenCADStudio {
Task::none()
}
Message::TableStyleCellCycleAlign(row) => {
Message::TableStyleCellSetAlign { row, value } => {
use acadrust::objects::CellAlignment;
let i = self.active_tab;
if let Some(s) = self.tablestyle_mut(i) {
if let Some(c) = Self::ts_cell_of(s, row) {
c.alignment = match c.alignment {
CellAlignment::TopLeft => CellAlignment::TopCenter,
CellAlignment::TopCenter => CellAlignment::TopRight,
CellAlignment::TopRight => CellAlignment::MiddleLeft,
CellAlignment::MiddleLeft => CellAlignment::MiddleCenter,
CellAlignment::MiddleCenter => CellAlignment::MiddleRight,
CellAlignment::MiddleRight => CellAlignment::BottomLeft,
CellAlignment::BottomLeft => CellAlignment::BottomCenter,
CellAlignment::BottomCenter => CellAlignment::BottomRight,
CellAlignment::BottomRight => CellAlignment::TopLeft,
c.alignment = match value.as_str() {
"TopLeft" => CellAlignment::TopLeft,
"TopCenter" => CellAlignment::TopCenter,
"TopRight" => CellAlignment::TopRight,
"MiddleLeft" => CellAlignment::MiddleLeft,
"MiddleRight" => CellAlignment::MiddleRight,
"BottomLeft" => CellAlignment::BottomLeft,
"BottomCenter" => CellAlignment::BottomCenter,
"BottomRight" => CellAlignment::BottomRight,
_ => CellAlignment::MiddleCenter,
};
}
self.push_undo_snapshot(i, "TABLESTYLE EDIT");
@@ -6298,7 +6298,7 @@ impl OpenCADStudio {
}
Task::none()
}
Message::MLeaderStyleCycle(field) => {
Message::MLeaderStyleSetEnum { field, value } => {
use acadrust::objects::{
LeaderContentType, MultiLeaderPathType, TextAlignmentType, TextAngleType,
};
@@ -6306,38 +6306,34 @@ impl OpenCADStudio {
if let Some(s) = self.mleaderstyle_mut(i) {
match field {
"path_type" => {
s.path_type = match s.path_type {
MultiLeaderPathType::Invisible => {
MultiLeaderPathType::StraightLineSegments
}
MultiLeaderPathType::StraightLineSegments => {
MultiLeaderPathType::Spline
}
MultiLeaderPathType::Spline => MultiLeaderPathType::Invisible,
s.path_type = match value.as_str() {
"Invisible" => MultiLeaderPathType::Invisible,
"Spline" => MultiLeaderPathType::Spline,
_ => MultiLeaderPathType::StraightLineSegments,
};
}
"content_type" => {
s.content_type = match s.content_type {
LeaderContentType::None => LeaderContentType::Block,
LeaderContentType::Block => LeaderContentType::MText,
LeaderContentType::MText => LeaderContentType::Tolerance,
LeaderContentType::Tolerance => LeaderContentType::None,
s.content_type = match value.as_str() {
"None" => LeaderContentType::None,
"Block" => LeaderContentType::Block,
"Tolerance" => LeaderContentType::Tolerance,
_ => LeaderContentType::MText,
};
}
"text_angle_type" => {
s.text_angle_type = match s.text_angle_type {
TextAngleType::ParallelToLastLeaderLine => TextAngleType::Horizontal,
TextAngleType::Horizontal => TextAngleType::Optimized,
TextAngleType::Optimized => {
s.text_angle_type = match value.as_str() {
"ParallelToLastLeaderLine" => {
TextAngleType::ParallelToLastLeaderLine
}
"Optimized" => TextAngleType::Optimized,
_ => TextAngleType::Horizontal,
};
}
"text_alignment" => {
s.text_alignment = match s.text_alignment {
TextAlignmentType::Left => TextAlignmentType::Center,
TextAlignmentType::Center => TextAlignmentType::Right,
TextAlignmentType::Right => TextAlignmentType::Left,
s.text_alignment = match value.as_str() {
"Center" => TextAlignmentType::Center,
"Right" => TextAlignmentType::Right,
_ => TextAlignmentType::Left,
};
}
_ => {}
@@ -6534,7 +6530,7 @@ impl OpenCADStudio {
self.apply_ds_toggle(field);
Task::none()
}
Message::DsCycleHandle(field) => {
Message::DsSetHandle { field, value } => {
let i = self.active_tab;
let name = self.dimstyle_selected.clone();
let is_lt = matches!(
@@ -6542,38 +6538,31 @@ impl OpenCADStudio {
"dimltex_handle" | "dimltex1_handle" | "dimltex2_handle"
);
let doc = &self.tabs[i].scene.document;
let mut candidates: Vec<acadrust::types::Handle> =
vec![acadrust::types::Handle::NULL];
if is_lt {
candidates.extend(doc.line_types.iter().map(|lt| lt.handle));
let handle = if value == "Default" || value == "ByBlock" {
acadrust::types::Handle::NULL
} else if is_lt {
doc.line_types
.iter()
.find(|lt| lt.name == value)
.map(|lt| lt.handle)
.unwrap_or(acadrust::types::Handle::NULL)
} else {
candidates.extend(doc.block_records.iter().map(|b| b.handle));
}
let Some(ds) = doc.dim_styles.get(&name) else {
return Task::none();
doc.block_records
.iter()
.find(|b| b.name == value)
.map(|b| b.handle)
.unwrap_or(acadrust::types::Handle::NULL)
};
let cur = match field {
"dimblk" => ds.dimblk,
"dimblk1" => ds.dimblk1,
"dimblk2" => ds.dimblk2,
"dimldrblk" => ds.dimldrblk,
"dimltex_handle" => ds.dimltex_handle,
"dimltex1_handle" => ds.dimltex1_handle,
"dimltex2_handle" => ds.dimltex2_handle,
_ => return Task::none(),
};
let idx = candidates.iter().position(|h| *h == cur).unwrap_or(0);
let next = candidates[(idx + 1) % candidates.len()];
self.push_undo_snapshot(i, "DIMSTYLE EDIT");
if let Some(ds) = self.tabs[i].scene.document.dim_styles.get_mut(&name) {
match field {
"dimblk" => ds.dimblk = next,
"dimblk1" => ds.dimblk1 = next,
"dimblk2" => ds.dimblk2 = next,
"dimldrblk" => ds.dimldrblk = next,
"dimltex_handle" => ds.dimltex_handle = next,
"dimltex1_handle" => ds.dimltex1_handle = next,
"dimltex2_handle" => ds.dimltex2_handle = next,
"dimblk" => ds.dimblk = handle,
"dimblk1" => ds.dimblk1 = handle,
"dimblk2" => ds.dimblk2 = handle,
"dimldrblk" => ds.dimldrblk = handle,
"dimltex_handle" => ds.dimltex_handle = handle,
"dimltex1_handle" => ds.dimltex1_handle = handle,
"dimltex2_handle" => ds.dimltex2_handle = handle,
_ => {}
}
}
+11 -3
View File
@@ -235,6 +235,12 @@ impl OpenCADStudio {
.map(|s| s.name.clone())
.collect();
let doc = &tab.scene.document;
// Dropdown options (names must match the records exactly so the
// selection can be resolved back to a handle on the update side).
let mut block_opts: Vec<String> = vec!["Default".to_string()];
block_opts.extend(doc.block_records.iter().map(|b| b.name.clone()));
let mut lt_opts: Vec<String> = vec!["ByBlock".to_string()];
lt_opts.extend(doc.line_types.iter().map(|lt| lt.name.clone()));
let blk_name = |h: acadrust::types::Handle| -> String {
if h.is_null() {
"Default".to_string()
@@ -242,8 +248,8 @@ impl OpenCADStudio {
doc.block_records
.iter()
.find(|b| b.handle == h)
.map(|b| b.name.trim_start_matches('_').to_string())
.unwrap_or_else(|| "?".to_string())
.map(|b| b.name.clone())
.unwrap_or_else(|| "Default".to_string())
}
};
let lt_name = |h: acadrust::types::Handle| -> String {
@@ -254,7 +260,7 @@ impl OpenCADStudio {
.iter()
.find(|lt| lt.handle == h)
.map(|lt| lt.name.clone())
.unwrap_or_else(|| "?".to_string())
.unwrap_or_else(|| "ByBlock".to_string())
}
};
let ds_sel = doc.dim_styles.get(&self.dimstyle_selected);
@@ -359,6 +365,8 @@ impl OpenCADStudio {
dimltex_name,
dimltex1_name,
dimltex2_name,
block_opts,
lt_opts,
},
);
}