agg_gui/widgets/text_field/theme.rs
1//! Per-widget colour overrides for [`super::TextField`].
2//!
3//! Split out of `text_field.rs` to keep the main file under the
4//! 800-line cap. See the [`TextFieldTheme`] struct + the
5//! `with_theme` builder method for the public surface.
6
7use super::*;
8
9/// Per-widget colour overrides for [`TextField`]. When set via
10/// [`TextField::with_theme`], paint reads from these instead of
11/// the ambient [`crate::draw_ctx::DrawCtx::visuals`]. Lets callers
12/// theme a single field to match a dialog palette without forking
13/// the global visuals.
14///
15/// Any field set to `None` falls back to the corresponding
16/// `visuals()` colour, so themes can override just what they need
17/// (e.g. background + border for a dark-panel field that still
18/// wants the ambient selection / cursor highlights).
19#[derive(Clone, Copy, Debug, Default)]
20pub struct TextFieldTheme {
21 pub background: Option<Color>,
22 pub text_color: Option<Color>,
23 pub placeholder_color: Option<Color>,
24 pub border_color: Option<Color>,
25 pub border_color_hovered: Option<Color>,
26 pub border_color_focused: Option<Color>,
27 pub selection_bg: Option<Color>,
28 pub selection_bg_unfocused: Option<Color>,
29 pub cursor_color: Option<Color>,
30 pub border_radius: Option<f64>,
31}
32
33impl TextField {
34 /// Install a [`TextFieldTheme`] of per-widget colour overrides.
35 /// Any field set to `None` on the theme falls back to the
36 /// ambient `visuals()` palette, so callers can override just
37 /// what they need (e.g. background + border for a dark-panel
38 /// field that keeps the default selection / cursor highlights).
39 pub fn with_theme(mut self, theme: TextFieldTheme) -> Self {
40 self.theme = theme;
41 self
42 }
43}