Adapt raw_window_handle 0.4 for nih_plug_egui
NIH-plug switched to version 0.5, so this adapter is needed for this version of nih_plug_egui.
This commit is contained in:
parent
b794cdeafe
commit
a16cbd6aad
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -2919,6 +2919,7 @@ dependencies = [
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"nih_plug",
|
"nih_plug",
|
||||||
"parking_lot 0.12.1",
|
"parking_lot 0.12.1",
|
||||||
|
"raw-window-handle 0.4.3",
|
||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,10 @@ opengl = []
|
||||||
[dependencies]
|
[dependencies]
|
||||||
nih_plug = { path = ".." }
|
nih_plug = { path = ".." }
|
||||||
|
|
||||||
|
# The currently targeted version of baseview uses a different version of
|
||||||
|
# `raw_window_handle` than NIH-plug, so we need to manually convert between them
|
||||||
|
raw-window-handle = "0.4"
|
||||||
|
|
||||||
baseview = { git = "https://github.com/RustAudio/baseview.git", rev = "1d9806d5bd92275d0d8142d9c9c90198757b9b25" }
|
baseview = { git = "https://github.com/RustAudio/baseview.git", rev = "1d9806d5bd92275d0d8142d9c9c90198757b9b25" }
|
||||||
crossbeam = "0.8"
|
crossbeam = "0.8"
|
||||||
# The `egui-default-features` feature enables the default features. This makes
|
# The `egui-default-features` feature enables the default features. This makes
|
||||||
|
|
|
@ -7,6 +7,7 @@ use egui::Context;
|
||||||
use egui_baseview::EguiWindow;
|
use egui_baseview::EguiWindow;
|
||||||
use nih_plug::prelude::{Editor, GuiContext, ParamSetter, ParentWindowHandle};
|
use nih_plug::prelude::{Editor, GuiContext, ParamSetter, ParentWindowHandle};
|
||||||
use parking_lot::RwLock;
|
use parking_lot::RwLock;
|
||||||
|
use raw_window_handle::{HasRawWindowHandle, RawWindowHandle};
|
||||||
use std::sync::atomic::Ordering;
|
use std::sync::atomic::Ordering;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
@ -28,6 +29,32 @@ pub(crate) struct EguiEditor<T> {
|
||||||
pub(crate) scaling_factor: AtomicCell<Option<f32>>,
|
pub(crate) scaling_factor: AtomicCell<Option<f32>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// This version of `baseview` uses a different version of `raw_window_handle than NIH-plug, so we
|
||||||
|
/// need to adapt it ourselves.
|
||||||
|
struct ParentWindowHandleAdapter(nih_plug::editor::ParentWindowHandle);
|
||||||
|
|
||||||
|
unsafe impl HasRawWindowHandle for ParentWindowHandleAdapter {
|
||||||
|
fn raw_window_handle(&self) -> RawWindowHandle {
|
||||||
|
match self.0 {
|
||||||
|
ParentWindowHandle::X11Window(window) => {
|
||||||
|
let mut handle = raw_window_handle::XcbHandle::empty();
|
||||||
|
handle.window = window;
|
||||||
|
RawWindowHandle::Xcb(handle)
|
||||||
|
}
|
||||||
|
ParentWindowHandle::AppKitNsView(ns_view) => {
|
||||||
|
let mut handle = raw_window_handle::AppKitHandle::empty();
|
||||||
|
handle.ns_view = ns_view;
|
||||||
|
RawWindowHandle::AppKit(handle)
|
||||||
|
}
|
||||||
|
ParentWindowHandle::Win32Hwnd(hwnd) => {
|
||||||
|
let mut handle = raw_window_handle::Win32Handle::empty();
|
||||||
|
handle.hwnd = hwnd;
|
||||||
|
RawWindowHandle::Win32(handle)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<T> Editor for EguiEditor<T>
|
impl<T> Editor for EguiEditor<T>
|
||||||
where
|
where
|
||||||
T: 'static + Send + Sync,
|
T: 'static + Send + Sync,
|
||||||
|
@ -44,7 +71,7 @@ where
|
||||||
let (unscaled_width, unscaled_height) = self.egui_state.size();
|
let (unscaled_width, unscaled_height) = self.egui_state.size();
|
||||||
let scaling_factor = self.scaling_factor.load();
|
let scaling_factor = self.scaling_factor.load();
|
||||||
let window = EguiWindow::open_parented(
|
let window = EguiWindow::open_parented(
|
||||||
&parent,
|
&ParentWindowHandleAdapter(parent),
|
||||||
WindowOpenOptions {
|
WindowOpenOptions {
|
||||||
title: String::from("egui window"),
|
title: String::from("egui window"),
|
||||||
// Baseview should be doing the DPI scaling for us
|
// Baseview should be doing the DPI scaling for us
|
||||||
|
|
Loading…
Reference in a new issue