Crate egui

Chester Wyke September 05, 2024 Updated: April 15, 2025 #rust

Get window size

Source: https://github.com/emilk/egui/discussions/2015

ctx.input(|i| {
    if let Some(rect) = i.viewport().outer_rect {
        dbg!(rect.size());
    }
});

Prevent a UI from shrinking if the contents get smaller

Source: https://github.com/emilk/egui/discussions/465

The example below checks for changes in hight but width should be similar. Without the if statement it causes the widget to grow if the contents get bigger.

if ui.available_height() > 0.0 {
    ui.allocate_space(ui.available_size());
}