Route dimension color fields correctly
This commit is contained in:
parent
c66ec7fb64
commit
80d7a8741e
12 changed files with 89 additions and 8 deletions
|
|
@ -1218,6 +1218,8 @@ pub enum ColorPickTarget {
|
||||||
Properties,
|
Properties,
|
||||||
/// Selected entities' background colour (hatch / MTEXT background row).
|
/// Selected entities' background colour (hatch / MTEXT background row).
|
||||||
PropertiesBg,
|
PropertiesBg,
|
||||||
|
/// A named per-entity Properties colour field.
|
||||||
|
PropertiesField(String),
|
||||||
/// Current creation colour (ribbon).
|
/// Current creation colour (ribbon).
|
||||||
Ribbon,
|
Ribbon,
|
||||||
/// A layer's colour, by panel row index.
|
/// A layer's colour, by panel row index.
|
||||||
|
|
|
||||||
|
|
@ -4841,6 +4841,11 @@ impl OpenCADStudio {
|
||||||
| "dim_text_color"
|
| "dim_text_color"
|
||||||
| "dim_text_fill_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 aci = color.approximate_index();
|
||||||
let code = match field.as_str() {
|
let code = match field.as_str() {
|
||||||
"dim_ext_line_color" => crate::entities::dim_override::DIMCLRE,
|
"dim_ext_line_color" => crate::entities::dim_override::DIMCLRE,
|
||||||
|
|
@ -4862,6 +4867,19 @@ impl OpenCADStudio {
|
||||||
if !targets.is_empty() {
|
if !targets.is_empty() {
|
||||||
self.push_undo_snapshot(i, "CHPROP");
|
self.push_undo_snapshot(i, "CHPROP");
|
||||||
for &handle in &targets {
|
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(
|
crate::entities::dim_override::set(
|
||||||
&mut self.tabs[i].scene.document,
|
&mut self.tabs[i].scene.document,
|
||||||
handle,
|
handle,
|
||||||
|
|
@ -7539,6 +7557,7 @@ impl OpenCADStudio {
|
||||||
|
|
||||||
let i = self.active_tab;
|
let i = self.active_tab;
|
||||||
self.tabs[i].properties.color_picker_open = false;
|
self.tabs[i].properties.color_picker_open = false;
|
||||||
|
self.tabs[i].properties.open_color_field = None;
|
||||||
self.tabs[i].layers.color_picker_row = None;
|
self.tabs[i].layers.color_picker_row = None;
|
||||||
|
|
||||||
Task::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(crate::app::ColorPickTarget::PropertiesBg) => {
|
||||||
Some(Message::PropBgColorChanged(color))
|
Some(Message::PropBgColorChanged(color))
|
||||||
}
|
}
|
||||||
|
Some(crate::app::ColorPickTarget::PropertiesField(field)) => {
|
||||||
|
Some(Message::PropColorFieldChanged { field, color })
|
||||||
|
}
|
||||||
Some(crate::app::ColorPickTarget::MText) => {
|
Some(crate::app::ColorPickTarget::MText) => {
|
||||||
Some(Message::MTextColorChanged(color))
|
Some(Message::MTextColorChanged(color))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -474,6 +474,7 @@ fn mtext_editor_content<'a>(
|
||||||
crate::ui::color_select::ColorExtras {
|
crate::ui::color_select::ColorExtras {
|
||||||
by_layer: true,
|
by_layer: true,
|
||||||
by_block: false,
|
by_block: false,
|
||||||
|
..Default::default()
|
||||||
},
|
},
|
||||||
Message::MTextColorChanged,
|
Message::MTextColorChanged,
|
||||||
Message::MTextColorPickerToggle,
|
Message::MTextColorPickerToggle,
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,8 @@ use crate::t;
|
||||||
pub struct ColorExtras {
|
pub struct ColorExtras {
|
||||||
pub by_layer: bool,
|
pub by_layer: bool,
|
||||||
pub by_block: bool,
|
pub by_block: bool,
|
||||||
|
pub none: bool,
|
||||||
|
pub background: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Encode a colour as the ACI integer string the style editors store
|
/// 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 }
|
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 {
|
pub fn nearest_aci(r: u8, g: u8, b: u8) -> u8 {
|
||||||
let mut best = 7;
|
let mut best = 7;
|
||||||
let mut best_distance = u32::MAX;
|
let mut best_distance = u32::MAX;
|
||||||
|
|
@ -209,7 +211,27 @@ pub fn color_list<'a>(
|
||||||
.into()
|
.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);
|
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 {
|
if extras.by_layer {
|
||||||
list = list.push(named_row(AcadColor::ByLayer));
|
list = list.push(named_row(AcadColor::ByLayer));
|
||||||
}
|
}
|
||||||
|
|
@ -297,7 +319,7 @@ pub fn index_color_page<'a>(
|
||||||
.into()
|
.into()
|
||||||
};
|
};
|
||||||
|
|
||||||
// AutoCAD's first standard indexed colours.
|
// The first standard indexed CAD colours.
|
||||||
let mut standard = row![].spacing(4);
|
let mut standard = row![].spacing(4);
|
||||||
for idx in 1u8..=9 {
|
for idx in 1u8..=9 {
|
||||||
standard = standard.push(swatch_button(AcadColor::Index(idx), 22.0));
|
standard = standard.push(swatch_button(AcadColor::Index(idx), 22.0));
|
||||||
|
|
@ -402,7 +424,7 @@ pub fn index_color_page<'a>(
|
||||||
tabs,
|
tabs,
|
||||||
text("Standard colors").size(11),
|
text("Standard colors").size(11),
|
||||||
standard,
|
standard,
|
||||||
text("AutoCAD Color Index (ACI) 10–249").size(11),
|
text("CAD Color Index (ACI) 10–249").size(11),
|
||||||
|
|
||||||
text("Color family → · Shade / intensity ↓")
|
text("Color family → · Shade / intensity ↓")
|
||||||
.size(9)
|
.size(9)
|
||||||
|
|
|
||||||
|
|
@ -834,6 +834,7 @@ impl PropertiesPanel {
|
||||||
crate::ui::color_select::ColorExtras {
|
crate::ui::color_select::ColorExtras {
|
||||||
by_layer: true,
|
by_layer: true,
|
||||||
by_block: true,
|
by_block: true,
|
||||||
|
..Default::default()
|
||||||
},
|
},
|
||||||
Message::PropBgColorChanged,
|
Message::PropBgColorChanged,
|
||||||
Message::PropBgColorPickerToggle,
|
Message::PropBgColorPickerToggle,
|
||||||
|
|
@ -851,18 +852,35 @@ impl PropertiesPanel {
|
||||||
// entity's main colour. Used by hatch gradient colours and the dim-line
|
// entity's main colour. Used by hatch gradient colours and the dim-line
|
||||||
// colour override (Leader / Dimension). Dim colours legitimately take
|
// colour override (Leader / Dimension). Dim colours legitimately take
|
||||||
// ByLayer / ByBlock; gradient colours do not.
|
// 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 open = self.open_color_field.as_deref() == Some(field);
|
||||||
let fsel = field.to_string();
|
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 {
|
crate::ui::color_select::ColorExtras {
|
||||||
by_layer: true,
|
by_layer: true,
|
||||||
by_block: true,
|
by_block: true,
|
||||||
|
..Default::default()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
crate::ui::color_select::ColorExtras {
|
crate::ui::color_select::ColorExtras {
|
||||||
by_layer: false,
|
by_layer: false,
|
||||||
by_block: false,
|
by_block: false,
|
||||||
|
..Default::default()
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let selector = crate::ui::color_select::color_selector(
|
let selector = crate::ui::color_select::color_selector(
|
||||||
|
|
@ -874,7 +892,10 @@ impl PropertiesPanel {
|
||||||
color: c,
|
color: c,
|
||||||
},
|
},
|
||||||
Message::PropColorFieldToggle(field.to_string()),
|
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);
|
return prop_row_widget(label, selector);
|
||||||
}
|
}
|
||||||
|
|
@ -884,6 +905,7 @@ impl PropertiesPanel {
|
||||||
crate::ui::color_select::ColorExtras {
|
crate::ui::color_select::ColorExtras {
|
||||||
by_layer: true,
|
by_layer: true,
|
||||||
by_block: true,
|
by_block: true,
|
||||||
|
..Default::default()
|
||||||
},
|
},
|
||||||
Message::PropColorChanged,
|
Message::PropColorChanged,
|
||||||
Message::PropColorPickerToggle,
|
Message::PropColorPickerToggle,
|
||||||
|
|
|
||||||
|
|
@ -1135,6 +1135,7 @@ impl Ribbon {
|
||||||
crate::ui::color_select::ColorExtras {
|
crate::ui::color_select::ColorExtras {
|
||||||
by_layer: true,
|
by_layer: true,
|
||||||
by_block: true,
|
by_block: true,
|
||||||
|
..Default::default()
|
||||||
},
|
},
|
||||||
Message::RibbonColorChanged,
|
Message::RibbonColorChanged,
|
||||||
Message::OpenColorWindow(
|
Message::OpenColorWindow(
|
||||||
|
|
|
||||||
|
|
@ -518,6 +518,7 @@ pub fn view_window<'a>(
|
||||||
crate::ui::color_select::ColorExtras {
|
crate::ui::color_select::ColorExtras {
|
||||||
by_layer: true,
|
by_layer: true,
|
||||||
by_block: true,
|
by_block: true,
|
||||||
|
..Default::default()
|
||||||
},
|
},
|
||||||
move |c| Message::DsEdit(f_sel.clone(), crate::ui::color_select::color_to_aci_string(c)),
|
move |c| Message::DsEdit(f_sel.clone(), crate::ui::color_select::color_to_aci_string(c)),
|
||||||
Message::DsColorMore(fld.clone()),
|
Message::DsColorMore(fld.clone()),
|
||||||
|
|
|
||||||
|
|
@ -115,7 +115,11 @@ fn color_row<'a>(
|
||||||
let selector = crate::ui::color_select::color_selector(
|
let selector = crate::ui::color_select::color_selector(
|
||||||
current,
|
current,
|
||||||
open,
|
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 {
|
move |color| Message::MLeaderStyleEdit {
|
||||||
field,
|
field,
|
||||||
value: crate::ui::color_select::color_to_aci_string(color),
|
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(
|
let selector = crate::ui::color_select::color_selector(
|
||||||
current,
|
current,
|
||||||
v.color_open == Some((row_index, field)),
|
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 {
|
move |color| Message::TableStyleCellEdit {
|
||||||
row: row_index,
|
row: row_index,
|
||||||
field,
|
field,
|
||||||
|
|
|
||||||
|
|
@ -412,6 +412,7 @@ fn editor_layer_row<'a>(
|
||||||
crate::ui::color_select::ColorExtras {
|
crate::ui::color_select::ColorExtras {
|
||||||
by_layer: false,
|
by_layer: false,
|
||||||
by_block: false,
|
by_block: false,
|
||||||
|
..Default::default()
|
||||||
},
|
},
|
||||||
move |color| Message::LayerStateEditorLayerColor(index, color),
|
move |color| Message::LayerStateEditorLayerColor(index, color),
|
||||||
Message::LayerStateEditorLayerColorToggle(index),
|
Message::LayerStateEditorLayerColorToggle(index),
|
||||||
|
|
|
||||||
|
|
@ -813,6 +813,7 @@ fn layer_row<'a>(
|
||||||
crate::ui::color_select::ColorExtras {
|
crate::ui::color_select::ColorExtras {
|
||||||
by_layer: false,
|
by_layer: false,
|
||||||
by_block: false,
|
by_block: false,
|
||||||
|
..Default::default()
|
||||||
},
|
},
|
||||||
Message::LayerColorSet,
|
Message::LayerColorSet,
|
||||||
Message::LayerColorPickerToggle(index),
|
Message::LayerColorPickerToggle(index),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue