Style

Struct Style 

Source
pub struct Style { /* private fields */ }
Expand description

A CSS style builder that provides a fluent API for creating CSS styles.

The Style struct is the main entry point for building CSS styles. It maintains an internal collection of CSS properties and provides methods for adding and manipulating these properties. The fluent API design allows for chaining method calls to create complex styles in a readable, declarative manner.

§Examples

Basic usage:

use mew_css::style;
use mew_css::values::{Color, Size};

let css = style()
    .color(Color::Blue)
    .font_size(Size::Px(16))
    .apply();

The resulting CSS string will be: color: blue; font-size: 16px;

Implementations§

Source§

impl Style

Source

pub fn new() -> Self

Creates a new empty style with no properties.

This is the starting point for building a CSS style. After creating a new style, you can chain method calls to add properties.

§Examples
use mew_css::style::Style;

let style = Style::new();

More commonly, you’ll use the style() function:

use mew_css::style;

let style = style();
Source

pub fn add_property(&mut self, property: Property) -> &mut Self

Adds a property to the style and returns a mutable reference to self.

This is a low-level method used by the property-specific methods. Most users won’t need to call this directly, but it’s useful for extending the library with custom properties.

§Arguments
  • property - The CSS property to add
§Returns

A mutable reference to self for method chaining

§Examples
use mew_css::style;
use mew_css::properties::Property;

let css = style()
    .add_property(Property::new("color", "blue"))
    .add_property(Property::new("font-size", "16px"))
    .apply();
Source

pub fn apply(&self) -> String

Generates the final CSS string from all added properties.

This method should be called after adding all desired properties to generate the CSS string. It formats each property as name: value; and joins them with spaces.

§Returns

A string containing the CSS representation of all properties

§Examples
use mew_css::style;
use mew_css::values::{Color, Size};

let css = style()
    .color(Color::Blue)
    .font_size(Size::Px(16))
    .apply();

assert_eq!(css, "color: blue; font-size: 16px;");
Examples found in repository?
examples/directional_borders.rs (line 11)
4fn main() {
5    // Create a style with directional border properties
6    let css = style()
7        .border_top(Size::Px(1), BorderStyle::Solid, Color::Red)
8        .border_right(Size::Px(2), BorderStyle::Dashed, Color::Blue)
9        .border_bottom(Size::Px(3), BorderStyle::Dotted, Color::Green)
10        .border_left(Size::Px(4), BorderStyle::Double, Color::Black)
11        .apply();
12
13    println!("Generated CSS with directional borders:");
14    println!("{}", css);
15}
More examples
Hide additional examples
examples/basic_style.rs (line 11)
4fn main() {
5    // Create a CSS style using the mew library
6    let css = style()
7        .color(Color::Blue)
8        .background_color(Color::Rgb(240, 240, 240))
9        .font_size(Size::Px(18))
10        .display(Display::Block)
11        .apply();
12
13    println!("Generated CSS: {}", css);
14
15    // Verify the output
16    let expected = "color: blue; background-color: rgb(240, 240, 240); font-size: 18px; display: block;";
17    assert_eq!(css, expected);
18
19    println!("Example completed successfully!");
20}
examples/css_variables.rs (line 21)
5fn main() {
6    // Create CSS variables
7    let primary_color = var("primary-color");
8    let spacing = var("spacing");
9    let display_mode = var("display-mode");
10    let font_weight = var("font-weight");
11
12    // Use CSS variables in style properties
13    // Method 1: Using explicit enum variants
14    let css1 = style()
15        .color(Color::Var(primary_color.clone()))
16        .background_color(Color::Rgba(240, 240, 240, 0.5))
17        .margin(Size::Var(spacing.clone()))
18        .padding(Size::Px(10))
19        .display(Display::Var(display_mode.clone()))
20        .font_weight(FontWeight::Var(font_weight.clone()))
21        .apply();
22
23    // Method 2: Using Into trait
24    let css2 = style()
25        .color(primary_color.clone().into())
26        .background_color(Color::Rgba(240, 240, 240, 0.5))
27        .margin(spacing.clone().into())
28        .padding(Size::Px(10))
29        .display(display_mode.into())
30        .font_weight(font_weight.into())
31        .apply();
32
33    println!("Generated CSS with variables (Method 1): {}", css1);
34    println!("Generated CSS with variables (Method 2): {}", css2);
35}
Source

