emilk / egui

egui: an easy-to-use immediate mode GUI in Rust that runs on both web and native
https://www.egui.rs/
Apache License 2.0
22.44k stars 1.6k forks source link

InputState.screen_rect on Windows does not have position #5215

Open barries opened 1 month ago

barries commented 1 month ago

Describe the bug According to the docs: InputState.screen_rect: Position and size of the egui area.

However, this code:

fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
    let ui_size = ctx.input(|i: &egui::InputState| i.screen_rect());

    info!("ui_size: {ui_size:?}");

...always reports an origin of [0.0 0.0] when dragging the window:

[2024-10-02T19:10:45Z INFO  iotasoft_ui::app] ui_size: [[0.0 0.0] - [1024.0 768.0]]
...
[2024-10-02T19:10:48Z INFO  iotasoft_ui::app] ui_size: [[0.0 0.0] - [1024.0 768.0]]
...
[2024-10-02T19:10:49Z INFO  iotasoft_ui::app] ui_size: [[0.0 0.0] - [1024.0 768.0]]

To Reproduce Steps to reproduce the behavior:

  1. Add the above code to an eframe_template
  2. Run
  3. Drag window
  4. Observe log

Expected behavior The reported origin is the actual origin, and changes when the window is moved, maximized, full-screened, restored, minimized, etc.

Screenshots

Desktop (please complete the following information):

Smartphone (please complete the following information):

Additional context

rustbasic commented 1 month ago

Please see below.

                let outer_rect = ui
                    .ctx()
                    .input(|i| i.viewport().outer_rect.unwrap_or(egui::Rect::ZERO));
                let inner_rect = ui
                    .ctx()
                    .input(|i| i.viewport().inner_rect.unwrap_or(egui::Rect::ZERO));
barries commented 1 month ago

Thanks for the workarounds!

This is still a discrepancy between the docs and implementation.