forked from 1b-agent/opencadstudio-upstream
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:
1 parent
7c76d2c27f
commit
c5f8eb2921
4 files changed
+66
-75
No files matched your search
@@ -10,6 +10,7 @@ use crate::io::xref::collect_entries_with_prev;
|
||||
use crate::io::xref_model::{normalize_lexical, Pathtype, RefKind, RefStatus, RefType, ReferenceEntry};
|
||||
use crate::ui::ROW_H;
|
||||
use crate::ui::style::common::muted_style;
|
||||
use crate::ui::style::row_button::cell_button_style;
|
||||
use codec::CadDocument;
|
||||
use iced::widget::{button, column, container, mouse_area, row, scrollable, text, tooltip};
|
||||
use iced::Padding;
|
||||
@@ -1259,27 +1260,6 @@ fn format_date(modified: Option<SystemTime>) -> String {
|
||||
|
||||
// ── Widget helpers (layers.rs conventions) ────────────────────────────────
|
||||
|
||||
fn row_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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn toolbar_btn(label: String, msg: Option<Message>, fill: bool) -> Element<'static, Message> {
|
||||
let mut b = button(text(label).size(11))
|
||||
.style(|theme: &Theme, status| {
|
||||
@@ -1808,7 +1788,7 @@ fn xref_row<'a>(
|
||||
let key = entry.key;
|
||||
let arrow = button(crate::ui::icons::themed_arrow_toggle(is_expanded, 10.0))
|
||||
.on_press(Message::XrefManagerToggleExpand(key))
|
||||
.style(row_button_style(is_selected, display.index))
|
||||
.style(cell_button_style(is_selected, display.index))
|
||||
.padding(Padding {
|
||||
top: 6.0,
|
||||
bottom: 6.0,
|
||||
@@ -1893,7 +1873,7 @@ fn tree_row(
|
||||
let key = entry.key;
|
||||
let arrow = button(crate::ui::icons::themed_arrow_toggle(is_expanded, 10.0))
|
||||
.on_press(Message::XrefManagerToggleExpand(key))
|
||||
.style(row_button_style(is_selected, display.index))
|
||||
.style(cell_button_style(is_selected, display.index))
|
||||
.padding(Padding {
|
||||
top: 6.0,
|
||||
bottom: 6.0,
|
||||
|
||||
Reference in new issue
Block a user