pub fn build(&self) -> String

Alias for apply() that generates the CSS string.

This method provides an alternative name that might be more intuitive in some contexts.

§Returns

A string containing the CSS representation of all properties

§Examples
use mew_css::style;
use mew_css::values::{Color, Size};

let css = style()
    .color(Color::Blue)
    .font_size(Size::Px(16))
    .build();

assert_eq!(css, "color: blue; font-size: 16px;");
Source

pub fn custom_property<T: Display>(&mut self, name: &str, value: T) -> &mut Self

Adds a custom property with the given name and value.

This method allows you to add any CSS property, including those not explicitly supported by the library. It’s useful for experimental properties, vendor-prefixed properties, or any other property not covered by the built-in methods.

§Arguments
  • name - The CSS property name
  • value - The property value, which can be any type that implements Display
§Returns

A mutable reference to self for method chaining

§Examples
use mew_css::style;

let css = style()
    .custom_property("animation-name", "fade-in")
    .custom_property("animation-duration", "2s")
    .apply();

assert_eq!(css, "animation-name: fade-in; animation-duration: 2s;");
Source

pub fn set_var<T: Display>(&mut self, name: &str, value: T) -> &mut Self

Defines a CSS custom property (CSS variable).

This method adds a CSS variable definition to the style. CSS variables are defined with the -- prefix and can be referenced using the var() function.

§Arguments
  • name - The variable name (with or without the -- prefix)
  • value - The variable value, which can be any type that implements Display
§Returns

A mutable reference to self for method chaining

§Examples
use mew_css::style;

let css = style()
    .set_var("primary-color", "#3366ff")
    .set_var("spacing", "1rem")
    .apply();

assert_eq!(css, "--primary-color: #3366ff; --spacing: 1rem;");

The -- prefix is added automatically if not present:

use mew_css::style;

let css = style()
    .set_var("--primary-color", "#3366ff") // With prefix
    .set_var("spacing", "1rem")            // Without prefix
    .apply();

assert_eq!(css, "--primary-color: #3366ff; --spacing: 1rem;");
Source

pub fn color(&mut self, value: Color) -> &mut Self

Sets the text color of an element.

The color property specifies the color of text content and text decorations. It can be set using named colors, RGB/RGBA values, HSL/HSLA values, or hex codes.

§Arguments
  • value - The color value to set
§Returns

A mutable reference to self for method chaining

§Examples
use mew_css::style;
use mew_css::values::Color;

// Using a named color
let css1 = style().color(Color::Red).apply();

// Using RGB values
let css2 = style().color(Color::Rgb(255, 0, 0)).apply();

// Using RGBA values with transparency
let css3 = style().color(Color::Rgba(255, 0, 0, 0.5)).apply();

// Using a hex color
let css4 = style().color(Color::Hex("#ff0000".to_string())).apply();
Examples found in repository?
examples/basic_style.rs (line 7)
4fn main() {
5    // Create a CSS style using the mew library
6    let css = style()
7        .color(Color::Blue)
8        .background_color(Color::Rgb(240, 240, 240))
9        .font_size(Size::Px(18))
10        .display(Display::Block)
11        .apply();
12
13    println!("Generated CSS: {}", css);
14
15    // Verify the output
16    let expected = "color: blue; background-color: rgb(240, 240, 240); font-size: 18px; display: block;";
17    assert_eq!(css, expected);
18
19    println!("Example completed successfully!");
20}
More examples
Hide additional examples
examples/css_variables.rs (line 15)
5fn main() {
6    // Create CSS variables
7    let primary_color = var("primary-color");
8    let spacing = var("spacing");
9    let display_mode = var("display-mode");
10    let font_weight = var("font-weight");
11
12    // Use CSS variables in style properties
13    // Method 1: Using explicit enum variants
14    let css1 = style()
15        .color(Color::Var(primary_color.clone()))
16        .background_color(Color::Rgba(240, 240, 240, 0.5))
17        .margin(Size::Var(spacing.clone()))
18        .padding(Size::Px(10))
19        .display(Display::Var(display_mode.clone()))
20        .font_weight(FontWeight::Var(font_weight.clone()))
21        .apply();
22
23    // Method 2: Using Into trait
24    let css2 = style()
25        .color(primary_color.clone().into())
26        .background_color(Color::Rgba(240, 240, 240, 0.5))
27        .margin(spacing.clone().into())
28        .padding(Size::Px(10))
29        .display(display_mode.into())
30        .font_weight(font_weight.into())
31        .apply();
32
33    println!("Generated CSS with variables (Method 1): {}", css1);
34    println!("Generated CSS with variables (Method 2): {}", css2);
35}
Source

pub fn background_color(&mut self, value: Color) -> &mut Self

Sets the background color of an element.

The background-color property sets the background color of an element. The background covers the element’s content, padding, and border areas.

§Arguments
  • value - The color value to set
§Returns

A mutable reference to self for method chaining

§Examples
use mew_css::style;
use mew_css::values::Color;

// Using a named color
let css1 = style().background_color(Color::LightGray).apply();

// Using RGB values
let css2 = style().background_color(Color::Rgb(240, 240, 240)).apply();

// Using RGBA values with transparency
let css3 = style().background_color(Color::Rgba(240, 240, 240, 0.5)).apply();
Examples found in repository?
examples/basic_style.rs (line 8)
4fn main() {
5    // Create a CSS style using the mew library
6    let css = style()
7        .color(Color::Blue)
8        .background_color(Color::Rgb(240, 240, 240))
9        .font_size(Size::Px(18))
10        .display(Display::Block)
11        .apply();
12
13    println!("Generated CSS: {}", css);
14
15    // Verify the output
16    let expected = "color: blue; background-color: rgb(240, 240, 240); font-size: 18px; display: block;";
17    assert_eq!(css, expected);
18
19    println!("Example completed successfully!");
20}
More examples
Hide additional examples
examples/css_variables.rs (line 16)
5fn main() {
6    // Create CSS variables
7    let primary_color = var("primary-color");
8    let spacing = var("spacing");
9    let display_mode = var("display-mode");
10    let font_weight = var("font-weight");
11
12    // Use CSS variables in style properties
13    // Method 1: Using explicit enum variants
14    let css1 = style()
15        .color(Color::Var(primary_color.clone()))
16        .background_color(Color::Rgba(240, 240, 240, 0.5))
17        .margin(Size::Var(spacing.clone()))
18        .padding(Size::Px(10))
19        .display(Display::Var(display_mode.clone()))
20        .font_weight(FontWeight::Var(font_weight.clone()))
21        .apply();
22
23    // Method 2: Using Into trait
24    let css2 = style()
25        .color(primary_color.clone().into())
26        .background_color(Color::Rgba(240, 240, 240, 0.5))
27        .margin(spacing.clone().into())
28        .padding(Size::Px(10))
29        .display(display_mode.into())
30        .font_weight(font_weight.into())
31        .apply();
32
33    println!("Generated CSS with variables (Method 1): {}", css1);
34    println!("Generated CSS with variables (Method 2): {}", css2);
35}
Source

pub fn border_color(&mut self, value: Color) -> &mut Self

Set the border-color property

Source

pub fn width(&mut self, value: Size) -> &mut Self

Sets the width of an element.

The width property sets the width of an element’s content area. It can be specified in various units like pixels, percentages, or relative units.

§Arguments
  • value - The width value to set
§Returns

A mutable reference to self for method chaining

§Examples
use mew_css::style;
use mew_css::values::Size;

// Fixed width in pixels
let css1 = style().width(Size::Px(300)).apply();

// Percentage width (relative to parent)
let css2 = style().width(Size::Percent(100.0)).apply();

// Auto width
let css3 = style().width(Size::Auto).apply();

// Viewport-relative width
let css4 = style().width(Size::Vw(50.0)).apply();
Source

pub fn height(&mut self, value: Size) -> &mut Self

Sets the height of an element.

The height property sets the height of an element’s content area. Like width, it can be specified in various units.

§Arguments
  • value - The height value to set
§Returns

A mutable reference to self for method chaining

§Examples
use mew_css::style;
use mew_css::values::Size;

// Fixed height in pixels
let css1 = style().height(Size::Px(200)).apply();

// Percentage height (requires parent to have a defined height)
let css2 = style().height(Size::Percent(100.0)).apply();

// Viewport-relative height
let css3 = style().height(Size::Vh(100.0)).apply();
Source

pub fn margin(&mut self, value: Size) -> &mut Self

Sets the margin around an element.

