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

use HasRawWindowHandle instead of RawWindowHandle #20

Merged
merged 3 commits into from Feb 8, 2021
Merged

use HasRawWindowHandle instead of RawWindowHandle #20

merged 3 commits into from Feb 8, 2021

Conversation

BillyDM
Copy link
Contributor

@BillyDM BillyDM commented Feb 8, 2021

Baseview requires a struct that implements HasRawWindowHandle, which means the user must convert the RawWindowHandle given in PluginUI::ui_open() into a struct that implements that. This PR fixes that by converting it at the baseview level.

It is called TrustedWindowHandle because of it mirrors this: https://github.com/rust-windowing/raw-window-handle/blob/master/src/lib.rs#L210. I don't believe that this is in crates.io yet, so I created a temporary one.

Instead of the user doing this:

fn ui_open(parent: RawWindowHandle) -> WindowOpenResult<Self::Handle> {
    let settings = iced_baseview::Settings {
        window: WindowOpenOptions {
            title: String::from("iced-baseplug-examples gain"),
            size: Size::new(Self::ui_size().0 as f64, Self::ui_size().1 as f64),
            scale: WindowScalePolicy::SystemScaleFactor,
        },
        flags: (),
    };

    // TODO: Fix this mess in baseplug.
    struct ParentWindow(RawWindowHandle);
    unsafe impl HasRawWindowHandle for ParentWindow {
        fn raw_window_handle(&self) -> RawWindowHandle {
            self.0
        }
    }

    let handle =
        iced_baseview::IcedWindow::<ui::GainUI>::open_parented(&ParentWindow(parent), settings);

    Ok(handle)
}

They can now do this:

fn ui_open(parent: &impl HasRawWindowHandle) -> WindowOpenResult<Self::Handle> {
    let settings = iced_baseview::Settings {
        window: WindowOpenOptions {
            title: String::from("iced-baseplug-examples gain"),
            size: Size::new(Self::ui_size().0 as f64, Self::ui_size().1 as f64),
            scale: WindowScalePolicy::SystemScaleFactor,
        },
        flags: (),
    };

    let handle =
        iced_baseview::IcedWindow::<ui::GainUI>::open_parented(parent, settings);

    Ok(handle)
}

@BillyDM BillyDM changed the title use TrustedWindowHandle instead of RawWindowHandle use HasRawWindowHandle instead of RawWindowHandle Feb 8, 2021
@wrl wrl merged commit 0c9a54f into wrl:trunk Feb 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants