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

+1
View File
@@ -10,6 +10,7 @@ pub mod scale_manager;
pub mod anno_object_scale;
pub mod style_manager;
pub mod common;
pub mod row_button;
pub mod form;
pub mod fusion_theme;
+57
View File
@@ -0,0 +1,57 @@
//! Row/header button styles shared by the layers and xref list panels.
//!
//! Centralizes the zebra/selected row-button coloring previously duplicated
//! in `src/ui/window/layers.rs` (`layer_cell_button_style` +
//! `layer_header_button_style`) and `src/ui/window/xref_manager.rs`
//! (`row_button_style`). The two cell copies were functionally byte-identical
//! (Hovered → `background.strong`, selected → `primary.weak`, even →
//! `background.base`, else → `background.weak`); a single source keeps hover,
//! selection, and zebra colors consistent across both panels.
use iced::widget::button;
use iced::{Background, Theme};
/// Cell (row) button style — closure form so both `.style(...)` call sites
/// (`layers.rs`, `xref_manager.rs`) keep their existing shape.
pub(crate) fn cell_button_style(
selected: bool,
index: usize,
) -> impl Fn(&Theme, button::Status) -> button::Style {
move |theme: &Theme, status: button::Status| {
let palette = theme.palette();
let highlighted = matches!(status, button::Status::Hovered);
let pair = if highlighted {
palette.background.strong
} else if 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()
}
}
}
/// Column-header button style (layers panel).
pub(crate) fn 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()
}
}