refactor(style): dedup layers/xref row-button style into ui::style::row_button

Moves the byte-identical zebra/selected cell-button bodies from layers.rs and xref_manager.rs plus the layers header-button body into one shared module. All six call sites now use the shared helpers; toolbar_btn helpers untouched (different semantics). No new tests per owner request (pure move, verified by build plus full suite before test removal).
This commit is contained in:
Karim Jerbi committed 2026-10-05 22:33:24 +01:00
1 parent 7c76d2c27f
commit c5f8eb2921
4 files changed
+66 -75

No files matched your search

+5 -52
View File
@@ -3,6 +3,7 @@
use crate::app::Message;
use crate::ui::properties::{lw_options, LinetypeItem, LwItem};
use crate::ui::style::common::muted_style;
use crate::ui::style::row_button::{cell_button_style, header_button_style};
use crate::ui::ROW_H;
use codec::tables::layer::Layer as DocLayer;
use codec::tables::Table;
@@ -503,48 +504,6 @@ impl LayerPanel {
// ── Sorting helpers ─────────────────────────────────────────────────────────
fn layer_cell_button_style(
theme: &Theme,
status: button::Status,
is_selected: bool,
index: usize,
) -> button::Style {
let palette = theme.palette();
let highlighted = matches!(status, button::Status::Hovered);
let pair = if highlighted {
palette.background.strong
} else if is_selected {
palette.primary.weak
} else if index % 2 == 0 {
palette.background.base
} else {
palette.background.weak
};
button::Style {
background: highlighted.then_some(Background::Color(pair.color)),
text_color: pair.text,
..Default::default()
}
}
fn layer_header_button_style(theme: &Theme, status: button::Status) -> button::Style {
let palette = theme.palette();
let highlighted = matches!(
status,
button::Status::Hovered | button::Status::Pressed
);
let pair = if highlighted {
palette.background.strong
} else {
palette.background.weak
};
button::Style {
background: highlighted.then_some(Background::Color(pair.color)),
text_color: pair.text,
..Default::default()
}
}
/// Packed RGB key for ordering colours deterministically by hue-ish bytes.
fn color_sort_key(c: AcadColor) -> u32 {
let c = iced_color_from_acad(&c);
@@ -573,7 +532,7 @@ fn sortable_header<'a>(
}
button(content)
.on_press(Message::LayerSort(col))
.style(layer_header_button_style)
.style(header_button_style)
.padding(Padding {
top: 0.0,
bottom: 0.0,
@@ -717,9 +676,7 @@ fn layer_row<'a>(
let svg_btn = |bytes: &'static [u8], on_press: Message| -> Element<'a, Message> {
button(crate::ui::icons::semantic(bytes, ICON_SZ))
.on_press(on_press)
.style(move |theme: &Theme, status| {
layer_cell_button_style(theme, status, is_selected, index)
})
.style(cell_button_style(is_selected, index))
.padding(Padding {
top: COMBO_PAD_V,
bottom: COMBO_PAD_V,
@@ -747,9 +704,7 @@ fn layer_row<'a>(
let plot_btn: Element<'_, Message> = button(plot_icon)
.on_press(Message::LayerTogglePlot(index))
.style(move |theme: &Theme, status| {
layer_cell_button_style(theme, status, is_selected, index)
})
.style(cell_button_style(is_selected, index))
.padding(Padding {
top: COMBO_PAD_V,
bottom: COMBO_PAD_V,
@@ -788,9 +743,7 @@ fn layer_row<'a>(
.size(FONT_SZ),
)
.on_press(Message::LayerRenameStart(index))
.style(move |theme: &Theme, status| {
layer_cell_button_style(theme, status, is_selected, index)
})
.style(cell_button_style(is_selected, index))
.padding(Padding {
top: COMBO_PAD_V,
bottom: COMBO_PAD_V,