kas_core/theme/style.rs
1// Licensed under the Apache License, Version 2.0 (the "License");
2// you may not use this file except in compliance with the License.
3// You may obtain a copy of the License in the LICENSE-APACHE file or at:
4// https://www.apache.org/licenses/LICENSE-2.0
5
6//! Theme style components
7
8use crate::dir::Direction;
9
10/// Margin size
11///
12/// Default value: [`MarginStyle::Large`].
13#[crate::impl_default(MarginStyle::Large)]
14#[derive(Copy, Clone, Debug, PartialEq)]
15pub enum MarginStyle {
16 /// No margins
17 None,
18 /// Inner margin, used to draw highlight/selection boxes
19 ///
20 /// Guide size: 1px at 100%, 2px at 125%, 2px at 150%, 3px at 200%.
21 ///
22 /// This is the smallest of the fixed margin sizes, and only really
23 /// useful to reserve space for drawing selection boxes.
24 Inner,
25 /// A small margin for inner layout
26 ///
27 /// Guide size: 2px at 100%, 3px at 125%, 4px at 150%, 5px at 200%.
28 Tiny,
29 /// Small external margin size
30 ///
31 /// Guide size: 4px at 100%, 5px at 125%, 7px at 150%, 9px at 200%.
32 Small,
33 /// Large margin, used between elements such as buttons
34 ///
35 /// Guide size: 7px at 100%, 9px at 125%, 11px at 150%, 15px at 200%.
36 Large,
37 /// Huge margin, used between things like file icons
38 ///
39 /// Guide size: 15px at 100%.
40 Huge,
41 /// Text margins
42 ///
43 /// Margins for use around standard text elements (may be asymmetric).
44 Text,
45 /// Specify in pixels (scaled)
46 Px(f32),
47 /// Specify in Em (font size)
48 Em(f32),
49}
50
51/// Style of marks
52#[derive(Copy, Clone, Debug, PartialEq, Eq, Ord, PartialOrd, Hash)]
53pub enum MarkStyle {
54 /// A chevron (i.e. arrow without stalk) pointing in the given direction
55 Chevron(Direction),
56 /// A cross rotated 45°
57 X,
58 /// Plus (+) symbol
59 Plus,
60 /// Minus (-) symbol
61 Minus,
62}
63
64/// Various features which may be sized and drawn
65///
66/// Includes most types of features excepting text and frames.
67#[derive(Copy, Clone, Debug, PartialEq, Eq, Ord, PartialOrd, Hash)]
68pub enum Feature {
69 Separator,
70 Mark(MarkStyle),
71 CheckBox,
72 RadioBox,
73 ScrollBar(Direction),
74 Slider(Direction),
75 ProgressBar(Direction),
76}
77
78impl From<MarkStyle> for Feature {
79 fn from(style: MarkStyle) -> Self {
80 Feature::Mark(style)
81 }
82}
83
84/// Style of a frame
85///
86/// A "frame" is an element surrounding another element.
87#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Ord, PartialOrd, Hash)]
88pub enum FrameStyle {
89 /// No frame, just draw the background and force margins to be internal
90 #[default]
91 None,
92 /// A frame for grouping content
93 Frame,
94 /// A frame around pop-ups
95 Popup,
96 /// Border around a pop-up menu entry
97 MenuEntry,
98 /// Frame used to indicate navigation focus
99 NavFocus,
100 /// Border of a button
101 Button,
102 /// Border of a button which is visible only when under the mouse
103 InvisibleButton,
104 /// Border of a tab
105 Tab,
106 /// Frame with a background, often used for editable text
107 EditBox,
108 /// Window decoration (excludes top buttons)
109 Window,
110}
111
112/// Selection style hint
113///
114/// How to draw selections
115#[derive(Copy, Clone, Debug, PartialEq, Eq, Ord, PartialOrd, Hash)]
116pub enum SelectionStyle {
117 /// Adjust background color
118 Highlight,
119 /// Draw a frame around the selection
120 Frame,
121 /// Both
122 Both,
123}
124
125impl SelectionStyle {
126 /// True if an external margin is required
127 ///
128 /// Margin size is [`SizeCx::inner_margins`](super::SizeCx::inner_margins)
129 pub fn is_external(self) -> bool {
130 matches!(self, SelectionStyle::Frame | SelectionStyle::Both)
131 }
132}
133
134/// Font "class" selector
135///
136/// Fonts are chosen from available (system) fonts depending on the `TextClass`
137/// and [configuration](crate::config::FontConfig).
138/// `TextClass` may affect other font properties, including size and weight.
139///
140/// Some classes by default appear identical to [`TextClass::Standard`] but may
141/// be configured otherwise by the user.
142#[derive(Copy, Clone, Debug, PartialEq, Eq, Ord, PartialOrd, Hash, linearize::Linearize)]
143#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
144pub enum TextClass {
145 /// The standard UI font
146 ///
147 /// By default this matches the system UI font.
148 Standard,
149 /// Label UI font
150 ///
151 /// This text class should be used by short labels such as those found on
152 /// buttons, menus and other UI controls.
153 ///
154 /// Its appearance is normally identical to [`TextClass::Standard`].
155 Label,
156 /// Small UI font
157 ///
158 /// This class is usually similar to [`TextClass::Standard`] but smaller.
159 Small,
160 /// Editable text
161 ///
162 /// This text class should be preferred for editable text.
163 ///
164 /// Its appearance is normally identical to [`TextClass::Standard`].
165 Editor,
166 /// Serif font
167 ///
168 /// This class may be used where a Serif font is specifically preferred,
169 /// for example in an editor where it is important to be able to distinguish
170 /// all letters.
171 Serif,
172 /// Sans-serif Font
173 ///
174 /// Its appearance is normally identical to [`TextClass::Standard`].
175 SansSerif,
176 /// Monospace font
177 Monospace,
178}