The margin property creates space around an element, outside of any defined borders. It sets the margin on all four sides at once (top, right, bottom, left).

§Arguments
  • value - The margin value to set
§Returns

A mutable reference to self for method chaining

§Examples
use mew_css::style;
use mew_css::values::Size;

// Fixed margin in pixels
let css1 = style().margin(Size::Px(10)).apply();

// Auto margin (useful for horizontal centering)
let css2 = style().margin(Size::Auto).apply();

// Relative margin using em
let css3 = style().margin(Size::Em(1.5)).apply();

For directional margins, use the specific methods: margin_top(), margin_right(), margin_bottom(), margin_left()

Examples found in repository?
examples/css_variables.rs (line 17)
5fn main() {
6    // Create CSS variables
7    let primary_color = var("primary-color");
8    let spacing = var("spacing");
9    let display_mode = var("display-mode");
10    let font_weight = var("font-weight");
11
12    // Use CSS variables in style properties
13    // Method 1: Using explicit enum variants
14    let css1 = style()
15        .color(Color::Var(primary_color.clone()))
16        .background_color(Color::Rgba(240, 240, 240, 0.5))
17        .margin(Size::Var(spacing.clone()))
18        .padding(Size::Px(10))
19        .display(Display::Var(display_mode.clone()))
20        .font_weight(FontWeight::Var(font_weight.clone()))
21        .apply();
22
23    // Method 2: Using Into trait
24    let css2 = style()
25        .color(primary_color.clone().into())
26        .background_color(Color::Rgba(240, 240, 240, 0.5))
27        .margin(spacing.clone().into())
28        .padding(Size::Px(10))
29        .display(display_mode.into())
30        .font_weight(font_weight.into())
31        .apply();
32
33    println!("Generated CSS with variables (Method 1): {}", css1);
34    println!("Generated CSS with variables (Method 2): {}", css2);
35}
Source

pub fn margin_top(&mut self, value: Size) -> &mut Self

Set the margin-top property

Source

pub fn margin_right(&mut self, value: Size) -> &mut Self

Set the margin-right property

Source

pub fn margin_bottom(&mut self, value: Size) -> &mut Self

Set the margin-bottom property

Source

pub fn margin_left(&mut self, value: Size) -> &mut Self

Set the margin-left property

Source

pub fn padding(&mut self, value: Size) -> &mut Self

Set the padding property

Examples found in repository?
examples/css_variables.rs (line 18)
5fn main() {
6    // Create CSS variables
7    let primary_color = var("primary-color");
8    let spacing = var("spacing");
9    let display_mode = var("display-mode");
10    let font_weight = var("font-weight");
11
12    // Use CSS variables in style properties
13    // Method 1: Using explicit enum variants
14    let css1 = style()
15        .color(Color::Var(primary_color.clone()))
16        .background_color(Color::Rgba(240, 240, 240, 0.5))
17        .margin(Size::Var(spacing.clone()))
18        .padding(Size::Px(10))
19        .display(Display::Var(display_mode.clone()))
20        .font_weight(FontWeight::Var(font_weight.clone()))
21        .apply();
22
23    // Method 2: Using Into trait
24    let css2 = style()
25        .color(primary_color.clone().into())
26        .background_color(Color::Rgba(240, 240, 240, 0.5))
27        .margin(spacing.clone().into())
28        .padding(Size::Px(10))
29        .display(display_mode.into())
30        .font_weight(font_weight.into())
31        .apply();
32
33    println!("Generated CSS with variables (Method 1): {}", css1);
34    println!("Generated CSS with variables (Method 2): {}", css2);
35}
Source

pub fn padding_top(&mut self, value: Size) -> &mut Self

Set the padding-top property

Source

pub fn padding_right(&mut self, value: Size) -> &mut Self

Set the padding-right property

Source

pub fn padding_bottom(&mut self, value: Size) -> &mut Self

Set the padding-bottom property

Source

pub fn padding_left(&mut self, value: Size) -> &mut Self

Set the padding-left property

Source

pub fn font_size(&mut self, value: Size) -> &mut Self

Set the font-size property

