Skip to main content

CssStyle

Struct CssStyle 

Source
pub struct CssStyle {
Show 73 fields pub display: Option<Display>, pub position: Option<Position>, pub top: Option<LengthPercentage>, pub right: Option<LengthPercentage>, pub bottom: Option<LengthPercentage>, pub left: Option<LengthPercentage>, pub width: Option<Size>, pub height: Option<Size>, pub min_width: Option<Size>, pub min_height: Option<Size>, pub max_width: Option<Size>, pub max_height: Option<Size>, pub margin: Option<Edges>, pub padding: Option<Edges>, pub border: Option<BorderEdges>, pub box_sizing: Option<BoxSizing>, pub aspect_ratio: Option<f32>, pub flex_direction: Option<FlexDirection>, pub flex_wrap: Option<FlexWrap>, pub justify_content: Option<JustifyContent>, pub align_items: Option<AlignItems>, pub align_self: Option<AlignSelf>, pub align_content: Option<AlignContent>, pub gap: Option<Gap>, pub flex_grow: Option<f32>, pub flex_shrink: Option<f32>, pub flex_basis: Option<Size>, pub order: Option<i32>, pub grid_template_columns: Option<Vec<GridTrack>>, pub grid_template_rows: Option<Vec<GridTrack>>, pub grid_column: Option<GridLine>, pub grid_row: Option<GridLine>, pub grid_auto_flow: Option<GridAutoFlow>, pub justify_items: Option<JustifyItems>, pub justify_self: Option<JustifySelf>, pub font_family: Option<String>, pub font_size: Option<Length>, pub font_weight: Option<FontWeight>, pub font_style: Option<FontStyle>, pub line_height: Option<LineHeight>, pub letter_spacing: Option<Length>, pub text_align: Option<TextAlign>, pub color: Option<Color>, pub white_space: Option<WhiteSpace>, pub overflow_wrap: Option<OverflowWrap>, pub text_overflow: Option<TextOverflow>, pub text_decoration: Option<TextDecoration>, pub text_autofit: Option<bool>, pub background: Option<Background>, pub border_radius: Option<BorderRadius>, pub box_shadow: Option<Vec<BoxShadow>>, pub text_shadow: Option<Vec<TextShadow>>, pub opacity: Option<f32>, pub mix_blend_mode: Option<BlendMode>, pub clip_path: Option<ClipPath>, pub gradient_border: Option<GradientBorder>, pub backdrop_blur: Option<f32>, pub inner_shadow: Option<InnerShadow>, pub filter: Option<Vec<FilterFn>>, pub backdrop_filter: Option<Vec<FilterFn>>, pub transform: Option<Vec<TransformFn>>, pub transform_origin: Option<TransformOrigin>, pub perspective: Option<Length>, pub perspective_origin: Option<TransformOrigin>, pub depth: Option<f32>, pub overflow: Option<Overflow>, pub overflow_x: Option<Overflow>, pub overflow_y: Option<Overflow>, pub z_index: Option<i32>, pub visibility: Option<Visibility>, pub animation: Vec<AnimationEffect>, pub transition: Option<StyleTransition>, pub audio_reactive: Option<AudioReactive>,
}
Expand description

Top-level CSS style block. All fields are optional; None means “not set” and lets the cascade fill in inherited / initial values.

Fields§

§display: Option<Display>§position: Option<Position>§top: Option<LengthPercentage>§right: Option<LengthPercentage>§bottom: Option<LengthPercentage>§left: Option<LengthPercentage>§width: Option<Size>§height: Option<Size>§min_width: Option<Size>§min_height: Option<Size>§max_width: Option<Size>§max_height: Option<Size>§margin: Option<Edges>§padding: Option<Edges>§border: Option<BorderEdges>§box_sizing: Option<BoxSizing>§aspect_ratio: Option<f32>§flex_direction: Option<FlexDirection>§flex_wrap: Option<FlexWrap>§justify_content: Option<JustifyContent>§align_items: Option<AlignItems>§align_self: Option<AlignSelf>§align_content: Option<AlignContent>§gap: Option<Gap>§flex_grow: Option<f32>§flex_shrink: Option<f32>§flex_basis: Option<Size>§order: Option<i32>§grid_template_columns: Option<Vec<GridTrack>>§grid_template_rows: Option<Vec<GridTrack>>§grid_column: Option<GridLine>§grid_row: Option<GridLine>§grid_auto_flow: Option<GridAutoFlow>§justify_items: Option<JustifyItems>§justify_self: Option<JustifySelf>§font_family: Option<String>§font_size: Option<Length>§font_weight: Option<FontWeight>§font_style: Option<FontStyle>§line_height: Option<LineHeight>§letter_spacing: Option<Length>§text_align: Option<TextAlign>§color: Option<Color>§white_space: Option<WhiteSpace>§overflow_wrap: Option<OverflowWrap>§text_overflow: Option<TextOverflow>§text_decoration: Option<TextDecoration>§text_autofit: Option<bool>

