feat(ui): shared colour selector used across all style editors (#94)

Add a reusable color_selector widget (ui/color_select.rs): a main-colour
dropdown plus a "more colours" button that expands the full 255-entry ACI
palette — the same design the properties panel uses. Replace the flat ACI
swatch rows added earlier in the dimension, multileader and table style
editors with it, wired through each editor's existing colour edit message
(the chosen colour is encoded as an ACI string) plus a per-field
palette-open toggle.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Hakan Seven 2026-06-14 10:42:39 +03:00
commit 8cdb17a6b4
8 changed files with 280 additions and 121 deletions

View file

@ -84,6 +84,7 @@ pub fn view_window<'a>(
border_spacing: &'a [[String; 6]; 3],
rename_active: Option<&'a str>,
rename_buf: &'a str,
color_open: Option<(u8, &'static str)>,
) -> Element<'a, Message> {
// ── Right: Details panel ──────────────────────────────────────────────
let info_row = |label: &'static str, val: String| -> Element<'_, Message> {
@ -121,49 +122,26 @@ pub fn view_window<'a>(
.align_y(iced::Center)
.into()
};
// ACI swatch row — sends the chosen index through the same cell edit.
// Shared colour selector — sends the chosen colour through the same
// cell edit as an ACI string.
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()
}),
let cur = crate::ui::color_select::aci_string_to_color(value);
let open = color_open == Some((row, field));
let selector = crate::ui::color_select::color_selector(
cur,
open,
crate::ui::color_select::ColorExtras {
by_layer: true,
by_block: true,
},
move |c| Message::TableStyleCellEdit {
row,
field,
value: crate::ui::color_select::color_to_aci_string(c),
},
Message::TableColorMore(row, field),
);
row![text(label).size(11).color(DIM).width(150), sw]
row![text(label).size(11).color(DIM).width(150), selector]
.spacing(8)
.align_y(iced::Center)
.into()