Examples found in repository?
examples/basic_style.rs (line 9)
4fn main() {
5    // Create a CSS style using the mew library
6    let css = style()
7        .color(Color::Blue)
8        .background_color(Color::Rgb(240, 240, 240))
9        .font_size(Size::Px(18))
10        .display(Display::Block)
11        .apply();
12
13    println!("Generated CSS: {}", css);
14
15    // Verify the output
16    let expected = "color: blue; background-color: rgb(240, 240, 240); font-size: 18px; display: block;";
17    assert_eq!(css, expected);
18
19    println!("Example completed successfully!");
20}
Source

pub fn line_height(&mut self, value: Size) -> &mut Self

Set the line-height property

Source

pub fn border_width(&mut self, value: Size) -> &mut Self

Set the border-width property

Source

pub fn display(&mut self, value: Display) -> &mut Self

Sets how an element is displayed in the layout.

The display property determines how an element is treated in the layout flow and how its children are laid out. This is one of the most important CSS properties for controlling layout.

§Arguments
  • value - The display value to set
§Returns

A mutable reference to self for method chaining

§Examples
use mew_css::style;
use mew_css::values::Display;

// Block layout (element takes up full width)
let css1 = style().display(Display::Block).apply();

// Inline layout (element flows with text)
let css2 = style().display(Display::Inline).apply();

// Flexbox layout
let css3 = style().display(Display::Flex).apply();

// Grid layout
let css4 = style().display(Display::Grid).apply();

// Hide element
let css5 = style().display(Display::None).apply();
Examples found in repository?
examples/basic_style.rs (line 10)
4fn main() {
5    // Create a CSS style using the mew library
6    let css = style()
7        .color(Color::Blue)
8        .background_color(Color::Rgb(240, 240, 240))
9        .font_size(Size::Px(18))
10        .display(Display::Block)
11        .apply();
12
13    println!("Generated CSS: {}", css);
14
15    // Verify the output
16    let expected = "color: blue; background-color: rgb(240, 240, 240); font-size: 18px; display: block;";
17    assert_eq!(css, expected);
18
19    println!("Example completed successfully!");
20}
More examples
Hide additional examples
examples/css_variables.rs (line 19)
5fn main() {
6    // Create CSS variables
7    let primary_color = var("primary-color");
8    let spacing = var("spacing");
9    let display_mode = var("display-mode");
10    let font_weight = var("font-weight");
11
12    // Use CSS variables in style properties
13    // Method 1: Using explicit enum variants
14    let css1 = style()
15        .color(Color::Var(primary_color.clone()))
16        .background_color(Color::Rgba(240, 240, 240, 0.5))
17        .margin(Size::Var(spacing.clone()))
18        .padding(Size::Px(10))
19        .display(Display::Var(display_mode.clone()))
20        .font_weight(FontWeight::Var(font_weight.clone()))
21        .apply();
22
23    // Method 2: Using Into trait
24    let css2 = style()
25        .color(primary_color.clone().into())
26        .background_color(Color::Rgba(240, 240, 240, 0.5))
27        .margin(spacing.clone().into())
28        .padding(Size::Px(10))
29        .display(display_mode.into())
30        .font_weight(font_weight.into())
31        .apply();
32
33    println!("Generated CSS with variables (Method 1): {}", css1);
34    println!("Generated CSS with variables (Method 2): {}", css2);
35}
Source

pub fn position(&mut self, value: Position) -> &mut Self

Sets the positioning method for an element.

The position property specifies how an element is positioned in the document. It works together with the top, right, bottom, and left properties to determine the final position of the element.

§Arguments
  • value - The position value to set
§Returns

A mutable reference to self for method chaining

§Examples
use mew_css::style;
use mew_css::values::{Position, Size};

// Static positioning (default flow)
let css1 = style().position(Position::Static).apply();

// Relative positioning (offset from normal position)
let css2 = style()
    .position(Position::Relative)
    .top(Size::Px(10))
    .left(Size::Px(20))
    .apply();

// Absolute positioning (relative to nearest positioned ancestor)
let css3 = style()
    .position(Position::Absolute)
    .top(Size::Px(0))
    .right(Size::Px(0))
    .apply();

// Fixed positioning (relative to viewport)
let css4 = style()
    .position(Position::Fixed)
    .bottom(Size::Px(20))
    .right(Size::Px(20))
    .apply();
Source

pub fn flex_direction(&mut self, value: FlexDirection) -> &mut Self

Sets the direction of flex items within a flex container.

The flex-direction property establishes the main axis of a flex container, defining the direction in which flex items are placed. This property only applies to elements with display: flex.

