fix(form): unify style manager field styling

This commit is contained in:
Karim Jerbi committed 2026-10-18 11:03:54 +01:00
1 parent ddbfb8f72b
commit 42ba7f12a0
7 files changed
+23 -107

No files matched your search

+1 -21
View File
@@ -4,7 +4,7 @@ use crate::app::{ColorPickTarget, DsField, Message};
use crate::scene::convert::tessellate::{arrow_from_block_name, ArrowKind}; use crate::scene::convert::tessellate::{arrow_from_block_name, ArrowKind};
use crate::t; use crate::t;
use crate::ui::style::common::muted_style; use crate::ui::style::common::muted_style;
use crate::ui::style::form::hdivider; use crate::ui::style::form::{field_style, hdivider};
use iced::widget::{ use iced::widget::{
button, canvas, checkbox, column, container, row, scrollable, text, text_input, Space, 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 { fn primary_style(theme: &Theme) -> iced::widget::text::Style {
iced::widget::text::Style { iced::widget::text::Style {
color: Some(theme.palette().primary.base.color), color: Some(theme.palette().primary.base.color),
+14 -1
View File
@@ -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. /// Text field: base background, neutral border that turns primary on focus.
pub fn field_style(theme: &Theme, status: text_input::Status) -> text_input::Style { 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 palette = theme.palette();
let border = match status { let border = match status {
text_input::Status::Focused { .. } => palette.primary.base.color, 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 { border: Border {
color: border, color: border,
width: 1.0, width: 1.0,
radius: 3.0.into(), radius: radius.into(),
}, },
icon: palette.background.base.text, icon: palette.background.base.text,
placeholder: palette.background.base.text.scale_alpha(0.48), placeholder: palette.background.base.text.scale_alpha(0.48),
+1 -21
View File
@@ -3,7 +3,7 @@
use crate::app::Message; use crate::app::Message;
use crate::t; use crate::t;
use crate::ui::style::common::muted_style; 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::widget::{button, column, container, row, scrollable, text, text_input, Space};
use iced::{Background, Border, Element, Theme}; use iced::{Background, Border, Element, Theme};
use std::borrow::Cow; 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. /// Layer names bucketed by ACI (AutoCAD Color Index), index = ACI.
/// ///
/// Pure function of `document.layers`: one entry per layer whose color is /// Pure function of `document.layers`: one entry per layer whose color is
+2 -22
View File
@@ -8,7 +8,7 @@
use crate::app::Message; use crate::app::Message;
use crate::t; use crate::t;
use crate::ui::style::common::muted_style; 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::widget::{button, canvas, column, container, row, text, text_input, Space};
use iced::{mouse, Background, Border, Element, Length, Point, Rectangle, Size, Theme}; use iced::{mouse, Background, Border, Element, Length, Point, Rectangle, Size, Theme};
use std::borrow::Cow; use std::borrow::Cow;
@@ -119,26 +119,6 @@ fn cell<'a>(value: i16, selected: bool) -> Element<'a, Message> {
.into() .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>( pub fn view_window<'a>(
pdmode: i16, pdmode: i16,
relative: bool, relative: bool,
@@ -164,7 +144,7 @@ pub fn view_window<'a>(
text_input("0", size_buf) text_input("0", size_buf)
.on_input(Message::PointStyleSizeInput) .on_input(Message::PointStyleSizeInput)
.on_submit(Message::PointStyleApplySize) .on_submit(Message::PointStyleApplySize)
.style(field_style) .style(|theme, status| field_style_with_radius(theme, status, 4.0))
.size(13) .size(13)
.width(110), .width(110),
Space::new().width(6), Space::new().width(6),
+2 -21
View File
@@ -7,6 +7,7 @@
use crate::app::Message; use crate::app::Message;
use crate::t; 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 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::widget::{column, container, mouse_area, row, scrollable, text, text_input, Space};
use iced::{Background, Border, Element, Theme}; 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") 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 /// `scales` is (name, "paper:drawing" ratio label). The editor buffers hold the
/// name / paper / drawing of the row being added or edited. /// name / paper / drawing of the row being added or edited.
pub fn view_window<'a, 'b>( 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(label).size(11).style(muted_text_style).width(96),
text_input(ph.as_ref(), value) text_input(ph.as_ref(), value)
.on_input(on) .on_input(on)
.style(field_style) .style(|theme, status| field_style_with_radius(theme, status, 4.0))
.size(12) .size(12)
.padding([5, 8]) .padding([5, 8])
.width(sizing.width), .width(sizing.width),
+1
View File
@@ -332,6 +332,7 @@ fn input_row<'a>(
text(label).size(11).style(muted_style).width(155), text(label).size(11).style(muted_style).width(155),
text_input(placeholder, value) text_input(placeholder, value)
.on_input(message) .on_input(message)
.style(crate::ui::style::form::field_style)
.size(11) .size(11)
.width(170), .width(170),
] ]
+2 -21
View File
@@ -3,10 +3,11 @@
use crate::app::{Message, StyleKind}; use crate::app::{Message, StyleKind};
use crate::t; use crate::t;
use crate::ui::style::common::muted_style; use crate::ui::style::common::muted_style;
use crate::ui::style::form::field_style;
use iced::widget::{ use iced::widget::{
button, canvas, checkbox, column, container, row, scrollable, text, text_input, 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; use std::borrow::Cow;
pub struct TextStyleView<'a> { 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 { fn list_item(active: bool) -> impl Fn(&Theme, button::Status) -> button::Style {
move |theme: &Theme, status| { move |theme: &Theme, status| {
let palette = theme.palette(); let palette = theme.palette();