made drag and drop support selectable on Windows for the eframe glium integration (#324)

* made drag and drop support selectable on windows

to avoid issues with crates that use multi-threaded COM apis

* fixed formatting and clippy issues
This commit is contained in:
Joel Nises 2021-04-19 22:49:28 +02:00 committed by GitHub
parent 23d292a974
commit 72d0d71d66
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 0 deletions

View file

@ -1,5 +1,7 @@
use crate::{window_settings::WindowSettings, *};
use egui::Color32;
#[cfg(target_os = "windows")]
use glium::glutin::platform::windows::WindowBuilderExtWindows;
use std::time::Instant;
#[cfg(feature = "persistence")]
@ -55,6 +57,23 @@ impl epi::RepaintSignal for GliumRepaintSignal {
}
}
#[cfg(target_os = "windows")]
fn window_builder_drag_and_drop(
window_builder: glutin::window::WindowBuilder,
enable: bool,
) -> glutin::window::WindowBuilder {
window_builder.with_drag_and_drop(enable)
}
#[cfg(not(target_os = "windows"))]
fn window_builder_drag_and_drop(
window_builder: glutin::window::WindowBuilder,
_enable: bool,
) -> glutin::window::WindowBuilder {
// drag and drop can only be disabled on windows
window_builder
}
fn create_display(
app: &dyn epi::App,
window_settings: Option<WindowSettings>,
@ -68,6 +87,8 @@ fn create_display(
.with_window_icon(window_icon)
.with_transparent(app.transparent());
window_builder = window_builder_drag_and_drop(window_builder, app.drag_and_drop_support());
let initial_size_points = app.initial_window_size();
if let Some(window_settings) = &window_settings {

View file

@ -155,6 +155,12 @@ pub trait App {
fn transparent(&self) -> bool {
false
}
/// On Windows: enable drag and drop support.
/// Set to false to avoid issues with crates such as cpal which uses that use multi-threaded COM API <https://github.com/rust-windowing/winit/pull/1524>
fn drag_and_drop_support(&self) -> bool {
true
}
}
/// Image data for the icon.