pub struct Style {Show 15 fields
pub fg: Option<Color>,
pub bg: Option<Color>,
pub decoration: Option<Vec<Decoration>>,
pub padding: Option<u8>,
pub padding_top: Option<u8>,
pub padding_bottom: Option<u8>,
pub padding_left: Option<u8>,
pub padding_right: Option<u8>,
pub margin: Option<u8>,
pub margin_top: Option<u8>,
pub margin_bottom: Option<u8>,
pub margin_left: Option<u8>,
pub margin_right: Option<u8>,
pub border_color: Option<Color>,
pub border_style: Option<BorderStyle>,
}Fields§
§fg: Option<Color>§bg: Option<Color>§decoration: Option<Vec<Decoration>>§padding: Option<u8>§padding_top: Option<u8>§padding_bottom: Option<u8>§padding_left: Option<u8>§padding_right: Option<u8>§margin: Option<u8>§margin_top: Option<u8>§margin_bottom: Option<u8>§margin_left: Option<u8>§margin_right: Option<u8>§border_color: Option<Color>§border_style: Option<BorderStyle>Implementations§
Source§impl Style
impl Style
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new default style.
Examples found in repository?
examples/multiple_sources.rs (line 63)
6fn main() {
7 // Create a new Termio instance
8 let mut tcss = Termio::new();
9
10 // Load basic styles from string
11 let base_styles = r#"
12 @element "base" {
13 color: white;
14 background: black;
15 decoration: bold;
16 padding: 1;
17 }
18
19 @element "subtle" {
20 color: i-black;
21 background: black;
22 decoration: italic;
23 }
24 "#;
25
26 // Parse basic styles
27 match tcss.parse(base_styles) {
28 Ok(_) => println!("Basic styles successfully loaded from string!"),
29 Err(e) => {
30 eprintln!("Error parsing basic styles: {}", e);
31 return;
32 }
33 }
34
35 // Load additional styles from file
36 let additional_styles_path = Path::new("examples/styles.tcss");
37 let mut additional_styles = String::new();
38
39 // Read the file
40 let mut file = match File::open(&additional_styles_path) {
41 Ok(file) => file,
42 Err(e) => {
43 eprintln!("Failed to open style file: {}", e);
44 return;
45 }
46 };
47
48 if let Err(e) = file.read_to_string(&mut additional_styles) {
49 eprintln!("Failed to read style file: {}", e);
50 return;
51 }
52
53 // Parse additional styles
54 match tcss.parse(&additional_styles) {
55 Ok(_) => println!("Additional styles successfully loaded from file!"),
56 Err(e) => {
57 eprintln!("Error parsing additional styles: {}", e);
58 return;
59 }
60 }
61
62 // Add another custom style via API
63 let mut custom_style = Style::new();
64 custom_style.fg = Some(Color::Magenta);
65 custom_style.decoration = Some(vec![Decoration::Bold, Decoration::Underline]);
66 custom_style.padding = Some(1);
67 custom_style.padding_left = Some(6);
68 custom_style.padding_right = Some(6);
69 custom_style.border_style = Some(BorderStyle::Rounded);
70
71 // Add style to the parser
72 tcss.add_style("custom", custom_style);
73 println!("Custom style successfully added via API!");
74
75 let style_from_macros = style! {
76 fg: Color::IntenseBlack,
77 bg: Color::Black,
78 decoration: vec![Decoration::Strikethrough],
79 padding: 1,
80 border_style: BorderStyle::Dashed,
81 };
82
83 tcss.add_style("macros", style_from_macros);
84 println!("Macros style successfully added via macros!");
85
86 // Display all styles
87 println!("Examples of using styles from different sources:");
88 println!("{}", "Base style from string".style("base", &tcss));
89 println!("{}", "Subtle style from string".style("subtle", &tcss));
90 println!("{}", "Header from file".style("header", &tcss));
91 println!("{}", "Warning from file".style("warning", &tcss));
92 println!("{}", "Custom style via API".style("custom", &tcss));
93 println!("{}", "Macros style".style("macros", &tcss));
94}Sourcepub fn decoration(self, deco: Vec<Decoration>) -> Self
pub fn decoration(self, deco: Vec<Decoration>) -> Self
Sets the text decoration.
Sourcepub fn padding_top(self, pad: u8) -> Self
pub fn padding_top(self, pad: u8) -> Self
Sets the top padding.
Sourcepub fn padding_bottom(self, pad: u8) -> Self
pub fn padding_bottom(self, pad: u8) -> Self
Sets the bottom padding.
Sourcepub fn padding_left(self, pad: u8) -> Self
pub fn padding_left(self, pad: u8) -> Self
Sets the left padding.
Sourcepub fn padding_right(self, pad: u8) -> Self
pub fn padding_right(self, pad: u8) -> Self
Sets the right padding.
Sourcepub fn margin_top(self, margin: u8) -> Self
pub fn margin_top(self, margin: u8) -> Self
Sets the top margin.
Sourcepub fn margin_bottom(self, margin: u8) -> Self
pub fn margin_bottom(self, margin: u8) -> Self
Sets the bottom margin.
Sourcepub fn margin_left(self, margin: u8) -> Self
pub fn margin_left(self, margin: u8) -> Self
Sets the left margin.
Sourcepub fn margin_right(self, margin: u8) -> Self
pub fn margin_right(self, margin: u8) -> Self
Sets the right margin.
Sourcepub fn border_color(self, color: Color) -> Self
pub fn border_color(self, color: Color) -> Self
Sets the border color.
Sourcepub fn border_style(self, style: BorderStyle) -> Self
pub fn border_style(self, style: BorderStyle) -> Self
Sets the border style.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Style
impl RefUnwindSafe for Style
impl Send for Style
impl Sync for Style
impl Unpin for Style
impl UnwindSafe for Style
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more