Skip to content

Add const builder methods to bevy_ui #5529

@alice-i-cecile

Description

@alice-i-cecile

What problem does this solve or what need does it fill?

Constants are useful when manually defining UIs to get compile-time guarantees that your style / layout won't unexpectedly change at runtime.

However, many of the existing builder methods are not const, when they could be.

What solution would you like?

  1. Look through bevy_ui, and make any methods that you can const. This is particularly important for methods that return a new struct of the type that the impl block is for (a "builder method").
  2. Ensure that all of the essential structs have a const equivalent to Default::default(). This should be a DEFAULT associated constant. Use these new constants in the default trait implementations where feasible.

What alternative(s) have you considered?

Use a const fn new(). This is less clear, doesn't display the actual value in docs, and may have indirection overhead (IIRC this varies based on the optimization level). These are simple values, they should be represented as such.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-UIGraphical user interfaces, styles, layouts, and widgetsC-UsabilityA targeted quality-of-life change that makes Bevy easier to useD-TrivialNice and easy! A great choice to get started with Bevy

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions