cabin_tailwind/utilities/
text.rs1use core::fmt;
9
10use crate::{Length, Property, Utility};
11
12const COLOR: &str = "color";
13
14include!(concat!(env!("OUT_DIR"), "/text-color.rs"));
15
16pub fn color(color: &'static str) -> Property {
18 Property(COLOR, color)
19}
20
21include!(concat!(env!("OUT_DIR"), "/font-size.rs"));
22
23pub struct FontSize {
24 font_size: Length,
25 line_height: LineHeight,
26}
27
28#[derive(Debug, Clone, Copy, PartialEq)]
29pub enum LineHeight {
30 Length(Length),
31 Multiple(u16),
32}
33
34pub const fn size(font_size: Length, line_height: LineHeight) -> FontSize {
36 FontSize {
37 font_size,
38 line_height,
39 }
40}
41
42impl Utility for FontSize {
43 fn declarations(&self, f: &mut dyn fmt::Write) -> fmt::Result {
44 writeln!(f, "font-size: {};", self.font_size)?;
45 writeln!(f, "line-height: {};", self.line_height)?;
46 Ok(())
47 }
48}
49
50impl fmt::Display for LineHeight {
51 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
52 match self {
53 LineHeight::Length(l) => l.fmt(f),
54 LineHeight::Multiple(x) => write!(f, "{x}"),
55 }
56 }
57}
58
59const TEXT_ALIGN: &str = "text-align";
60
61pub const LEFT: Property = Property(TEXT_ALIGN, "left");
65
66pub const CENTER: Property = Property(TEXT_ALIGN, "center");
70
71pub const RIGHT: Property = Property(TEXT_ALIGN, "right");
75
76pub const JUSTIFY: Property = Property(TEXT_ALIGN, "justify");
80
81pub const START: Property = Property(TEXT_ALIGN, "start");
85
86pub const END: Property = Property(TEXT_ALIGN, "end");
90
91const TEXT_TRANSFORM: &str = "text-transform";
92
93pub const UPPERCASE: Property = Property(TEXT_TRANSFORM, "uppercase");
97
98pub const LOWERCASE: Property = Property(TEXT_TRANSFORM, "lowercase");
102
103pub const CAPITALIZE: Property = Property(TEXT_TRANSFORM, "capitalize");
107
108pub const NORMAL_CASE: Property = Property(TEXT_TRANSFORM, "none");
112
113const TEXT_OVERFLOW: &str = "text-overflow";
114
115pub const ELLIPSIS: Property = Property(TEXT_OVERFLOW, "ellipsis");
119
120pub const CLIP: Property = Property(TEXT_OVERFLOW, "clip");
124
125pub const TRUNCATE: Truncate = Truncate;
131
132pub struct Truncate;
133
134impl Utility for Truncate {
135 fn declarations(&self, f: &mut dyn fmt::Write) -> fmt::Result {
136 f.write_str("overflow: hidden;")?;
137 f.write_str("text-overflow: ellipsis;")?;
138 f.write_str("white-space: nowrap;")?;
139 Ok(())
140 }
141}