-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom MeasureFunc
#7730
Custom MeasureFunc
#7730
Conversation
* Added a new trait `MeasureNode`. * Added new structs `ImageMeasure` and `BasicMeasure` that implement `MeasureNode`. * Add a field to `CalculatedSize` called `measure` that takes a boxed `MeasureNode`. * `upsert_leaf` uses the `measure` of `CalculatedSize` to create a `MeasureFunc` for the node.
This PR is the wrong approach, the whole |
@ickshonpe What are the underlying problems? |
The major problem with this PR is that it clones and double-boxes the There are a lot of internal performance bugs that are hard to find because they only have an impact when the UI updates and not every frame. I just published #8402 which fixes another unnecessary update bug. |
@ickshonpe Would it be helpful if
|
Objective
At the moment Bevy UI has a very basic, unmodifiable
MeasureFunc
.Problems:
Text wrapping can't be implemented correctly as the
MeasureFunc
needs access to the font and text data to choose the correct size for the node.Images are difficult to work with. With more complicated layouts users have to set fixed size constraints using
min_size
andmax_size
to get the correct dimensions, which isn't acceptable.Users can't implement widgets that need to control their own size.
There are bugs that are hard to find and replicate without modifying the
MeasureFunc
definite measure func #8111, MeasureFunc Text aspect ratio bug #6748, and MeasureFunc given incorrect AvailableSpace DioxusLabs/taffy#406 are examples.
Solution
Create a new trait
MeasureNode
and add aBox<dyn MeasureNode>
field toCalculatedSize
.Have
upsert_leaf
use the boxedMeasureNode
to create theMeasureFunc
for the node.Changelog
MeasureNode
.ImageMeasure
andBasicMeasure
that implementMeasureNode
.CalculatedSize
calledmeasure
that takes a boxedMeasureNode
.upsert_leaf
uses themeasure
ofCalculatedSize
to create aMeasureFunc
for the node.