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

Bugfix/drag window #1108

Merged
merged 6 commits into from
Jan 26, 2022
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions egui-winit/src/epi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ pub struct EpiIntegration {
pub app: Box<dyn epi::App>,
/// When set, it is time to quit
quit: bool,
can_drag_window: bool,
}

impl EpiIntegration {
Expand Down Expand Up @@ -229,6 +230,7 @@ impl EpiIntegration {
egui_winit: crate::State::new(window),
app,
quit: false,
can_drag_window: false,
};

slf.setup(window);
Expand Down Expand Up @@ -264,8 +266,18 @@ impl EpiIntegration {
}

pub fn on_event(&mut self, event: &winit::event::WindowEvent<'_>) {
use winit::event::WindowEvent;
use winit::event::{ElementState, MouseButton, WindowEvent};
self.quit |= matches!(event, WindowEvent::CloseRequested | WindowEvent::Destroyed);

if let WindowEvent::MouseInput {
button: MouseButton::Left,
state: ElementState::Pressed,
..
} = event
{
self.can_drag_window = true;
}

self.egui_winit.on_event(&self.egui_ctx, event);
}

Expand All @@ -289,7 +301,10 @@ impl EpiIntegration {
self.egui_winit
.handle_output(window, &self.egui_ctx, egui_output);

let app_output = self.frame.take_app_output();
let mut app_output = self.frame.take_app_output();
app_output.drag_window &= self.can_drag_window;
emilk marked this conversation as resolved.
Show resolved Hide resolved
self.can_drag_window = false;

self.quit |= app_output.quit;
let tex_allocation_data =
crate::epi::handle_app_output(window, self.egui_ctx.pixels_per_point(), app_output);
Expand Down