emilk / emilk/egui

Viewport decoration offsets the registered mouse position

Open
#7,108 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Rust
Stars
30.6k
Forks
2.1k
Avg merge
1d 9h
Merged PRs (30d)
72

Description

**Describe the bug**
When hiding the viewport's decorations the mouse input seems to be offset from the actual mouse position. There are also these black bars instead of the decorations (that can be fixed by setting the viewport as transparent).

**To Reproduce**
Here is a minimal example for that bug:
This is my main.rs
```rust
use eframe::egui;

fn main() -> eframe::Result {
let options = eframe::NativeOptions {
viewport: egui::ViewportBuilder::default().with_inner_size([320.0, 240.0]).with_decorations(false),
..Default::default()
};
eframe::run_native(
"My egui App",
options,
Box::new(|_cc| {
Ok(Box::::default())
}),
)
}

#[derive(Default)]
struct MyApp {
}

impl eframe::App for MyApp {
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
egui::CentralPanel::default().show(ctx, |ui| {
if ui.button("Press me").clicked() {
println!("Button pressed.");
}
});
}
}
```
and my cargo.toml
```toml
[package]
name = "egui-decoration-test"
version = "0.1.0"
edition = "2021"

[dependencies]
egui = { git = "https://github.com/emilk/egui", branch = "main" }
# if you're using eframe:
eframe = { git = "https://github.com/emilk/egui", branch = "main" }
```
When you run the app, in order to press the button you will have to hover slightly above it as the mouse input is offset
**Expected behavior**
When moving the mouse over the button the button should appear hovered but I have to move the mouse slightly above it so egui "thinks" it's above the button

**Screenshots**

https://github.com/user-attachments/assets/9b1de91b-7668-4fd9-a63c-e9482d21f2ca

**Desktop:**
- OS: windows 10
I tried both the latest egui version in from crate.io and the github repository

Contributor guide

Open the contributing guide

Research direction

Start by running the minimal main.rs example on Windows 10 and verify the decoration-disabled viewport behavior. Trace the eframe::run_native viewport path related to with_decorations(false); done means mouse hover coordinates align with the displayed controls and the unwanted black bars are gone.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
desktop
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.