pub struct StyleComponent {Show 35 fields
pub display: Option<Display>,
pub width: SizeDimension,
pub height: SizeDimension,
pub min_width: Option<f32>,
pub max_width: Option<f32>,
pub min_height: Option<f32>,
pub max_height: Option<f32>,
pub margin: EdgeInsets,
pub padding: EdgeInsets,
pub box_sizing: BoxSizing,
pub flex_direction: FlexDirection,
pub justify_content: JustifyContent,
pub align_items: AlignItems,
pub flex_wrap: FlexWrap,
pub row_gap: f32,
pub column_gap: f32,
pub flex_grow: f32,
pub flex_shrink: f32,
pub flex_basis: SizeDimension,
pub position: Position,
pub top: Option<SizeDimension>,
pub right: Option<SizeDimension>,
pub bottom: Option<SizeDimension>,
pub left: Option<SizeDimension>,
pub line_height: f32,
pub font_size: SizeDimension,
pub text_align: TextAlign,
pub vertical_align: VerticalAlign,
pub overflow: Overflow,
pub z_index: Option<i32>,
pub background_color: Option<[f32; 4]>,
pub background_z: Option<f32>,
pub color: Option<[f32; 4]>,
pub word_wrap: Option<WordWrapMode>,
pub word_wrap_tokens: Option<Vec<String>>,
/* private fields */
}Expand description
All CSS layout properties for a node, in one struct.
This mirrors the browser’s “computed style” record — a single bundle per element rather
than dozens of separate ECS components. Paired with
HtmlElementComponent (semantic role)
and LayoutComponent at the subtree root.
All size values are in glyph units (1.0 = one monospace character cell).
Style resolution order for any property:
StyleComponentvalue (if not the type’sDefault)HtmlElementComponent.element_typeUA-default (e.g.Div→Display::Block)- Layout system built-in fallback
Fields§
§display: Option<Display>None = inherit from HtmlElementComponent UA default.
width: SizeDimension§height: SizeDimension§min_width: Option<f32>§max_width: Option<f32>§min_height: Option<f32>§max_height: Option<f32>§margin: EdgeInsets§padding: EdgeInsets§box_sizing: BoxSizingbox-sizing. Default: BoxSizing::BorderBox (cat-engine default).
flex_direction: FlexDirection§justify_content: JustifyContent§align_items: AlignItems§flex_wrap: FlexWrap§row_gap: f32§column_gap: f32§flex_grow: f32§flex_shrink: f32§flex_basis: SizeDimension§position: Position§top: Option<SizeDimension>§right: Option<SizeDimension>§bottom: Option<SizeDimension>§left: Option<SizeDimension>§line_height: f32Line height in glyph units. Default: 1.0.
font_size: SizeDimensionVisual glyph scale applied by descendant TextComponents.
Carries its unit: GlyphUnits(1.0) = one row of glyphs per glyph unit
(the layout system’s intrinsic measure); WorldUnits(0.08) = each row
of glyphs is 0.08 world units tall (the renderer’s glyph quad scale).
Layout resolves to world units via the nearest LayoutComponent.unit_scale
before stamping the value onto descendant TextComponents.
Auto falls back to the descendant’s authored font size.
text_align: TextAlignText alignment within the content box. Default: Auto (no positioning).
vertical_align: VerticalAlignVertical text alignment within the content box.
Auto preserves the legacy behavior: if text_align is set, text is
vertically centered; otherwise the authored translation is preserved.
overflow: Overflow§z_index: Option<i32>§background_color: Option<[f32; 4]>RGBA background color. When Some, LayoutSystem spawns and manages a
background quad (covering the padding box) as a child of this item’s TC.
When None, no background quad is created (or an existing one is removed).
background_z: Option<f32>Optional override for the __bg quad’s local Z in the item TC’s frame.
None (default) means layout derives the background Z from the item’s
resolved stacking layer: resolved_z - 0.5 * LAYER_DISTANCE. Some(z)
pins the background to an absolute local Z, overriding the half-step
rule. See docs/spec/layout-stacking-z-index.md.
color: Option<[f32; 4]>CSS color. Inherited by every descendant glyph via the renderable
ancestor color walk (RenderableSystem::inherited_color_for_renderable).
When Some, layout spawns/maintains a __text_color ColorComponent
as an immediate child of this item’s TC; when None, any existing
helper is removed. Nested styled TCs with their own color override
naturally because their helper sits closer to the glyph in the walk.
word_wrap: Option<WordWrapMode>None = don’t override the descendant TextComponent’s authored mode.
Some(_) = write through to the descendant TextComponent during layout.
Does not yet cascade through nested TC boundaries (v2).
word_wrap_tokens: Option<Vec<String>>Token strings the wrap algorithm may break after when word_wrap == BreakWord.
None = inherit the descendant TextComponent’s authored tokens.
Implementations§
Source§impl StyleComponent
impl StyleComponent
Sourcepub fn new() -> Self
pub fn new() -> Self
Examples found in repository?
3fn spawn_runtime_text(
4 universe: &mut engine::Universe,
5 owner: engine::ecs::ComponentId,
6 label: &str,
7) {
8 use engine::ecs::component::{
9 ColorComponent, EdgeInsets, SizeDimension, StyleComponent, TextComponent,
10 TransformComponent,
11 };
12
13 let root = universe
14 .world
15 .add_component_boxed_named(label, Box::new(TransformComponent::new()));
16 let style = universe.world.add_component_boxed_named(
17 format!("{label}_style"),
18 Box::new({
19 let mut style = StyleComponent::new();
20 style.margin = EdgeInsets::all(0.5);
21 style.padding = EdgeInsets::axes(0.75, 0.5);
22 style.width = SizeDimension::Auto;
23 style.background_color = Some([0.93, 0.88, 0.98, 1.0]);
24 style
25 }),
26 );
27 let text = universe
28 .world
29 .add_component_boxed_named(format!("{label}_text"), Box::new(TextComponent::new(label)));
30 let color = universe
31 .world
32 .add_component(ColorComponent::rgba(0.38, 0.14, 0.62, 1.0));
33
34 let _ = universe.world.add_child(root, style);
35 let _ = universe.world.add_child(root, text);
36 let _ = universe.world.add_child(text, color);
37
38 universe.attach(owner, root).expect("attach routed child");
39}More examples
5fn spawn_runtime_text(
6 universe: &mut engine::Universe,
7 owner: engine::ecs::ComponentId,
8 label: &str,
9) {
10 use engine::ecs::component::{
11 ColorComponent, EdgeInsets, SizeDimension, StyleComponent, TextComponent,
12 TransformComponent,
13 };
14
15 let root = universe.world.add_component_boxed_named(
16 label,
17 Box::new(TransformComponent::new().with_position(0.0, 0.0, 0.2)),
18 );
19 let style = universe.world.add_component_boxed_named(
20 format!("{label}_style"),
21 Box::new({
22 let mut style = StyleComponent::new();
23 style.margin = EdgeInsets::axes(0.25, 0.25);
24 style.padding = EdgeInsets::axes(0.5, 0.5);
25 style.height = SizeDimension::GlyphUnits(2.5);
26 style.width = SizeDimension::Auto;
27 style.background_color = Some([1.0, 0.80, 0.80, 1.0]);
28 style
29 }),
30 );
31 let text_root = universe.world.add_component_boxed_named(
32 format!("{label}_text_root"),
33 Box::new(TransformComponent::new().with_position(0.0, 0.0, 0.2)),
34 );
35 let text = universe
36 .world
37 .add_component_boxed_named(format!("{label}_text"), Box::new(TextComponent::new(label)));
38 let color = universe
39 .world
40 .add_component(ColorComponent::rgba(0.40, 0.05, 0.05, 1.0));
41
42 let _ = universe.world.add_child(root, style);
43 let _ = universe.world.add_child(root, text_root);
44 let _ = universe.world.add_child(text_root, text);
45 let _ = universe.world.add_child(text, color);
46
47 universe.attach(owner, root).expect("attach routed child");
48}Sourcepub fn apply_patch(&mut self, patch: StylePatch)
pub fn apply_patch(&mut self, patch: StylePatch)
Apply a StylePatch, updating only fields where the patch has Some(...).
Trait Implementations§
Source§impl Clone for StyleComponent
impl Clone for StyleComponent
Source§fn clone(&self) -> StyleComponent
fn clone(&self) -> StyleComponent
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Component for StyleComponent
impl Component for StyleComponent
Source§fn name(&self) -> &'static str
fn name(&self) -> &'static str
fn set_id(&mut self, id: ComponentId)
fn as_any(&self) -> &dyn Any
fn as_any_mut(&mut self) -> &mut dyn Any
Source§fn to_mms_ast(&self, _world: &World) -> ComponentExpression
fn to_mms_ast(&self, _world: &World) -> ComponentExpression
Source§fn init(&mut self, _emit: &mut dyn SignalEmitter, _component: ComponentId)
fn init(&mut self, _emit: &mut dyn SignalEmitter, _component: ComponentId)
Source§fn cleanup(&mut self, _emit: &mut dyn SignalEmitter, _component: ComponentId)
fn cleanup(&mut self, _emit: &mut dyn SignalEmitter, _component: ComponentId)
Source§impl Debug for StyleComponent
impl Debug for StyleComponent
Auto Trait Implementations§
impl Freeze for StyleComponent
impl RefUnwindSafe for StyleComponent
impl Send for StyleComponent
impl Sync for StyleComponent
impl Unpin for StyleComponent
impl UnsafeUnpin for StyleComponent
impl UnwindSafe for StyleComponent
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.