Skip to content
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

Add Ui::is_sizing_pass for better size estimation of Areas, and menus in particular #4557

Merged
merged 14 commits into from
May 29, 2024

Conversation

emilk
Copy link
Owner

@emilk emilk commented May 28, 2024

This adds a special sizing_pass mode to Ui, in which we have no centered or justified layouts, and everything is hidden. This is used by Area to use the first frame to measure the size of its contents so that it can then set the perfectly correct size the subsequent frames.

For menus, where buttons are justified (span the full width), this finally the problem of auto-sizing. Before you would have to pick a width manually, and all buttons would expand to that width. If it was too wide, it looked weird. If it was too narrow, text would wrap. Now all menus are exactly the width they need to be. By default menus will wrap at Spacing::menu_width.

This affects all situations when you have something that should be as small as possible, but still span the full width/height of the parent. For instance: the egui::Separator widget now checks the ui.is_sizing_pass flag before deciding on a size. In the sizing pass a horizontal separator is always 0 wide, and only in subsequent passes will it span the full width.

@emilk emilk added the egui label May 28, 2024
@emilk emilk force-pushed the emilk/sizing-pass-flag branch 2 times, most recently from 9385170 to a1d3c66 Compare May 28, 2024 12:20
@emilk emilk marked this pull request as draft May 28, 2024 12:22
@emilk emilk marked this pull request as ready for review May 29, 2024 07:04
@emilk emilk changed the title Better sizing pass for Areas, and menus in particular Add Ui::is_sizing_pass for better size estimation of Areas, and menus in particular May 29, 2024
@emilk emilk merged commit a768d74 into master May 29, 2024
35 checks passed
@emilk emilk deleted the emilk/sizing-pass-flag branch May 29, 2024 08:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

egui menus: remember size from previous frame
1 participant