diff --git a/src/ui/dimstyle.rs b/src/ui/dimstyle.rs index 6f4f0b79..834be310 100644 --- a/src/ui/dimstyle.rs +++ b/src/ui/dimstyle.rs @@ -290,6 +290,48 @@ pub fn view_window<'a>( ("6", "Windows desktop"), ]; + // ACI colour swatches (1-9) + ByLayer; reuses the existing DsEdit path + // (the chosen index is sent as the field's string value). + let color_row = move |label: &'static str, fld: DsField, val: &'a str| -> Element<'a, Message> { + let cur: i16 = val.trim().parse().unwrap_or(256); + let mut swatches = row![].spacing(2).align_y(iced::Center); + for aci in 1u8..=9 { + let c = acadrust::types::Color::from_index(aci as i16); + let (bg, _) = crate::ui::properties::acad_color_display(c); + let sel = cur == aci as i16; + swatches = swatches.push( + button(text("").width(16).height(14)) + .on_press(Message::DsEdit(fld.clone(), aci.to_string())) + .style(move |_: &Theme, _| button::Style { + background: Some(Background::Color(bg)), + border: Border { + color: if sel { Color::WHITE } else { Color::BLACK }, + width: if sel { 2.0 } else { 1.0 }, + radius: 2.0.into(), + }, + ..Default::default() + }), + ); + } + // ByLayer (256) chip. + swatches = swatches.push( + button(text("ByLayer").size(10)) + .on_press(Message::DsEdit(fld.clone(), "256".to_string())) + .style(move |_: &Theme, _| button::Style { + border: Border { + color: if cur == 256 { Color::WHITE } else { BORDER }, + width: if cur == 256 { 2.0 } else { 1.0 }, + radius: 2.0.into(), + }, + ..Default::default() + }), + ); + row![lbl(label), swatches] + .spacing(8) + .align_y(iced::Center) + .into() + }; + // Block / linetype Handle dropdown: pick a block-record (arrowheads) or a // linetype by name from the available records. let hrow = move |label: &'static str, @@ -348,24 +390,14 @@ pub fn view_window<'a>( .align_y(iced::Center), chk("Suppress 1st line (DIMSE1)", vals.dimse1, DsField::Dimse1), chk("Suppress 2nd line (DIMSE2)", vals.dimse2, DsField::Dimse2), - row![ - lbl("Dim line color ACI (DIMCLRD)"), - mk_field(DsField::Dimclrd, vals.dimclrd) - ] - .spacing(8) - .align_y(iced::Center), + color_row("Dim line color ACI (DIMCLRD)", DsField::Dimclrd, vals.dimclrd), row![ lbl("Dim line weight (DIMLWD)"), mk_field(DsField::Dimlwd, vals.dimlwd) ] .spacing(8) .align_y(iced::Center), - row![ - lbl("Ext line color ACI (DIMCLRE)"), - mk_field(DsField::Dimclre, vals.dimclre) - ] - .spacing(8) - .align_y(iced::Center), + color_row("Ext line color ACI (DIMCLRE)", DsField::Dimclre, vals.dimclre), row![ lbl("Ext line weight (DIMLWE)"), mk_field(DsField::Dimlwe, vals.dimlwe) @@ -496,12 +528,7 @@ pub fn view_window<'a>( ), chk("Horizontal inside (DIMTIH)", vals.dimtih, DsField::Dimtih), chk("Horizontal outside (DIMTOH)", vals.dimtoh, DsField::Dimtoh), - row![ - lbl("Text color ACI (DIMCLRT)"), - mk_field(DsField::Dimclrt, vals.dimclrt) - ] - .spacing(8) - .align_y(iced::Center), + color_row("Text color ACI (DIMCLRT)", DsField::Dimclrt, vals.dimclrt), enum_field( "Horizontal just (DIMJUST)", DsField::Dimjust, @@ -530,12 +557,7 @@ pub fn view_window<'a>( ("2", "Color"), ], ), - row![ - lbl("Fill color ACI (DIMTFILLCLR)"), - mk_field(DsField::Dimtfillclr, vals.dimtfillclr) - ] - .spacing(8) - .align_y(iced::Center), + color_row("Fill color ACI (DIMTFILLCLR)", DsField::Dimtfillclr, vals.dimtfillclr), chk( "Left-to-right (DIMTXTDIRECTION)", vals.dimtxtdirection, diff --git a/src/ui/mleaderstyle.rs b/src/ui/mleaderstyle.rs index 1b3b327c..8ed9219a 100644 --- a/src/ui/mleaderstyle.rs +++ b/src/ui/mleaderstyle.rs @@ -126,6 +126,53 @@ fn num_row<'a>( .into() } +/// ACI colour swatch row (1-9 + ByLayer). Reuses MLeaderStyleEdit by sending +/// the chosen index as the field's string value. +fn color_row<'a>(label: &'static str, value: &'a str, field: &'static str) -> Element<'a, Message> { + let cur: i16 = value.trim().parse().unwrap_or(256); + let mut swatches = row![].spacing(2).align_y(iced::Center); + for aci in 1u8..=9 { + let c = acadrust::types::Color::from_index(aci as i16); + let (bg, _) = crate::ui::properties::acad_color_display(c); + let sel = cur == aci as i16; + swatches = swatches.push( + button(text("").width(16).height(14)) + .on_press(Message::MLeaderStyleEdit { + field, + value: aci.to_string(), + }) + .style(move |_: &Theme, _| button::Style { + background: Some(Background::Color(bg)), + border: Border { + color: if sel { Color::WHITE } else { Color::BLACK }, + width: if sel { 2.0 } else { 1.0 }, + radius: 2.0.into(), + }, + ..Default::default() + }), + ); + } + swatches = swatches.push( + button(text("ByLayer").size(10)) + .on_press(Message::MLeaderStyleEdit { + field, + value: "256".to_string(), + }) + .style(move |_: &Theme, _| button::Style { + border: Border { + color: if cur == 256 { Color::WHITE } else { BORDER }, + width: if cur == 256 { 2.0 } else { 1.0 }, + radius: 2.0.into(), + }, + ..Default::default() + }), + ); + row![text(label).size(11).color(DIM).width(150), swatches] + .spacing(8) + .align_y(iced::Center) + .into() +} + fn enum_row<'a>( label: &'static str, options: Vec, @@ -213,7 +260,7 @@ pub fn view_window<'a>(v: MLeaderStyleView<'a>) -> Element<'a, Message> { format!("{:?}", s.path_type), "path_type" ), - num_row("Line color (ACI):", "256", v.line_color, "line_color"), + color_row("Line color (ACI):", v.line_color, "line_color"), num_row("Line weight:", "-2", v.line_weight, "line_weight"), handle_row( "Line type:", @@ -289,7 +336,7 @@ pub fn view_window<'a>(v: MLeaderStyleView<'a>) -> Element<'a, Message> { "text_style_handle" ), num_row("Text height:", "0.18", v.text_height, "text_height"), - num_row("Text color (ACI):", "256", v.text_color, "text_color"), + color_row("Text color (ACI):", v.text_color, "text_color"), enum_row( "Text angle:", opts(&["ParallelToLastLeaderLine", "Horizontal", "Optimized"]), @@ -342,7 +389,7 @@ pub fn view_window<'a>(v: MLeaderStyleView<'a>) -> Element<'a, Message> { v.block_content_name.clone(), "block_content_handle" ), - num_row("Block color (ACI):", "256", v.block_color, "block_color"), + color_row("Block color (ACI):", v.block_color, "block_color"), enum_row( "Block connection:", opts(&["BlockExtents", "BasePoint"]), diff --git a/src/ui/tablestyle.rs b/src/ui/tablestyle.rs index c21c25b5..d2c851bb 100644 --- a/src/ui/tablestyle.rs +++ b/src/ui/tablestyle.rs @@ -121,6 +121,53 @@ pub fn view_window<'a>( .align_y(iced::Center) .into() }; + // ACI swatch row — sends the chosen index through the same cell edit. + let cell_color = |label: &'static str, value: &'a str, field: &'static str| -> Element<'a, Message> { + let cur: i16 = value.trim().parse().unwrap_or(256); + let mut sw = row![].spacing(2).align_y(iced::Center); + for aci in 1u8..=9 { + let c = acadrust::types::Color::from_index(aci as i16); + let (bg, _) = crate::ui::properties::acad_color_display(c); + let sel = cur == aci as i16; + sw = sw.push( + button(text("").width(16).height(14)) + .on_press(Message::TableStyleCellEdit { + row, + field, + value: aci.to_string(), + }) + .style(move |_: &Theme, _| button::Style { + background: Some(Background::Color(bg)), + border: Border { + color: if sel { Color::WHITE } else { Color::BLACK }, + width: if sel { 2.0 } else { 1.0 }, + radius: 2.0.into(), + }, + ..Default::default() + }), + ); + } + sw = sw.push( + button(text("ByLayer").size(10)) + .on_press(Message::TableStyleCellEdit { + row, + field, + value: "256".to_string(), + }) + .style(move |_: &Theme, _| button::Style { + border: Border { + color: if cur == 256 { Color::WHITE } else { BORDER }, + width: if cur == 256 { 2.0 } else { 1.0 }, + radius: 2.0.into(), + }, + ..Default::default() + }), + ); + row![text(label).size(11).color(DIM).width(150), sw] + .spacing(8) + .align_y(iced::Center) + .into() + }; let mut col = Column::new() .spacing(3) .push(text(row_label).size(11).color(ACCENT)) @@ -131,18 +178,8 @@ pub fn view_window<'a>( "textstyle", )) .push(cell_in(" Text height:", "0.18", &cell_height[r], "height")) - .push(cell_in( - " Text color (ACI):", - "256", - &cell_textcolor[r], - "textcolor", - )) - .push(cell_in( - " Fill color (ACI):", - "256", - &cell_fillcolor[r], - "fillcolor", - )) + .push(cell_color(" Text color:", &cell_textcolor[r], "textcolor")) + .push(cell_color(" Fill color:", &cell_fillcolor[r], "fillcolor")) .push( row![ text(" Alignment:").size(11).color(DIM).width(150),