forked from 1b-agent/opencadstudio-upstream
Route dimension color fields correctly
This commit is contained in:
1 parent
c66ec7fb64
commit
80d7a8741e
12 files changed
+89
-8
No files matched your search
@@ -1218,6 +1218,8 @@ pub enum ColorPickTarget {
|
||||
Properties,
|
||||
/// Selected entities' background colour (hatch / MTEXT background row).
|
||||
PropertiesBg,
|
||||
/// A named per-entity Properties colour field.
|
||||
PropertiesField(String),
|
||||
/// Current creation colour (ribbon).
|
||||
Ribbon,
|
||||
/// A layer's colour, by panel row index.
|
||||
|
||||
@@ -4841,6 +4841,11 @@ impl OpenCADStudio {
|
||||
| "dim_text_color"
|
||||
| "dim_text_fill_color"
|
||||
) {
|
||||
let fill_mode = (field == "dim_text_fill_color").then(|| match color {
|
||||
acadrust::types::Color::None => 0,
|
||||
acadrust::types::Color::ByBlock => 1,
|
||||
_ => 2,
|
||||
});
|
||||
let aci = color.approximate_index();
|
||||
let code = match field.as_str() {
|
||||
"dim_ext_line_color" => crate::entities::dim_override::DIMCLRE,
|
||||
@@ -4862,6 +4867,19 @@ impl OpenCADStudio {
|
||||
if !targets.is_empty() {
|
||||
self.push_undo_snapshot(i, "CHPROP");
|
||||
for &handle in &targets {
|
||||
if field == "dim_text_fill_color" {
|
||||
crate::entities::dim_override::set(
|
||||
&mut self.tabs[i].scene.document,
|
||||
handle,
|
||||
crate::entities::dim_override::DIMTFILL,
|
||||
Some(acadrust::xdata::XDataValue::Integer16(
|
||||
fill_mode.unwrap_or(2),
|
||||
)),
|
||||
);
|
||||
if fill_mode != Some(2) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
crate::entities::dim_override::set(
|
||||
&mut self.tabs[i].scene.document,
|
||||
handle,
|
||||
@@ -7539,6 +7557,7 @@ impl OpenCADStudio {
|
||||
|
||||
let i = self.active_tab;
|
||||
self.tabs[i].properties.color_picker_open = false;
|
||||
self.tabs[i].properties.open_color_field = None;
|
||||
self.tabs[i].layers.color_picker_row = None;
|
||||
|
||||
Task::none()
|
||||
|
||||
@@ -1146,6 +1146,9 @@ pub(super) fn on_text_style_dialog_open(&mut self) -> Task<Message> {
|
||||
Some(crate::app::ColorPickTarget::PropertiesBg) => {
|
||||
Some(Message::PropBgColorChanged(color))
|
||||
}
|
||||
Some(crate::app::ColorPickTarget::PropertiesField(field)) => {
|
||||
Some(Message::PropColorFieldChanged { field, color })
|
||||
}
|
||||
Some(crate::app::ColorPickTarget::MText) => {
|
||||
Some(Message::MTextColorChanged(color))
|
||||
}
|
||||
|
||||
@@ -474,6 +474,7 @@ fn mtext_editor_content<'a>(
|
||||
crate::ui::color_select::ColorExtras {
|
||||
by_layer: true,
|
||||
by_block: false,
|
||||
..Default::default()
|
||||
},
|
||||
Message::MTextColorChanged,
|
||||
Message::MTextColorPickerToggle,
|
||||
|
||||
+25
-3
@@ -16,6 +16,8 @@ use crate::t;
|
||||
pub struct ColorExtras {
|
||||
pub by_layer: bool,
|
||||
pub by_block: bool,
|
||||
pub none: bool,
|
||||
pub background: bool,
|
||||
}
|
||||
|
||||
/// Encode a colour as the ACI integer string the style editors store
|
||||
@@ -38,7 +40,7 @@ pub fn iced_to_acad_color(color: Color) -> AcadColor {
|
||||
AcadColor::Rgb { r, g, b }
|
||||
}
|
||||
|
||||
/// Return the closest AutoCAD Color Index for an RGB colour.
|
||||
/// Return the closest CAD Color Index for an RGB colour.
|
||||
pub fn nearest_aci(r: u8, g: u8, b: u8) -> u8 {
|
||||
let mut best = 7;
|
||||
let mut best_distance = u32::MAX;
|
||||
@@ -209,7 +211,27 @@ pub fn color_list<'a>(
|
||||
.into()
|
||||
};
|
||||
|
||||
let logical_row = |color: AcadColor, label: &'static str| -> Element<'a, Message> {
|
||||
let (bg, _) = acad_color_display(color);
|
||||
button(
|
||||
row![swatch(bg), text(t!(label)).size(11)]
|
||||
.spacing(5)
|
||||
.align_y(iced::Center),
|
||||
)
|
||||
.on_press(on_select(color))
|
||||
.style(list_row_style)
|
||||
.padding([2, 4])
|
||||
.width(Length::Fill)
|
||||
.into()
|
||||
};
|
||||
|
||||
let mut list = column![].spacing(1);
|
||||
if extras.none {
|
||||
list = list.push(named_row(AcadColor::None));
|
||||
}
|
||||
if extras.background {
|
||||
list = list.push(logical_row(AcadColor::ByBlock, "Background"));
|
||||
}
|
||||
if extras.by_layer {
|
||||
list = list.push(named_row(AcadColor::ByLayer));
|
||||
}
|
||||
@@ -297,7 +319,7 @@ pub fn index_color_page<'a>(
|
||||
.into()
|
||||
};
|
||||
|
||||
// AutoCAD's first standard indexed colours.
|
||||
// The first standard indexed CAD colours.
|
||||
let mut standard = row![].spacing(4);
|
||||
for idx in 1u8..=9 {
|
||||
standard = standard.push(swatch_button(AcadColor::Index(idx), 22.0));
|
||||
@@ -402,7 +424,7 @@ pub fn index_color_page<'a>(
|
||||
tabs,
|
||||
text("Standard colors").size(11),
|
||||
standard,
|
||||
text("AutoCAD Color Index (ACI) 10–249").size(11),
|
||||
text("CAD Color Index (ACI) 10–249").size(11),
|
||||
|
||||
text("Color family → · Shade / intensity ↓")
|
||||
.size(9)
|
||||
|
||||
+25
-3
@@ -834,6 +834,7 @@ impl PropertiesPanel {
|
||||
crate::ui::color_select::ColorExtras {
|
||||
by_layer: true,
|
||||
by_block: true,
|
||||
..Default::default()
|
||||
},
|
||||
Message::PropBgColorChanged,
|
||||
Message::PropBgColorPickerToggle,
|
||||
@@ -851,18 +852,35 @@ impl PropertiesPanel {
|
||||
// entity's main colour. Used by hatch gradient colours and the dim-line
|
||||
// colour override (Leader / Dimension). Dim colours legitimately take
|
||||
// ByLayer / ByBlock; gradient colours do not.
|
||||
if field == "gradient_color_1" || field == "gradient_color_2" || field == "dim_line_color" {
|
||||
if matches!(
|
||||
field,
|
||||
"gradient_color_1"
|
||||
| "gradient_color_2"
|
||||
| "dim_line_color"
|
||||
| "dim_ext_line_color"
|
||||
| "dim_text_color"
|
||||
| "dim_text_fill_color"
|
||||
) {
|
||||
let open = self.open_color_field.as_deref() == Some(field);
|
||||
let fsel = field.to_string();
|
||||
let extras = if field == "dim_line_color" {
|
||||
let full_palette_field = field.to_string();
|
||||
let extras = if field == "dim_text_fill_color" {
|
||||
crate::ui::color_select::ColorExtras {
|
||||
none: true,
|
||||
background: true,
|
||||
..Default::default()
|
||||
}
|
||||
} else if field.starts_with("dim_") {
|
||||
crate::ui::color_select::ColorExtras {
|
||||
by_layer: true,
|
||||
by_block: true,
|
||||
..Default::default()
|
||||
}
|
||||
} else {
|
||||
crate::ui::color_select::ColorExtras {
|
||||
by_layer: false,
|
||||
by_block: false,
|
||||
..Default::default()
|
||||
}
|
||||
};
|
||||
let selector = crate::ui::color_select::color_selector(
|
||||
@@ -874,7 +892,10 @@ impl PropertiesPanel {
|
||||
color: c,
|
||||
},
|
||||
Message::PropColorFieldToggle(field.to_string()),
|
||||
Message::PropColorFieldToggle(field.to_string()),
|
||||
Message::OpenColorWindow(
|
||||
crate::app::ColorPickTarget::PropertiesField(full_palette_field),
|
||||
color,
|
||||
),
|
||||
);
|
||||
return prop_row_widget(label, selector);
|
||||
}
|
||||
@@ -884,6 +905,7 @@ impl PropertiesPanel {
|
||||
crate::ui::color_select::ColorExtras {
|
||||
by_layer: true,
|
||||
by_block: true,
|
||||
..Default::default()
|
||||
},
|
||||
Message::PropColorChanged,
|
||||
Message::PropColorPickerToggle,
|
||||
|
||||
@@ -1135,6 +1135,7 @@ impl Ribbon {
|
||||
crate::ui::color_select::ColorExtras {
|
||||
by_layer: true,
|
||||
by_block: true,
|
||||
..Default::default()
|
||||
},
|
||||
Message::RibbonColorChanged,
|
||||
Message::OpenColorWindow(
|
||||
|
||||
@@ -518,6 +518,7 @@ pub fn view_window<'a>(
|
||||
crate::ui::color_select::ColorExtras {
|
||||
by_layer: true,
|
||||
by_block: true,
|
||||
..Default::default()
|
||||
},
|
||||
move |c| Message::DsEdit(f_sel.clone(), crate::ui::color_select::color_to_aci_string(c)),
|
||||
Message::DsColorMore(fld.clone()),
|
||||
|
||||
@@ -115,7 +115,11 @@ fn color_row<'a>(
|
||||
let selector = crate::ui::color_select::color_selector(
|
||||
current,
|
||||
open,
|
||||
crate::ui::color_select::ColorExtras { by_layer: true, by_block: true },
|
||||
crate::ui::color_select::ColorExtras {
|
||||
by_layer: true,
|
||||
by_block: true,
|
||||
..Default::default()
|
||||
},
|
||||
move |color| Message::MLeaderStyleEdit {
|
||||
field,
|
||||
value: crate::ui::color_select::color_to_aci_string(color),
|
||||
|
||||
@@ -317,7 +317,11 @@ fn cell_editor<'a>(v: &TableStyleView<'a>, row_index: u8) -> Element<'a, Message
|
||||
let selector = crate::ui::color_select::color_selector(
|
||||
current,
|
||||
v.color_open == Some((row_index, field)),
|
||||
crate::ui::color_select::ColorExtras { by_layer: true, by_block: true },
|
||||
crate::ui::color_select::ColorExtras {
|
||||
by_layer: true,
|
||||
by_block: true,
|
||||
..Default::default()
|
||||
},
|
||||
move |color| Message::TableStyleCellEdit {
|
||||
row: row_index,
|
||||
field,
|
||||
|
||||
@@ -412,6 +412,7 @@ fn editor_layer_row<'a>(
|
||||
crate::ui::color_select::ColorExtras {
|
||||
by_layer: false,
|
||||
by_block: false,
|
||||
..Default::default()
|
||||
},
|
||||
move |color| Message::LayerStateEditorLayerColor(index, color),
|
||||
Message::LayerStateEditorLayerColorToggle(index),
|
||||
|
||||
@@ -813,6 +813,7 @@ fn layer_row<'a>(
|
||||
crate::ui::color_select::ColorExtras {
|
||||
by_layer: false,
|
||||
by_block: false,
|
||||
..Default::default()
|
||||
},
|
||||
Message::LayerColorSet,
|
||||
Message::LayerColorPickerToggle(index),
|
||||
|
||||
Reference in new issue
Block a user