polyhorn_ui/styles/text.rs
1use strum_macros::EnumString;
2
3use super::Inherited;
4use crate::color::Color;
5use crate::font::{FontFamily, FontSize, FontStyle, FontWeight};
6
7/// Controls the alignment of text in a container that is larger than the text
8/// itself.
9#[derive(Copy, Clone, Debug, Eq, PartialEq, EnumString)]
10pub enum TextAlign {
11 /// Text is aligned to the left edge of the container.
12 #[strum(serialize = "left")]
13 Left,
14
15 /// Text is aligned in the center of the container.
16 #[strum(serialize = "center")]
17 Center,
18
19 /// Text is aligned to the right edge of the container.
20 #[strum(serialize = "right")]
21 Right,
22}
23
24/// Controls the appearance of a Text.
25#[derive(Copy, Clone, Debug, Default, PartialEq)]
26pub struct TextStyle<S = &'static str> {
27 /// This is the color that will be used to fill the text outlines. If not
28 /// present, the Text component will inherit the text color of its parent.
29 /// If the parent does not have a color, the default `Color::canvastext()`
30 /// system color will be used. Note that the concrete value of this color
31 /// is system-dependent and can vary depending on the user's appearance mode
32 /// (i.e. light vs. dark mode).
33 pub color: Inherited<Color>,
34
35 /// This is the font family that will be used to render the text outlines.
36 /// If not present, the Text component will inherit its font family from its
37 /// parent. If the parent does not have a font family, the default
38 /// `FontFamily::Generic(GenericFontFamily::SansSerif)` will be used. Note
39 /// that the concrete value of this font family is system-dependent and can
40 /// vary depending on the user's preferred fonts.
41 pub font_family: Inherited<FontFamily<S>>,
42
43 /// This is the font weight that will be used to render the text outlines.
44 /// If not present, the Text component will inherit its font weight from its
45 /// parent. If the parent does not have a font weight, the default
46 /// `FontWeight::Normal` (400) will be used.
47 pub font_weight: Inherited<FontWeight>,
48
49 /// This is the font style that will be used to render the text outlines. If
50 /// not present, the Text component will inherit its font style from its
51 /// parent. If the parent does not have a font style, the default
52 /// `FontStyle::Normal` will be used.
53 pub font_style: Inherited<FontStyle>,
54
55 /// This is the font size that will be used to render the text. If not
56 /// present, the Text component will inherit its font size from its parent.
57 /// If the parent does not have a font size, the default `FontSize:Medium`
58 /// will be used. Note that the concrete value of this font size is
59 /// system-dependent and can vary depending on a user's preferred font size.
60 pub font_size: Inherited<FontSize>,
61
62 /// Controls the alignment of text when it is rendered to a container that
63 /// is larger than the rendered text.
64 pub text_align: Inherited<TextAlign>,
65}