fix(mleader): use lineweight choices

Replace the raw sentinel input with typed CAD lineweight options so special
values display correctly and unsupported values cannot be entered.

Refs #522
This commit is contained in:
Hakan Seven committed 2026-07-27 18:09:28 +03:00
1 parent dce2533767
commit a3538ddc45
5 files changed
+26 -11

No files matched your search

+1 -2
View File
@@ -630,7 +630,6 @@ pub(super) struct OpenCADStudio {
mls_line_color: String,
mls_text_color: String,
mls_description: String,
mls_line_weight: String,
mls_align_space: String,
mls_block_color: String,
mls_block_rotation: String,
@@ -2336,6 +2335,7 @@ pub enum Message {
field: &'static str,
value: String,
},
MLeaderStyleLineWeightChanged(LineWeight),
/// Set an Option<Handle> field (linetype / arrowhead / text style / block)
/// from a dropdown of record names ("None" clears it).
MLeaderStyleSetHandle {
@@ -2677,7 +2677,6 @@ impl OpenCADStudio {
mls_line_color: String::new(),
mls_text_color: String::new(),
mls_description: String::new(),
mls_line_weight: String::new(),
mls_align_space: String::new(),
mls_block_color: String::new(),
mls_block_rotation: String::new(),
+7
View File
@@ -4809,6 +4809,13 @@ impl OpenCADStudio {
Message::MLeaderStyleSetEnum { field, value } => {
self.on_mleader_style_set_enum(field, value)
}
Message::MLeaderStyleLineWeightChanged(line_weight) => {
let i = self.active_tab;
if let Some(s) = self.mleaderstyle_mut(i) {
s.line_weight = line_weight;
}
Task::none()
}
Message::MLeaderStyleSetHandle { field, value } => {
self.on_mleader_style_set_handle(field, value)
}
-6
View File
@@ -178,7 +178,6 @@ impl OpenCADStudio {
.map(|c| c.to_string())
.unwrap_or_default();
self.mls_description = s.description.clone();
self.mls_line_weight = s.line_weight.value().to_string();
self.mls_align_space = format!("{:.4}", s.align_space);
self.mls_block_color = s
.block_content_color
@@ -699,7 +698,6 @@ pub(super) fn on_text_style_dialog_open(&mut self) -> Task<Message> {
"line_color" => self.mls_line_color = value,
"text_color" => self.mls_text_color = value,
"description" => self.mls_description = value,
"line_weight" => self.mls_line_weight = value,
"align_space" => self.mls_align_space = value,
"block_color" => self.mls_block_color = value,
"block_rotation" => self.mls_block_rotation = value,
@@ -863,7 +861,6 @@ pub(super) fn on_text_style_dialog_open(&mut self) -> Task<Message> {
self.mls_text_color.parse::<i16>().ok(),
);
let desc = self.mls_description.clone();
let lw = self.mls_line_weight.parse::<i16>().ok();
let align = self.mls_align_space.parse::<f64>().ok();
let bclr = self.mls_block_color.parse::<i16>().ok();
let brot = self.mls_block_rotation.parse::<f64>().ok();
@@ -906,9 +903,6 @@ pub(super) fn on_text_style_dialog_open(&mut self) -> Task<Message> {
s.text_color = acadrust::types::Color::from_index(v);
}
s.description = desc;
if let Some(v) = lw {
s.line_weight = acadrust::types::LineWeight::from_value(v);
}
if let Some(v) = align {
s.align_space = v;
}
-1
View File
@@ -393,7 +393,6 @@ impl OpenCADStudio {
line_color: &self.mls_line_color,
text_color: &self.mls_text_color,
description: &self.mls_description,
line_weight: &self.mls_line_weight,
align_space: &self.mls_align_space,
block_color: &self.mls_block_color,
block_rotation: &self.mls_block_rotation,
+18 -2
View File
@@ -83,7 +83,6 @@ pub struct MLeaderStyleView<'a> {
pub line_color: &'a str,
pub text_color: &'a str,
pub description: &'a str,
pub line_weight: &'a str,
pub align_space: &'a str,
pub block_color: &'a str,
pub block_rotation: &'a str,
@@ -176,6 +175,23 @@ fn enum_row<'a>(
.into()
}
fn lineweight_row<'a>(selected: acadrust::types::LineWeight) -> Element<'a, Message> {
let selected = crate::ui::properties::LwItem(selected);
row![
text("Line weight:").size(11).color(DIM).width(150),
pick_list(
crate::ui::properties::lw_options(),
Some(selected),
|item| Message::MLeaderStyleLineWeightChanged(item.0)
)
.text_size(11)
.width(190),
]
.spacing(8)
.align_y(iced::Center)
.into()
}
/// The 11 horizontal text-attachment variants (debug names).
const ATTACH_OPTS: [&str; 11] = [
"TopOfTopLine",
@@ -245,7 +261,7 @@ pub fn view_window<'a>(v: MLeaderStyleView<'a>) -> Element<'a, Message> {
"path_type"
),
color_row("Line color (ACI):", v.line_color, "line_color", v.color_open == Some("line_color")),
num_row("Line weight:", "-2", v.line_weight, "line_weight"),
lineweight_row(s.line_weight),
handle_row(
"Line type:",
v.lt_opts.clone(),