Struct bevy::ui::Style

pub struct Style {
Show 22 fields pub display: Display, pub position_type: PositionType, pub direction: Direction, pub flex_direction: FlexDirection, pub flex_wrap: FlexWrap, pub align_items: AlignItems, pub align_self: AlignSelf, pub align_content: AlignContent, pub justify_content: JustifyContent, pub position: UiRect, pub margin: UiRect, pub padding: UiRect, pub border: UiRect, pub flex_grow: f32, pub flex_shrink: f32, pub flex_basis: Val, pub size: Size, pub min_size: Size, pub max_size: Size, pub aspect_ratio: Option<f32>, pub overflow: Overflow, pub gap: Size,
}
Expand description

Describes the style of a UI node

It uses the Flexbox system.

Fields§

§display: Display

Whether to arrange this node and its children with flexbox layout

If this is set to Display::None, this node will be collapsed.

§position_type: PositionType

Whether to arrange this node relative to other nodes, or positioned absolutely

§direction: Direction

Which direction the content of this node should go

§flex_direction: FlexDirection

Whether to use column or row layout

§flex_wrap: FlexWrap

How to wrap nodes

§align_items: AlignItems

How items are aligned according to the cross axis

§align_self: AlignSelf

How this item is aligned according to the cross axis. Overrides AlignItems.

§align_content: AlignContent

How to align each line, only applies if flex_wrap is set to FlexWrap::Wrap and there are multiple lines of items

§justify_content: JustifyContent

How items align according to the main axis

§position: UiRect

The position of the node as described by its Rect

§margin: UiRect

The amount of space around a node outside its border.

If a percentage value is used, the percentage is calculated based on the width of the parent node.

Example

let style = Style {
    margin: UiRect {
        left: Val::Percent(10.),
        right: Val::Percent(10.),
        top: Val::Percent(15.),
        bottom: Val::Percent(15.)
    },
    ..Default::default()
};

A node with this style and a parent with dimensions of 100px by 300px, will have calculated margins of 10px on both left and right edges, and 15px on both top and bottom egdes.

§padding: UiRect

The amount of space between the edges of a node and its contents.

If a percentage value is used, the percentage is calculated based on the width of the parent node.

Example

let style = Style {
    padding: UiRect {
        left: Val::Percent(1.),
        right: Val::Percent(2.),
        top: Val::Percent(3.),
        bottom: Val::Percent(4.)
    },
    ..Default::default()
};

A node with this style and a parent with dimensions of 300px by 100px, will have calculated padding of 3px on the left, 6px on the right, 9px on the top and 12px on the bottom.

§border: UiRect

The amount of space between the margins of a node and its padding.

If a percentage value is used, the percentage is calculated based on the width of the parent node.

The size of the node will be expanded if there are constraints that prevent the layout algorithm from placing the border within the existing node boundary.

Rendering for borders is not yet implemented.

§flex_grow: f32

Defines how much a flexbox item should grow if there’s space available

§flex_shrink: f32

How to shrink if there’s not enough space available

§flex_basis: Val

The initial length of the main axis, before other properties are applied.

If both are set, flex_basis overrides size on the main axis but it obeys the bounds defined by min_size and max_size.

§size: Size

The ideal size of the flexbox

size.width is used when it is within the bounds defined by min_size.width and max_size.width. size.height is used when it is within the bounds defined by min_size.height and max_size.height.

§min_size: Size

The minimum size of the flexbox

min_size.width is used if it is greater than either size.width or max_size.width, or both. min_size.height is used if it is greater than either size.height or max_size.height, or both.

§max_size: Size

The maximum size of the flexbox

max_size.width is used if it is within the bounds defined by min_size.width and size.width. max_size.height is used if it is within the bounds defined by min_size.height and `size.height.

§aspect_ratio: Option<f32>

The aspect ratio of the flexbox

§overflow: Overflow

How to handle overflow

§gap: Size

The size of the gutters between the rows and columns of the flexbox layout

Values of Size::UNDEFINED and Size::AUTO are treated as zero.

Implementations§

§

impl Style

pub const DEFAULT: Style = Self{ display: Display::DEFAULT, position_type: PositionType::DEFAULT, direction: Direction::DEFAULT, flex_direction: FlexDirection::DEFAULT, flex_wrap: FlexWrap::DEFAULT, align_items: AlignItems::DEFAULT, align_self: AlignSelf::DEFAULT, align_content: AlignContent::DEFAULT, justify_content: JustifyContent::DEFAULT, position: UiRect::DEFAULT, margin: UiRect::DEFAULT, padding: UiRect::DEFAULT, border: UiRect::DEFAULT, flex_grow: 0.0, flex_shrink: 1.0, flex_basis: Val::Auto, size: Size::AUTO, min_size: Size::AUTO, max_size: Size::AUTO, aspect_ratio: None, overflow: Overflow::DEFAULT, gap: Size::UNDEFINED,}

Trait Implementations§

§

impl Clone for Style

§

fn clone(&self) -> Style

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
§

impl Component for Stylewhere Style: Send + Sync + 'static,

§

impl Debug for Style

§

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

Formats the value using the given formatter. Read more
§

impl Default for Style

§

fn default() -> Style

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

impl GetTypeRegistration for Stylewhere Display: Reflect, PositionType: Reflect, Direction: Reflect, FlexDirection: Reflect, FlexWrap: Reflect, AlignItems: Reflect, AlignSelf: Reflect, AlignContent: Reflect, JustifyContent: Reflect, UiRect: Reflect, f32: Reflect, Val: Reflect, Size: Reflect, Option<f32>: Reflect, Overflow: Reflect,

§

impl PartialEq<Style> for Style

§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl Reflect for Stylewhere Display: Reflect, PositionType: Reflect, Direction: Reflect, FlexDirection: Reflect, FlexWrap: Reflect, AlignItems: Reflect, AlignSelf: Reflect, AlignContent: Reflect, JustifyContent: Reflect, UiRect: Reflect, f32: Reflect, Val: Reflect, Size: Reflect, Option<f32>: Reflect, Overflow: Reflect,

§

fn type_name(&self) -> &str

Returns the type name of the underlying type.
§

fn get_type_info(&self) -> &'static TypeInfo

Returns the TypeInfo of the underlying type. Read more
§

fn into_any(self: Box<Style, Global>) -> Box<dyn Any + 'static, Global>

Returns the value as a Box<dyn Any>.
§

fn as_any(&self) -> &(dyn Any + 'static)

Returns the value as a &dyn Any.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Returns the value as a &mut dyn Any.
§

fn into_reflect(self: Box<Style, Global>) -> Box<dyn Reflect + 'static, Global>

Casts this type to a boxed reflected value.
§

fn as_reflect(&self) -> &(dyn Reflect + 'static)

Casts this type to a reflected value.
§

fn as_reflect_mut(&mut self) -> &mut (dyn Reflect + 'static)

Casts this type to a mutable reflected value.
§

fn clone_value(&self) -> Box<dyn Reflect + 'static, Global>

Clones the value as a Reflect trait object. Read more
§

fn set( &mut self, value: Box<dyn Reflect + 'static, Global> ) -> Result<(), Box<dyn Reflect + 'static, Global>>

Performs a type-checked assignment of a reflected value to this value. Read more
§

fn apply(&mut self, value: &(dyn Reflect + 'static))

Applies a reflected value to this value. Read more
§

fn reflect_ref(&self) -> ReflectRef<'_>

Returns an enumeration of “kinds” of type. Read more
§

fn reflect_mut(&mut self) -> ReflectMut<'_>

Returns a mutable enumeration of “kinds” of type. Read more
§

fn reflect_owned(self: Box<Style, Global>) -> ReflectOwned

Returns an owned enumeration of “kinds” of type. Read more
§

fn reflect_partial_eq(&self, value: &(dyn Reflect + 'static)) -> Option<bool>

Returns a “partial equality” comparison result. Read more
§

fn reflect_hash(&self) -> Option<u64>

Returns a hash of the value (which includes the type). Read more
§

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

Debug formatter for the value. Read more
§

fn serializable(&self) -> Option<Serializable<'_>>

Returns a serializable version of the value. Read more
§

impl Struct for Stylewhere Display: Reflect, PositionType: Reflect, Direction: Reflect, FlexDirection: Reflect, FlexWrap: Reflect, AlignItems: Reflect, AlignSelf: Reflect, AlignContent: Reflect, JustifyContent: Reflect, UiRect: Reflect, f32: Reflect, Val: Reflect, Size: Reflect, Option<f32>: Reflect, Overflow: Reflect,

§

fn field(&self, name: &str) -> Option<&(dyn Reflect + 'static)>

Returns a reference to the value of the field named name as a &dyn Reflect.
§

fn field_mut(&mut self, name: &str) -> Option<&mut (dyn Reflect + 'static)>

Returns a mutable reference to the value of the field named name as a &mut dyn Reflect.
§

fn field_at(&self, index: usize) -> Option<&(dyn Reflect + 'static)>

Returns a reference to the value of the field with index index as a &dyn Reflect.
§

fn field_at_mut(&mut self, index: usize) -> Option<&mut (dyn Reflect + 'static)>

Returns a mutable reference to the value of the field with index index as a &mut dyn Reflect.
§

fn name_at(&self, index: usize) -> Option<&str>

Returns the name of the field with index index.
§

fn field_len(&self) -> usize

Returns the number of fields in the struct.
§

fn iter_fields(&self) -> FieldIter<'_>

Returns an iterator over the values of the reflectable fields for this struct.
§

fn clone_dynamic(&self) -> DynamicStruct

Clones the struct into a DynamicStruct.
§

impl Typed for Stylewhere Display: Reflect, PositionType: Reflect, Direction: Reflect, FlexDirection: Reflect, FlexWrap: Reflect, AlignItems: Reflect, AlignSelf: Reflect, AlignContent: Reflect, JustifyContent: Reflect, UiRect: Reflect, f32: Reflect, Val: Reflect, Size: Reflect, Option<f32>: Reflect, Overflow: Reflect,

§

fn type_info() -> &'static TypeInfo

Returns the compile-time info for the underlying type.
§

impl StructuralPartialEq for Style

Auto Trait Implementations§

§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T, U> AsBindGroupShaderType<U> for Twhere U: ShaderType, &'a T: for<'a> Into<U>,

§

fn as_bind_group_shader_type(&self, _images: &RenderAssets<Image>) -> U

Return the T ShaderType for self. When used in AsBindGroup derives, it is safe to assume that all images in self exist.
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
§

impl<C> Bundle for Cwhere C: Component,

§

fn component_ids( components: &mut Components, storages: &mut Storages, ids: &mut impl FnMut(ComponentId) )

§

unsafe fn from_components<T, F>(ctx: &mut T, func: &mut F) -> Cwhere F: for<'a> FnMut(&'a mut T) -> OwningPtr<'a, Aligned>,

§

fn get_components( self, func: &mut impl FnMut(StorageType, OwningPtr<'_, Aligned>) )

§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

§

impl<T> Downcast for Twhere T: Any,

§

fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>

Convert 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.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for Twhere T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send + 'static>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<S> FromSample<S> for S

§

fn from_sample_(s: S) -> S

§

impl<T> FromWorld for Twhere T: Default,

§

fn from_world(_world: &mut World) -> T

Creates Self using data from the given World
§

impl<S> GetField for Swhere S: Struct,

§

fn get_field<T>(&self, name: &str) -> Option<&T>where T: Reflect,

Returns a reference to the value of the field named name, downcast to T.
§

fn get_field_mut<T>(&mut self, name: &str) -> Option<&mut T>where T: Reflect,

Returns a mutable reference to the value of the field named name, downcast to T.
§

impl<T> GetPath for Twhere T: Reflect,

§

fn reflect_path<'r, 'p>( &'r self, path: &'p str ) -> Result<&'r (dyn Reflect + 'static), ReflectPathError<'p>>

Returns a reference to the value specified by path. Read more
§

fn reflect_path_mut<'r, 'p>( &'r mut self, path: &'p str ) -> Result<&'r mut (dyn Reflect + 'static), ReflectPathError<'p>>

Returns a mutable reference to the value specified by path. Read more
§

fn path<T, 'r, 'p>( &'r self, path: &'p str ) -> Result<&'r T, ReflectPathError<'p>>where T: Reflect,

Returns a statically typed reference to the value specified by path. Read more
§

fn path_mut<T, 'r, 'p>( &'r mut self, path: &'p str ) -> Result<&'r mut T, ReflectPathError<'p>>where T: Reflect,

Returns a statically typed mutable reference to the value specified by path. Read more
source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

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

const: unstable · 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> ToOwned for Twhere T: Clone,

§

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
§

impl<T, U> ToSample<U> for Twhere U: FromSample<T>,

§

fn to_sample_(self) -> U

source§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
§

impl<T> TypeData for Twhere T: 'static + Send + Sync + Clone,

§

fn clone_type_data(&self) -> Box<dyn TypeData + 'static, Global>

§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
§

impl<S, T> Duplex<S> for Twhere T: FromSample<S> + ToSample<S>,

§

impl<T> Event for Twhere T: Send + Sync + 'static,