From b8a7f5edfbfba369a62d4da0a98bbadf4b7b6aee Mon Sep 17 00:00:00 2001 From: Karim Jerbi Date: Fri, 18 Sep 2026 13:42:51 +0100 Subject: [PATCH] refactor(ui): centralize hdivider/vsep in style::form Deduplicate the byte-identical 1px divider helpers previously copy-pasted across 6 modules. form::{hdivider, vseparator} is now canonical, with a form::vsep alias for legacy call sites. style_manager re-exports both so scale_manager and anno_object_scale imports keep working unchanged. Delete locals in style_manager, plotstyle, dimstyle, layout_manager, attribute_editor. Replace thin wrappers in window/plot with direct imports. no visual change. --- src/ui/style/dimstyle.rs | 14 +------------- src/ui/style/form.rs | 6 ++++++ src/ui/style/plotstyle.rs | 27 +-------------------------- src/ui/style/style_manager.rs | 26 +------------------------- src/ui/window/attribute_editor.rs | 15 +-------------- src/ui/window/layout_manager.rs | 27 +-------------------------- src/ui/window/plot.rs | 9 +-------- 7 files changed, 12 insertions(+), 112 deletions(-) diff --git a/src/ui/style/dimstyle.rs b/src/ui/style/dimstyle.rs index aed2e9b74..c1d01ccab 100644 --- a/src/ui/style/dimstyle.rs +++ b/src/ui/style/dimstyle.rs @@ -6,6 +6,7 @@ use iced::widget::{ }; use iced::{mouse, Background, Border, Element, Length, Point, Rectangle, Theme}; use crate::ui::style::common::muted_style; +use crate::ui::style::form::hdivider; use crate::t; use std::borrow::Cow; use std::fmt; @@ -263,19 +264,6 @@ impl canvas::Program for DimensionPreview { } } -fn hdivider<'a>(width: iced::Length) -> Element<'a, Message> { - container(Space::new().width(width).height(1)) - .width(width) - .height(1) - .style(|theme: &Theme| container::Style { - background: Some(Background::Color( - theme.palette().background.neutral.color - )), - ..Default::default() - }) - .into() -} - pub fn view_window<'a>( styles: Vec, selected: &'a str, diff --git a/src/ui/style/form.rs b/src/ui/style/form.rs index 6f79d4fec..050fa0eb4 100644 --- a/src/ui/style/form.rs +++ b/src/ui/style/form.rs @@ -83,6 +83,12 @@ pub fn vseparator<'a>(height: Length) -> Element<'a, Message> { .into() } +/// Alias kept for call sites that historically used `vsep`. +/// Same implementation as [`vseparator`]. +pub fn vsep<'a>(height: Length) -> Element<'a, Message> { + vseparator(height) +} + /// Muted section heading. pub fn section_label<'a>(label: Cow<'static, str>) -> Element<'a, Message> { text(label).size(11).style(muted_style).into() diff --git a/src/ui/style/plotstyle.rs b/src/ui/style/plotstyle.rs index 22a01c9e6..cf2b93a0b 100644 --- a/src/ui/style/plotstyle.rs +++ b/src/ui/style/plotstyle.rs @@ -4,6 +4,7 @@ use crate::app::Message; use iced::widget::{button, column, container, row, scrollable, text, text_input, Space}; use iced::{Background, Border, Element, Theme}; use crate::ui::style::common::muted_style; +use crate::ui::style::form::{hdivider, vsep}; use crate::t; use std::borrow::Cow; use std::fmt; @@ -83,32 +84,6 @@ fn field_style(theme: &Theme, status: text_input::Status) -> text_input::Style { } } -fn hdivider<'a>(width: iced::Length) -> Element<'a, Message> { - container(Space::new().width(width).height(1)) - .width(width) - .height(1) - .style(|theme: &Theme| container::Style { - background: Some(Background::Color( - theme.palette().background.neutral.color - )), - ..Default::default() - }) - .into() -} - -fn vsep<'a>(height: iced::Length) -> Element<'a, Message> { - container(Space::new().width(1).height(height)) - .width(1) - .height(height) - .style(|theme: &Theme| container::Style { - background: Some(Background::Color( - theme.palette().background.neutral.color - )), - ..Default::default() - }) - .into() -} - pub fn view_window<'a>( document: &'a acadrust::CadDocument, table: Option<&'a crate::io::plot_style::PlotStyleTable>, diff --git a/src/ui/style/style_manager.rs b/src/ui/style/style_manager.rs index 64cc1be9d..7595f48ff 100644 --- a/src/ui/style/style_manager.rs +++ b/src/ui/style/style_manager.rs @@ -327,28 +327,4 @@ pub(crate) fn muted_text_style(theme: &Theme) -> iced::widget::text::Style { crate::ui::style::common::muted_style(theme) } -pub(crate) fn hdivider<'a>(width: iced::Length) -> Element<'a, Message> { - container(Space::new().width(width).height(1)) - .width(width) - .height(1) - .style(|theme: &Theme| container::Style { - background: Some(Background::Color( - theme.palette().background.neutral.color - )), - ..Default::default() - }) - .into() -} - -pub(crate) fn vsep<'a>(height: iced::Length) -> Element<'a, Message> { - container(Space::new().width(1).height(height)) - .width(1) - .height(height) - .style(|theme: &Theme| container::Style { - background: Some(Background::Color( - theme.palette().background.neutral.color - )), - ..Default::default() - }) - .into() -} +pub(crate) use crate::ui::style::form::{hdivider, vsep}; diff --git a/src/ui/window/attribute_editor.rs b/src/ui/window/attribute_editor.rs index 65dc18914..2f43d9f59 100644 --- a/src/ui/window/attribute_editor.rs +++ b/src/ui/window/attribute_editor.rs @@ -25,6 +25,7 @@ use std::borrow::Cow; use std::fmt; use crate::ui::properties::{lw_options, LwItem}; +use crate::ui::style::form::hdivider; const LABEL_W: f32 = 120.0; @@ -161,20 +162,6 @@ fn field_style(theme: &Theme, status: text_input::Status) -> text_input::Style { } } -/// Horizontal 1px divider in the shared border colour (matches style windows). -fn hdivider<'a>(width: Length) -> Element<'a, Message> { - container(Space::new().width(width).height(1)) - .width(width) - .height(1) - .style(|theme: &Theme| container::Style { - background: Some(Background::Color( - theme.palette().background.neutral.color - )), - ..Default::default() - }) - .into() -} - /// One `label : widget` row with a fixed-width label column. fn field_row<'a>( label: Cow<'static, str>, diff --git a/src/ui/window/layout_manager.rs b/src/ui/window/layout_manager.rs index 4891a2c0f..1f30938fb 100644 --- a/src/ui/window/layout_manager.rs +++ b/src/ui/window/layout_manager.rs @@ -1,6 +1,7 @@ //! Layout Manager window — fills the entire OS window. use crate::app::Message; +use crate::ui::style::form::{hdivider, vsep}; use iced::widget::{button, column, container, row, scrollable, text, text_input, Space}; use iced::{Background, Element, Theme}; use crate::t; @@ -37,32 +38,6 @@ fn list_item(active: bool) -> impl Fn(&Theme, button::Status) -> button::Style { } } -fn hdivider<'a>(width: iced::Length) -> Element<'a, Message> { - container(Space::new().width(width).height(1)) - .width(width) - .height(1) - .style(|theme: &Theme| container::Style { - background: Some(Background::Color( - theme.palette().background.neutral.color, - )), - ..Default::default() - }) - .into() -} - -fn vsep<'a>(height: iced::Length) -> Element<'a, Message> { - container(Space::new().width(1).height(height)) - .width(1) - .height(height) - .style(|theme: &Theme| container::Style { - background: Some(Background::Color( - theme.palette().background.neutral.color, - )), - ..Default::default() - }) - .into() -} - pub fn view_window<'a>( layouts: Vec, selected: &'a str, diff --git a/src/ui/window/plot.rs b/src/ui/window/plot.rs index 451860c9a..21b0936f3 100644 --- a/src/ui/window/plot.rs +++ b/src/ui/window/plot.rs @@ -9,6 +9,7 @@ use crate::io::paper_catalog::{self, CustomPaper, Margins, PaperSize, PaperUnits use crate::io::plot_device::PrinterCapabilities; use crate::ui::style::common::muted_style; use crate::ui::style::form; +use crate::ui::style::form::{hdivider, vseparator as vsep}; use iced::widget::{ button, checkbox, column, container, mouse_area, row, scrollable, text, text_input, Space, @@ -543,18 +544,10 @@ fn btn(accent: bool) -> impl Fn(&Theme, button::Status) -> button::Style { form::button_style(accent) } -fn hdivider<'a>(width: Length) -> Element<'a, Message> { - form::hdivider(width) -} - fn section_label<'a>(s: Cow<'static, str>) -> Element<'a, Message> { form::section_label(s) } -fn vsep<'a>(height: Length) -> Element<'a, Message> { - form::vseparator(height) -} - fn setup_row<'a>( name: &'a str, selected: &str,