When true on text/gradient_text, the effective font-size is shrunk (never grown) until the content fits the box it was assigned, instead of overflowing it. This is what lets an author declare “this text must fit here” and closes ContentOverflowsBox as a possible validator failure for that node — see apply_fixes (rustmotion/src/cli/commands/validate.rs)’s comment on why it deliberately refuses to auto-fix that violation today: growing the box, shrinking the font, and shortening the copy are all legitimate fixes, and picking one was never this tool’s call to make silently. text-autofit removes that ambiguity by having the author pick “shrink the font” up front.

Which box. Two independent axes, each opt-in on its own:

  • Width: the box’s resolved width — its own width/max-width if set, else whatever it inherited from its parent (exactly the value text/gradient_text already wrap against — see TextIntrinsic/Text::paint). Always present once the node is laid out, so the width axis is always a candidate for shrinking.
  • Height: only when the node’s own box resolves to a definite height (an explicit height, or a parent that hands it one, e.g. a fixed flex-basis) — never an implicit/inherited one. A box that grows to fit its content has, by construction, nothing to overflow on the height axis, so there is nothing to shrink for. See TextIntrinsic::measure / Text::paint’s content_height for exactly how this is read (the same taffy-resolved, padding/border- already-subtracted content-box value on both the pre-layout measure path and the post-layout paint path — this is what guarantees the two agree on the target, not just the algorithm).

white-space: nowrap. Does not change: nowrap still means “never break this into multiple lines”. text-autofit composes with it rather than overriding it — a nowrap line combined with text-autofit: true shrinks the one line until it fits the box’s width (this is text/gradient_text’s answer to Remotion’s fitText()), it does not start wrapping.

auto_scroll (codeblock/terminal). Unrelated: text-autofit is only read by text/gradient_text’s own painter/intrinsic — codeblock/terminal never look at this field, so there is no precedence to resolve between the two; auto_scroll keeps scrolling (never shrinking) exactly as documented in CLAUDE.md.

The floor. Never shrinks below TEXT_AUTOFIT_MIN_FONT_PX — the same calibrated legibility ratio check_legibility (rustmotion/src/cli/commands/geometry.rs) already enforces, not a new threshold. If the content still doesn’t fit at the floor, the floor size is used anyway (illegible-but-smallest beats an even larger overflow) and the geometry validator’s ContentOverflowsBox still fires — text-autofit narrows that failure class, it does not silence it.

§background: Option<Background>§border_radius: Option<BorderRadius>§box_shadow: Option<Vec<BoxShadow>>§text_shadow: Option<Vec<TextShadow>>§opacity: Option<f32>§mix_blend_mode: Option<BlendMode>§clip_path: Option<ClipPath>§gradient_border: Option<GradientBorder>

Gradient-colored border painted instead of border when present. { "colors": [...], "width": 2, "angle": 0 } — angle follows the same convention as background linear gradients.

§backdrop_blur: Option<f32>

Deprecated: use backdrop-filter: [{ "fn": "blur", "radius": N }].

§inner_shadow: Option<InnerShadow>

Deprecated: use box-shadow with "inset": true.

§filter: Option<Vec<FilterFn>>§backdrop_filter: Option<Vec<FilterFn>>§transform: Option<Vec<TransformFn>>§transform_origin: Option<TransformOrigin>§perspective: Option<Length>§perspective_origin: Option<TransformOrigin>§depth: Option<f32>

