forked from 1b-agent/opencadstudio-upstream
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:
1 parent
3ccda2f129
commit
8cdb17a6b4
8 files changed
+280
-121
No files matched your search
+27
-44
@@ -102,6 +102,8 @@ pub struct MLeaderStyleView<'a> {
|
||||
pub rename_active: Option<&'a str>,
|
||||
/// Edit buffer for the inline rename text input.
|
||||
pub rename_buf: &'a str,
|
||||
/// Colour field whose expanded palette is currently open.
|
||||
pub color_open: Option<&'static str>,
|
||||
}
|
||||
|
||||
fn section<'a>(label: &'static str) -> Element<'a, Message> {
|
||||
@@ -126,48 +128,29 @@ 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()
|
||||
}),
|
||||
/// Shared colour selector row. Reuses MLeaderStyleEdit by sending the chosen
|
||||
/// colour as an ACI string; `open` shows the expanded palette.
|
||||
fn color_row<'a>(
|
||||
label: &'static str,
|
||||
value: &'a str,
|
||||
field: &'static str,
|
||||
open: bool,
|
||||
) -> Element<'a, Message> {
|
||||
let cur = crate::ui::color_select::aci_string_to_color(value);
|
||||
let selector = crate::ui::color_select::color_selector(
|
||||
cur,
|
||||
open,
|
||||
crate::ui::color_select::ColorExtras {
|
||||
by_layer: true,
|
||||
by_block: true,
|
||||
},
|
||||
move |c| Message::MLeaderStyleEdit {
|
||||
field,
|
||||
value: crate::ui::color_select::color_to_aci_string(c),
|
||||
},
|
||||
Message::MLeaderColorMore(field),
|
||||
);
|
||||
row![text(label).size(11).color(DIM).width(150), swatches]
|
||||
row![text(label).size(11).color(DIM).width(150), selector]
|
||||
.spacing(8)
|
||||
.align_y(iced::Center)
|
||||
.into()
|
||||
@@ -260,7 +243,7 @@ pub fn view_window<'a>(v: MLeaderStyleView<'a>) -> Element<'a, Message> {
|
||||
format!("{:?}", s.path_type),
|
||||
"path_type"
|
||||
),
|
||||
color_row("Line color (ACI):", v.line_color, "line_color"),
|
||||
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"),
|
||||
handle_row(
|
||||
"Line type:",
|
||||
@@ -336,7 +319,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"),
|
||||
color_row("Text color (ACI):", v.text_color, "text_color"),
|
||||
color_row("Text color (ACI):", v.text_color, "text_color", v.color_open == Some("text_color")),
|
||||
enum_row(
|
||||
"Text angle:",
|
||||
opts(&["ParallelToLastLeaderLine", "Horizontal", "Optimized"]),
|
||||
@@ -389,7 +372,7 @@ pub fn view_window<'a>(v: MLeaderStyleView<'a>) -> Element<'a, Message> {
|
||||
v.block_content_name.clone(),
|
||||
"block_content_handle"
|
||||
),
|
||||
color_row("Block color (ACI):", v.block_color, "block_color"),
|
||||
color_row("Block color (ACI):", v.block_color, "block_color", v.color_open == Some("block_color")),
|
||||
enum_row(
|
||||
"Block connection:",
|
||||
opts(&["BlockExtents", "BasePoint"]),
|
||||
|
||||
Reference in new issue
Block a user