SecondHalfGames / yakui

yakui is a declarative Rust UI library for games
Apache License 2.0
222 stars 18 forks source link

Add pivot to reflow #144

Closed Uriopass closed 3 months ago

Uriopass commented 5 months ago

This allows reflowing while taking into account the child size. I personally need this to be able to show a tooltip over a button (when hovered for a bit) that is nicely centered.

I introduced a new "Pivot" type to avoid accidentally swapping the anchor and the pivot arguments in the reflow shorthand.

Another idea: This could be implemented as a separate Pivot widget with the same offset logic. Could also be added to the Offset widget which would now also take relative (pivot) coordinates. (Could be worth simplifying Flow::Relative removing offset since the Offset widget can already do this?)

Some screenshots:

Backward compat: Pivot is TOP_LEFT. Screenshot from 2024-02-07 16-34-21

Pivot is 'CENTER': Screenshot from 2024-02-07 16-51-56

Pivot is equal to anchor: Screenshot from 2024-02-07 16-51-11