bevy icon indicating copy to clipboard operation
bevy copied to clipboard

Add additional constructors for `UiRect` to specify values for specific fields

Open Piturnah opened this issue 3 years ago • 0 comments

Objective

Often one wants to create a UiRect with a value only specifying a single field. These ways are already available, but not the most ergonomic:

UiRect::new(Val::Undefined, Val::Undefined, Val::Percent(25.0), Val::Undefined)
UiRect {
    top: Val::Percent(25.0),
    ..default()
}

Solution

Introduce 6 new constructors:

  • horizontal
  • vertical
  • left
  • right
  • top
  • bottom

So the above code can be written instead as:

UiRect::top(Val::Percent(25.0))

This solution is similar to the style fields margin-left, padding-top, etc. that you would see in CSS, from which bevy's UI has other inspiration. Therefore, it should still feel intuitive to users coming from CSS.


Changelog

Added

  • Additional constructors for UiRect to specify values for specific fields

Piturnah avatar Sep 14 '22 18:09 Piturnah