-
-
Notifications
You must be signed in to change notification settings - Fork 161
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
[WIP] update to the latest iced_baseview (iced 0.10) #112
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,4 +14,4 @@ quote = "1.0" | |
proc-macro2 = "1.0" | ||
|
||
[dev-dependencies] | ||
nih_plug = { path = ".." } | ||
nih_plug = { path = "..", default-features = false } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. otherwise it's impossible to opt out of default features in a binary There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,38 @@ | ||
//! Binary assets for use with `nih_plug_iced`. | ||
use crate::Font; | ||
use std::borrow::Cow; | ||
|
||
use crate::core::Font; | ||
|
||
use iced_baseview::runtime::{font, Command}; | ||
// This module provides a re-export and simple font wrappers around the re-exported fonts. | ||
pub use nih_plug_assets::*; | ||
|
||
pub const NOTO_SANS_REGULAR: Font = Font::External { | ||
name: "Noto Sans Regular", | ||
bytes: fonts::NOTO_SANS_REGULAR, | ||
}; | ||
|
||
pub const NOTO_SANS_REGULAR_ITALIC: Font = Font::External { | ||
name: "Noto Sans Regular Italic", | ||
bytes: fonts::NOTO_SANS_REGULAR_ITALIC, | ||
}; | ||
|
||
pub const NOTO_SANS_THIN: Font = Font::External { | ||
name: "Noto Sans Thin", | ||
bytes: fonts::NOTO_SANS_THIN, | ||
}; | ||
|
||
pub const NOTO_SANS_THIN_ITALIC: Font = Font::External { | ||
name: "Noto Sans Thin Italic", | ||
bytes: fonts::NOTO_SANS_THIN_ITALIC, | ||
}; | ||
|
||
pub const NOTO_SANS_LIGHT: Font = Font::External { | ||
name: "Noto Sans Light", | ||
bytes: fonts::NOTO_SANS_LIGHT, | ||
}; | ||
|
||
pub const NOTO_SANS_LIGHT_ITALIC: Font = Font::External { | ||
name: "Noto Sans Light Italic", | ||
bytes: fonts::NOTO_SANS_LIGHT_ITALIC, | ||
}; | ||
|
||
pub const NOTO_SANS_BOLD: Font = Font::External { | ||
name: "Noto Sans Bold", | ||
bytes: fonts::NOTO_SANS_BOLD, | ||
}; | ||
|
||
pub const NOTO_SANS_BOLD_ITALIC: Font = Font::External { | ||
name: "Noto Sans Bold Italic", | ||
bytes: fonts::NOTO_SANS_BOLD_ITALIC, | ||
}; | ||
pub const NOTO_SANS_REGULAR: Font = Font::with_name("Noto Sans Regular"); | ||
pub const NOTO_SANS_REGULAR_ITALIC: Font = Font::with_name("Noto Sans Regular Italic"); | ||
pub const NOTO_SANS_THIN: Font = Font::with_name("Noto Sans Thin"); | ||
pub const NOTO_SANS_THIN_ITALIC: Font = Font::with_name("Noto Sans Thin Italic"); | ||
pub const NOTO_SANS_LIGHT: Font = Font::with_name("Noto Sans Light"); | ||
pub const NOTO_SANS_LIGHT_ITALIC: Font = Font::with_name("Noto Sans Light Italic"); | ||
pub const NOTO_SANS_BOLD: Font = Font::with_name("Noto Sans Bold"); | ||
pub const NOTO_SANS_BOLD_ITALIC: Font = Font::with_name("Noto Sans Bold Italic"); | ||
|
||
/// Useful for initializing the Settings, like this: | ||
/// ```rust | ||
/// Settings { | ||
/// ... | ||
/// fonts: noto_sans_fonts_data().into_iter().collect(), | ||
/// } | ||
/// ``` | ||
pub const fn noto_sans_fonts_data() -> [Cow<'static, [u8]>; 8] { | ||
[ | ||
Cow::Borrowed(nih_plug_assets::fonts::NOTO_SANS_REGULAR), | ||
Cow::Borrowed(nih_plug_assets::fonts::NOTO_SANS_REGULAR_ITALIC), | ||
Cow::Borrowed(nih_plug_assets::fonts::NOTO_SANS_THIN), | ||
Cow::Borrowed(nih_plug_assets::fonts::NOTO_SANS_THIN_ITALIC), | ||
Cow::Borrowed(nih_plug_assets::fonts::NOTO_SANS_LIGHT), | ||
Cow::Borrowed(nih_plug_assets::fonts::NOTO_SANS_LIGHT_ITALIC), | ||
Cow::Borrowed(nih_plug_assets::fonts::NOTO_SANS_BOLD), | ||
Cow::Borrowed(nih_plug_assets::fonts::NOTO_SANS_BOLD_ITALIC), | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,23 @@ | ||
//! And [`Editor`] implementation for iced. | ||
use baseview::{WindowOpenOptions, WindowScalePolicy}; | ||
use ::baseview::{WindowOpenOptions, WindowScalePolicy}; | ||
use crossbeam::atomic::AtomicCell; | ||
use crossbeam::channel; | ||
pub use iced_baseview::*; | ||
use iced_baseview::settings::IcedBaseviewSettings; | ||
use nih_plug::prelude::{Editor, GuiContext, ParentWindowHandle}; | ||
use raw_window_handle::{HasRawWindowHandle, RawWindowHandle}; | ||
use std::sync::atomic::Ordering; | ||
use std::{borrow::Cow, sync::atomic::Ordering}; | ||
use std::sync::Arc; | ||
|
||
use crate::{wrapper, IcedEditor, IcedState, ParameterUpdate}; | ||
|
||
pub use iced_baseview::*; | ||
|
||
/// An [`Editor`] implementation that renders an iced [`Application`]. | ||
pub(crate) struct IcedEditorWrapper<E: IcedEditor> { | ||
pub(crate) iced_state: Arc<IcedState>, | ||
pub(crate) initialization_flags: E::InitializationFlags, | ||
pub(crate) fonts: Vec<Cow<'static, [u8]>>, | ||
|
||
/// The scaling factor reported by the host, if any. On macOS this will never be set and we | ||
/// should use the system scaling factor instead. | ||
|
@@ -33,17 +36,17 @@ 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(); | ||
let mut handle = raw_window_handle::XcbWindowHandle::empty(); | ||
handle.window = window; | ||
RawWindowHandle::Xcb(handle) | ||
} | ||
ParentWindowHandle::AppKitNsView(ns_view) => { | ||
let mut handle = raw_window_handle::AppKitHandle::empty(); | ||
let mut handle = raw_window_handle::AppKitWindowHandle::empty(); | ||
handle.ns_view = ns_view; | ||
RawWindowHandle::AppKit(handle) | ||
} | ||
ParentWindowHandle::Win32Hwnd(hwnd) => { | ||
let mut handle = raw_window_handle::Win32Handle::empty(); | ||
let mut handle = raw_window_handle::Win32WindowHandle::empty(); | ||
handle.hwnd = hwnd; | ||
RawWindowHandle::Win32(handle) | ||
} | ||
|
@@ -62,7 +65,7 @@ impl<E: IcedEditor> Editor for IcedEditorWrapper<E> { | |
|
||
// TODO: iced_baseview does not have gracefuly error handling for context creation failures. | ||
// This will panic if the context could not be created. | ||
let window = IcedWindow::<wrapper::IcedEditorWrapperApplication<E>>::open_parented( | ||
let window = iced_baseview::open_parented::<wrapper::IcedEditorWrapperApplication<E>, _>( | ||
&ParentWindowHandleAdapter(parent), | ||
Settings { | ||
window: WindowOpenOptions { | ||
|
@@ -96,8 +99,8 @@ impl<E: IcedEditor> Editor for IcedEditorWrapper<E> { | |
// FIXME: Rust analyzer always thinks baseview/opengl is enabled even if we | ||
// don't explicitly enable it, so you'd get a compile error if this line | ||
// is missing | ||
#[cfg(not(feature = "opengl"))] | ||
gl_config: None, | ||
// #[cfg(not(feature = "opengl"))] | ||
// gl_config: None, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this is not needed anymore then the whole section including the comment can be removed. |
||
}, | ||
iced_baseview: IcedBaseviewSettings { | ||
ignore_non_modifier_keys: false, | ||
|
@@ -109,6 +112,7 @@ impl<E: IcedEditor> Editor for IcedEditorWrapper<E> { | |
self.parameter_updates_receiver.clone(), | ||
self.initialization_flags.clone(), | ||
), | ||
fonts: self.fonts.clone(), | ||
}, | ||
); | ||
|
||
|
@@ -154,7 +158,7 @@ impl<E: IcedEditor> Editor for IcedEditorWrapper<E> { | |
/// The window handle used for [`IcedEditorWrapper`]. | ||
struct IcedEditorHandle<Message: 'static + Send> { | ||
iced_state: Arc<IcedState>, | ||
window: iced_baseview::WindowHandle<Message>, | ||
window: iced_baseview::window::WindowHandle<Message>, | ||
} | ||
|
||
/// The window handle enum stored within 'WindowHandle' contains raw pointers. Is there a way around | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice drive by fix! Meant to add this for a while (would be nice if it was inferred from the edition of the workspace members) but I kept forgetting about it.