Parallax plane depth for the scene camera (issue #90). 0 = locked plane (the camera does not affect it), 1 = normal plane (default), above 1 = amplified foreground. v1: effective on direct children of the scene root only (each top-level child is one plane whose depth governs its whole subtree). Not inherited via cascade.

§overflow: Option<Overflow>§overflow_x: Option<Overflow>§overflow_y: Option<Overflow>§z_index: Option<i32>§visibility: Option<Visibility>§animation: Vec<AnimationEffect>§transition: Option<StyleTransition>

Smoothing for timeline style-state changes. Supported properties: opacity; color on text/counter; background (solid colour only) and border-radius (single uniform, absolute-px value only) — see box_builder.rs’s transition_keyframes/ resolve_transition_css_overrides. Everything else — including a background/border-radius value outside the shape those two support (gradients, per-corner radii, %/em/rem/vw/vh) — still snaps at the step’s at; rustmotion validate’s check_transition_smoothing (validate_schema.rs) reports exactly which property and why whenever it would otherwise snap silently.

§audio_reactive: Option<AudioReactive>

Implementations§

Source§

impl CssStyle

Source

pub fn font_size_px_or(&self, default: f32) -> f32

font-size in px, falling back to default when unset.

Source

pub fn font_size_px(&self) -> Option<f32>

font-size in px if set as a length.

Source

pub fn color_str(&self) -> Option<&str>

color as a hex string (only Color::String returns Some).

Source

pub fn color_str_or<'a>(&'a self, default: &'a str) -> &'a str

color as a hex string with default fallback.

Source

pub fn font_family_str(&self) -> Option<&str>

font-family string.

Source

pub fn font_family_or<'a>(&'a self, default: &'a str) -> &'a str

font-family string with default fallback.

Source

pub fn letter_spacing_px(&self) -> f32

letter-spacing in px, defaulting to 0.

Source

pub fn line_height_for(&self, font_size: f32) -> f32

line-height resolution. For Number (unitless) returns n * font_size; for Length(px) returns the px value; otherwise returns 1.3 * font_size.

Source

pub fn font_size_px_ctx(&self, ctx: &LengthContext, default: f32) -> f32

font-size resolved against ctx, correctly handling %/em/rem/vw/vh — unlike Self::font_size_px_or. em/% resolve against ctx.font_size, which the caller should set to the parent’s actual computed font-size in px for correctness (see the module note above on why nothing does that yet).

Source

pub fn letter_spacing_px_ctx(&self, ctx: &LengthContext) -> f32

letter-spacing resolved against ctx, correctly handling %/em/rem/vw/vh — unlike Self::letter_spacing_px. Per CSS, em here means the element’s own font-size, so pass a ctx whose font_size is the already-resolved own font-size (e.g. via Self::font_size_px_ctx), not the parent’s — see Self::typography_px_ctx for a helper that gets this right automatically.

Source

pub fn line_height_for_ctx(&self, font_size: f32, ctx: &LengthContext) -> f32

line-height resolved against ctx, correctly handling %/em/rem/vw/vh — unlike Self::line_height_for. LineHeight::Number (unitless, e.g. 1.5) is unaffected — it always means n * font_size regardless of any context. For LineHeight::Length, % is special-cased to CSS’s actual rule for this property (relative to the element’s own font-size, not ctx.parent_size like % normally means): a generic ParsedLength::resolve would silently resolve it against the wrong base otherwise. Same own-vs-parent em caveat as Self::letter_spacing_px_ctx applies.

Source

pub fn typography_px_ctx( &self, ctx: &LengthContext, default_font_size: f32, ) -> (f32, f32, f32)

Resolve font-size, letter-spacing, and line-height together in one call, honouring CSS’s two different em bases (see the module note above font_size_px_ctx): font-size’s own em resolves against ctx.font_size (conventionally the parent’s font-size), while letter-spacing’s and line-height’s em resolve against the just-computed own font-size, not ctx.font_size again. Returns (font_size_px, letter_spacing_px, line_height_px).

Source

pub fn opacity_or(&self, default: f32) -> f32

opacity with default 1.0.

Source

pub fn border_radius_px(&self) -> Option<f32>

border-radius resolved as a single uniform px value (drops per-corner).

Source

pub fn border_radius_px_or(&self, default: f32) -> f32

border-radius as px, defaulting to default.

Source

pub fn padding_px(&self) -> (f32, f32, f32, f32)

Resolved padding tuple (top, right, bottom, left) in px.

Source

pub fn margin_px(&self) -> (f32, f32, f32, f32)

Resolved margin tuple (top, right, bottom, left) in px.

Source

pub fn background_color_str(&self) -> Option<&str>

background as a hex/keyword string when set as a plain color.

Trait Implementations§

Source§

impl Clone for CssStyle

Source§

fn clone(&self) -> CssStyle

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CssStyle

Source§

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

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

impl Default for CssStyle

Source§

fn default() -> CssStyle

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

impl<'de> Deserialize<'de> for CssStyle

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl JsonSchema for CssStyle

Source§

fn schema_name() -> String

The name of the generated JSON Schema. Read more
Source§

fn schema_id() -> Cow<'static, str>

Returns a string that uniquely identifies the schema produced by this type. Read more
Source§

fn json_schema(generator: &mut SchemaGenerator) -> Schema

Generates a JSON Schema for this type. Read more
Source§

fn is_referenceable() -> bool

Whether JSON Schemas generated for this type should be re-used where possible using the $ref keyword. Read more
Source§

impl PartialEq for CssStyle

Source§

fn eq(&self, other: &CssStyle) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for CssStyle

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for CssStyle

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.