Inline Styling
Inline properties refers to style and layout properties which are set on a per widget basis.
Setting styles on entities
Style properties can be set on any widget by calling a property setter on its id. For example, to set the background color of a widget:
entity.set_background_color(state, Color::blue());
where entity
is the Entity
id of the widget and state
is a mutable reference to State
. Property setters are available on the entity id thanks to the PropSet
trait, which exposes setters for all of the style and layout properties.
Setting styles during widget building
It is also possible to set the style properties of a widget when the widget is built using the builder
argument of the supplied closure to the build
method. For example, when building a Button
instance we can set its background color like so:
let button = Button::new().build(state, parent, |builder|
builder
.set_background_color(Color::blue())
);
The name of the setter is identical to the one used on an entity id, except now a mutable reference to State
is not required because there is one internal to the builder.
Note that the widget being acted upon when setting properties on the builder may not be the same widget as the one referred to by the returned entity id.