From 42ba7f12a01248bf9514a34dccd03f92d6a75d0f Mon Sep 17 00:00:00 2001 From: Karim Jerbi Date: Sun, 18 Oct 2026 11:03:54 +0100 Subject: [PATCH] fix(form): unify style manager field styling --- src/ui/style/dimstyle.rs | 22 +--------------------- src/ui/style/form.rs | 15 ++++++++++++++- src/ui/style/plotstyle.rs | 22 +--------------------- src/ui/style/point_style.rs | 24 ++---------------------- src/ui/style/scale_manager.rs | 23 ++--------------------- src/ui/style/tablestyle.rs | 1 + src/ui/style/textstyle.rs | 23 ++--------------------- 7 files changed, 23 insertions(+), 107 deletions(-) diff --git a/src/ui/style/dimstyle.rs b/src/ui/style/dimstyle.rs index 8c362826a..460f956a4 100644 --- a/src/ui/style/dimstyle.rs +++ b/src/ui/style/dimstyle.rs @@ -4,7 +4,7 @@ use crate::app::{ColorPickTarget, DsField, Message}; use crate::scene::convert::tessellate::{arrow_from_block_name, ArrowKind}; use crate::t; use crate::ui::style::common::muted_style; -use crate::ui::style::form::hdivider; +use crate::ui::style::form::{field_style, hdivider}; use iced::widget::{ button, canvas, checkbox, column, container, row, scrollable, text, text_input, Space, }; @@ -137,26 +137,6 @@ fn tab_btn_style(active: bool) -> impl Fn(&Theme, button::Status) -> button::Sty } } -fn field_style(theme: &Theme, status: text_input::Status) -> text_input::Style { - let palette = theme.palette(); - let border = match status { - text_input::Status::Focused { .. } => palette.primary.base.color, - _ => palette.background.neutral.color, - }; - text_input::Style { - background: Background::Color(palette.background.base.color), - border: Border { - color: border, - width: 1.0, - radius: 3.0.into(), - }, - icon: palette.background.base.text, - placeholder: palette.background.base.text.scale_alpha(0.48), - value: palette.background.base.text, - selection: palette.primary.base.color.scale_alpha(0.5), - } -} - fn primary_style(theme: &Theme) -> iced::widget::text::Style { iced::widget::text::Style { color: Some(theme.palette().primary.base.color), diff --git a/src/ui/style/form.rs b/src/ui/style/form.rs index 91136217d..ec6fe09e5 100644 --- a/src/ui/style/form.rs +++ b/src/ui/style/form.rs @@ -96,6 +96,19 @@ pub fn button_style(accent: bool) -> impl Fn(&Theme, button::Status) -> button:: /// Text field: base background, neutral border that turns primary on focus. pub fn field_style(theme: &Theme, status: text_input::Status) -> text_input::Style { + field_style_with_radius(theme, status, 3.0) +} + +/// Shared text-field styling with a caller-selected corner radius. +/// +/// The default dialog radius is 3px. A small number of compact dialogs use +/// 4px; they can preserve that visual choice without duplicating the palette +/// and focus-border logic. +pub fn field_style_with_radius( + theme: &Theme, + status: text_input::Status, + radius: f32, +) -> text_input::Style { let palette = theme.palette(); let border = match status { text_input::Status::Focused { .. } => palette.primary.base.color, @@ -106,7 +119,7 @@ pub fn field_style(theme: &Theme, status: text_input::Status) -> text_input::Sty border: Border { color: border, width: 1.0, - radius: 3.0.into(), + radius: radius.into(), }, icon: palette.background.base.text, placeholder: palette.background.base.text.scale_alpha(0.48), diff --git a/src/ui/style/plotstyle.rs b/src/ui/style/plotstyle.rs index 77af540ad..31cbe6fc0 100644 --- a/src/ui/style/plotstyle.rs +++ b/src/ui/style/plotstyle.rs @@ -3,7 +3,7 @@ use crate::app::Message; use crate::t; use crate::ui::style::common::muted_style; -use crate::ui::style::form::{hdivider, vsep}; +use crate::ui::style::form::{field_style, hdivider, vsep}; use iced::widget::{button, column, container, row, scrollable, text, text_input, Space}; use iced::{Background, Border, Element, Theme}; use std::borrow::Cow; @@ -62,26 +62,6 @@ fn btn_s(accent: bool) -> impl Fn(&Theme, button::Status) -> button::Style { } } -fn field_style(theme: &Theme, status: text_input::Status) -> text_input::Style { - let palette = theme.palette(); - let border = match status { - text_input::Status::Focused { .. } => palette.primary.base.color, - _ => palette.background.neutral.color, - }; - text_input::Style { - background: Background::Color(palette.background.base.color), - border: Border { - color: border, - width: 1.0, - radius: 3.0.into(), - }, - icon: palette.background.base.text, - placeholder: palette.background.base.text.scale_alpha(0.48), - value: palette.background.base.text, - selection: palette.primary.base.color.scale_alpha(0.5), - } -} - /// Layer names bucketed by ACI (AutoCAD Color Index), index = ACI. /// /// Pure function of `document.layers`: one entry per layer whose color is diff --git a/src/ui/style/point_style.rs b/src/ui/style/point_style.rs index 45d195761..2184c1ba9 100644 --- a/src/ui/style/point_style.rs +++ b/src/ui/style/point_style.rs @@ -8,7 +8,7 @@ use crate::app::Message; use crate::t; use crate::ui::style::common::muted_style; -use crate::ui::style::form::{dialog_button, form_radio}; +use crate::ui::style::form::{dialog_button, field_style_with_radius, form_radio}; use iced::widget::{button, canvas, column, container, row, text, text_input, Space}; use iced::{mouse, Background, Border, Element, Length, Point, Rectangle, Size, Theme}; use std::borrow::Cow; @@ -119,26 +119,6 @@ fn cell<'a>(value: i16, selected: bool) -> Element<'a, Message> { .into() } -fn field_style(theme: &Theme, status: text_input::Status) -> text_input::Style { - let palette = theme.palette(); - let border = match status { - text_input::Status::Focused { .. } => palette.primary.base.color, - _ => palette.background.neutral.color, - }; - text_input::Style { - background: Background::Color(palette.background.base.color), - border: Border { - color: border, - width: 1.0, - radius: 4.0.into(), - }, - icon: palette.background.base.text, - placeholder: palette.background.base.text.scale_alpha(0.48), - value: palette.background.base.text, - selection: palette.primary.base.color.scale_alpha(0.5), - } -} - pub fn view_window<'a>( pdmode: i16, relative: bool, @@ -164,7 +144,7 @@ pub fn view_window<'a>( text_input("0", size_buf) .on_input(Message::PointStyleSizeInput) .on_submit(Message::PointStyleApplySize) - .style(field_style) + .style(|theme, status| field_style_with_radius(theme, status, 4.0)) .size(13) .width(110), Space::new().width(6), diff --git a/src/ui/style/scale_manager.rs b/src/ui/style/scale_manager.rs index cf59358a9..c94224adb 100644 --- a/src/ui/style/scale_manager.rs +++ b/src/ui/style/scale_manager.rs @@ -7,6 +7,7 @@ use crate::app::Message; use crate::t; +use crate::ui::style::form::field_style_with_radius; use crate::ui::style::style_manager::{hdivider, muted_text_style, tb_button, vsep}; use iced::widget::{column, container, mouse_area, row, scrollable, text, text_input, Space}; use iced::{Background, Border, Element, Theme}; @@ -17,26 +18,6 @@ pub fn rename_input_id() -> iced::widget::Id { iced::widget::Id::new("scale-rename-input") } -fn field_style(theme: &Theme, status: text_input::Status) -> text_input::Style { - let palette = theme.palette(); - let border = match status { - text_input::Status::Focused { .. } => palette.primary.base.color, - _ => palette.background.neutral.color, - }; - text_input::Style { - background: Background::Color(palette.background.base.color), - border: Border { - color: border, - width: 1.0, - radius: 4.0.into(), - }, - icon: palette.background.base.text, - placeholder: palette.background.base.text.scale_alpha(0.48), - value: palette.background.base.text, - selection: palette.primary.base.color.scale_alpha(0.5), - } -} - /// `scales` is (name, "paper:drawing" ratio label). The editor buffers hold the /// name / paper / drawing of the row being added or edited. pub fn view_window<'a, 'b>( @@ -154,7 +135,7 @@ pub fn view_window<'a, 'b>( text(label).size(11).style(muted_text_style).width(96), text_input(ph.as_ref(), value) .on_input(on) - .style(field_style) + .style(|theme, status| field_style_with_radius(theme, status, 4.0)) .size(12) .padding([5, 8]) .width(sizing.width), diff --git a/src/ui/style/tablestyle.rs b/src/ui/style/tablestyle.rs index f9ca8dac7..c7b0bd8b9 100644 --- a/src/ui/style/tablestyle.rs +++ b/src/ui/style/tablestyle.rs @@ -332,6 +332,7 @@ fn input_row<'a>( text(label).size(11).style(muted_style).width(155), text_input(placeholder, value) .on_input(message) + .style(crate::ui::style::form::field_style) .size(11) .width(170), ] diff --git a/src/ui/style/textstyle.rs b/src/ui/style/textstyle.rs index 296fb41bd..982a41320 100644 --- a/src/ui/style/textstyle.rs +++ b/src/ui/style/textstyle.rs @@ -3,10 +3,11 @@ use crate::app::{Message, StyleKind}; use crate::t; use crate::ui::style::common::muted_style; +use crate::ui::style::form::field_style; use iced::widget::{ button, canvas, checkbox, column, container, row, scrollable, text, text_input, }; -use iced::{mouse, Background, Border, Element, Length, Point, Rectangle, Theme}; +use iced::{mouse, Background, Element, Length, Point, Rectangle, Theme}; use std::borrow::Cow; pub struct TextStyleView<'a> { @@ -45,26 +46,6 @@ fn primary_style(theme: &Theme) -> iced::widget::text::Style { } } -fn field_style(theme: &Theme, status: text_input::Status) -> text_input::Style { - let palette = theme.palette(); - text_input::Style { - background: Background::Color(palette.background.base.color), - border: Border { - color: if matches!(status, text_input::Status::Focused { .. }) { - palette.primary.base.color - } else { - palette.background.neutral.color - }, - width: 1.0, - radius: 3.0.into(), - }, - icon: palette.background.base.text, - placeholder: palette.background.base.text.scale_alpha(0.48), - value: palette.background.base.text, - selection: palette.primary.base.color.scale_alpha(0.5), - } -} - fn list_item(active: bool) -> impl Fn(&Theme, button::Status) -> button::Style { move |theme: &Theme, status| { let palette = theme.palette();