§Arguments
  • value - The flex-direction value to set
§Returns

A mutable reference to self for method chaining

§Examples
use mew_css::style;
use mew_css::values::{Display, FlexDirection};

// Create a horizontal flex container (default)
let css1 = style()
    .display(Display::Flex)
    .flex_direction(FlexDirection::Row)
    .apply();

// Create a vertical flex container
let css2 = style()
    .display(Display::Flex)
    .flex_direction(FlexDirection::Column)
    .apply();

// Reverse the order of items
let css3 = style()
    .display(Display::Flex)
    .flex_direction(FlexDirection::RowReverse)
    .apply();
Source

pub fn justify_content(&mut self, value: JustifyContent) -> &mut Self

Set the justify-content property

Source

pub fn align_items(&mut self, value: AlignItems) -> &mut Self

Set the align-items property

Source

pub fn font_weight(&mut self, value: FontWeight) -> &mut Self

Set the font-weight property

Examples found in repository?
examples/css_variables.rs (line 20)
5fn main() {
6    // Create CSS variables
7    let primary_color = var("primary-color");
8    let spacing = var("spacing");
9    let display_mode = var("display-mode");
10    let font_weight = var("font-weight");
11
12    // Use CSS variables in style properties
13    // Method 1: Using explicit enum variants
14    let css1 = style()
15        .color(Color::Var(primary_color.clone()))
16        .background_color(Color::Rgba(240, 240, 240, 0.5))
17        .margin(Size::Var(spacing.clone()))
18        .padding(Size::Px(10))
19        .display(Display::Var(display_mode.clone()))
20        .font_weight(FontWeight::Var(font_weight.clone()))
21        .apply();
22
23    // Method 2: Using Into trait
24    let css2 = style()
25        .color(primary_color.clone().into())
26        .background_color(Color::Rgba(240, 240, 240, 0.5))
27        .margin(spacing.clone().into())
28        .padding(Size::Px(10))
29        .display(display_mode.into())
30        .font_weight(font_weight.into())
31        .apply();
32
33    println!("Generated CSS with variables (Method 1): {}", css1);
34    println!("Generated CSS with variables (Method 2): {}", css2);
35}
Source

pub fn font_family(&mut self, value: &str) -> &mut Self

Set the font-family property

Source

pub fn text_align(&mut self, value: TextAlign) -> &mut Self

Set the text-align property

Source

pub fn font_size_enum(&mut self, value: FontSize) -> &mut Self

Set the font-size property with FontSize enum

Source

pub fn line_height_enum(&mut self, value: LineHeight) -> &mut Self

Set the line-height property with LineHeight enum

Source

pub fn text_decoration(&mut self, value: TextDecoration) -> &mut Self

Set the text-decoration property

Source

pub fn border_style(&mut self, value: BorderStyle) -> &mut Self

Set the border-style property

Source

pub fn border_radius(&mut self, value: Size) -> &mut Self

Set the border-radius property

Source

pub fn border( &mut self, width: Size, style: BorderStyle, color: Color, ) -> &mut Self

Set the border property (shorthand)

Source

pub fn border_top( &mut self, width: Size, style: BorderStyle, color: Color, ) -> &mut Self

Set the border-top property (shorthand)

Examples found in repository?
examples/directional_borders.rs (line 7)
4fn main() {
5    // Create a style with directional border properties
6    let css = style()
7        .border_top(Size::Px(1), BorderStyle::Solid, Color::Red)
8        .border_right(Size::Px(2), BorderStyle::Dashed, Color::Blue)
9        .border_bottom(Size::Px(3), BorderStyle::Dotted, Color::Green)
10        .border_left(Size::Px(4), BorderStyle::Double, Color::Black)
11        .apply();
12
13    println!("Generated CSS with directional borders:");
14    println!("{}", css);
15}
Source

pub fn border_right( &mut self, width: Size, style: BorderStyle, color: Color, ) -> &mut Self

Set the border-right property (shorthand)

Examples found in repository?
examples/directional_borders.rs (line 8)
4fn main() {
5    // Create a style with directional border properties
6    let css = style()
7        .border_top(Size::Px(1), BorderStyle::Solid, Color::Red)
8        .border_right(Size::Px(2), BorderStyle::Dashed, Color::Blue)
9        .border_bottom(Size::Px(3), BorderStyle::Dotted, Color::Green)
10        .border_left(Size::Px(4), BorderStyle::Double, Color::Black)
11        .apply();
12
13    println!("Generated CSS with directional borders:");
14    println!("{}", css);
15}
Source

