emilk / emilk/egui

Calculating a UI's size without rendering it

Open
#606 10 comments 1 reaction 0 assignees View on GitHub
design layout
Dominant language
Rust
Stars
30.6k
Forks
2.1k
Avg merge
1d 9h
Merged PRs (30d)
72

Description

It would be cool if we were able to get a widgets size before actually rendering it. I know this is a fundamental limitation of immediate mode UIs, but it should be easily possible to do this, right? Basically we just make all of the calls except the ones that take any effect on the screen.

My situation is that I have a row of items with different sizes, and I want the entire row to have the same height. When I add the tallest item first, this works, because then the later elements know their height. But when the tallest element is not the first, then the first item will not know how tall it should be. So I would like to iterate through all elements before rendering them, to calculate their sizes and find the max height, then set use that height for all elements when rendering them.

![Screenshot_2021-08-04_00-41-16](https://user-images.githubusercontent.com/20745737/128095586-b06b1144-c2f0-4fb4-be14-2e3006088ac1.png)

The idea is basically to render to an offscreen buffer, just to get the final size of the `Ui`, without actually rendering anything. If there is some way to know if the `Ui` changed it would also be possible to cache something here, but I doubt that this will be possible without compromising developer experience.

Contributor guide

Open the contributing guide

Research direction

The issue provides no files, tests, or entry points; begin by reviewing egui's layout and rendering paths against the proposed offscreen sizing approach. Done would require an agreed design and a demonstrated way to determine a row's maximum height before visible rendering, validated with the order-dependent example.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
frontend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.