pub fn border_bottom( &mut self, width: Size, style: BorderStyle, color: Color, ) -> &mut Self

Set the border-bottom property (shorthand)

Examples found in repository?
examples/directional_borders.rs (line 9)
4fn main() {
5    // Create a style with directional border properties
6    let css = style()
7        .border_top(Size::Px(1), BorderStyle::Solid, Color::Red)
8        .border_right(Size::Px(2), BorderStyle::Dashed, Color::Blue)
9        .border_bottom(Size::Px(3), BorderStyle::Dotted, Color::Green)
10        .border_left(Size::Px(4), BorderStyle::Double, Color::Black)
11        .apply();
12
13    println!("Generated CSS with directional borders:");
14    println!("{}", css);
15}
Source

pub fn border_left( &mut self, width: Size, style: BorderStyle, color: Color, ) -> &mut Self

Set the border-left property (shorthand)

Examples found in repository?
examples/directional_borders.rs (line 10)
4fn main() {
5    // Create a style with directional border properties
6    let css = style()
7        .border_top(Size::Px(1), BorderStyle::Solid, Color::Red)
8        .border_right(Size::Px(2), BorderStyle::Dashed, Color::Blue)
9        .border_bottom(Size::Px(3), BorderStyle::Dotted, Color::Green)
10        .border_left(Size::Px(4), BorderStyle::Double, Color::Black)
11        .apply();
12
13    println!("Generated CSS with directional borders:");
14    println!("{}", css);
15}
Source

pub fn box_shadow(&mut self, value: BoxShadow) -> &mut Self

Set the box-shadow property

Source

pub fn box_shadow_none(&mut self) -> &mut Self

Set the box-shadow property to none

Source

pub fn top(&mut self, value: Size) -> &mut Self

Set the top property

Source

pub fn right(&mut self, value: Size) -> &mut Self

Set the right property

Source

pub fn bottom(&mut self, value: Size) -> &mut Self

Set the bottom property

Source

pub fn left(&mut self, value: Size) -> &mut Self

Set the left property

Source

pub fn z_index(&mut self, value: ZIndex) -> &mut Self

Set the z-index property

Source

pub fn overflow(&mut self, value: Overflow) -> &mut Self

Set the overflow property

Source

pub fn overflow_x(&mut self, value: Overflow) -> &mut Self

Set the overflow-x property

Source

pub fn overflow_y(&mut self, value: Overflow) -> &mut Self

Set the overflow-y property

Source

pub fn visibility(&mut self, value: Visibility) -> &mut Self

Set the visibility property

Source

pub fn opacity(&mut self, value: f32) -> &mut Self

Set the opacity property

Source

pub fn cursor(&mut self, value: Cursor) -> &mut Self

Set the cursor property

Source

pub fn gap(&mut self, value: Size) -> &mut Self

Set the gap property

Source

pub fn row_gap(&mut self, value: Size) -> &mut Self

Set the row-gap property

Source

pub fn column_gap(&mut self, value: Size) -> &mut Self

Set the column-gap property

Source

pub fn grid_template_columns(&mut self, value: &str) -> &mut Self

Set the grid-template-columns property

Source

pub fn grid_template_rows(&mut self, value: &str) -> &mut Self

Set the grid-template-rows property

Source

pub fn transition(&mut self, value: Transition) -> &mut Self

Set the transition property

Source

pub fn transition_none(&mut self) -> &mut Self

Set the transition property to none

Source

pub fn transition_all( &mut self, duration: f32, timing_function: Option<&str>, delay: Option<f32>, ) -> &mut Self

Set the transition property to all

Source

pub fn max_width(&mut self, value: Size) -> &mut Self

Set the max-width property

Source

pub fn min_width(&mut self, value: Size) -> &mut Self

Set the min-width property

Source

pub fn max_height(&mut self, value: Size) -> &mut Self

Set the max-height property

Source

pub fn min_height(&mut self, value: Size) -> &mut Self

Set the min-height property

Trait Implementations§

Source§

impl Debug for Style

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Style

Source§

fn default() -> Style

Returns the “default value” for a type. Read more
Source§

impl Display for Style

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.