api change: AppWindow methods receive an &mut Window, which implements HasRawWindowHandle
This commit is contained in:
parent
17c673957c
commit
58ed00eb11
|
@ -1,6 +1,6 @@
|
||||||
use std::sync::mpsc;
|
use std::sync::mpsc;
|
||||||
|
|
||||||
use baseview::Event;
|
use baseview::{Event, Window};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let window_open_options = baseview::WindowOpenOptions {
|
let window_open_options = baseview::WindowOpenOptions {
|
||||||
|
@ -14,21 +14,21 @@ fn main() {
|
||||||
|
|
||||||
// Send _app_message_tx to a separate thread, then send messages to the GUI thread.
|
// Send _app_message_tx to a separate thread, then send messages to the GUI thread.
|
||||||
|
|
||||||
let _ = baseview::Window::<MyProgram>::open(window_open_options, app_message_rx);
|
let _ = Window::open::<MyProgram>(window_open_options, app_message_rx);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct MyProgram {}
|
struct MyProgram {}
|
||||||
|
|
||||||
impl baseview::AppWindow for MyProgram {
|
impl baseview::AppWindow for MyProgram {
|
||||||
type AppMessage = ();
|
type AppMessage = ();
|
||||||
|
|
||||||
fn build(_window_handle: baseview::RawWindow, window_info: &baseview::WindowInfo) -> Self {
|
fn build(window: &mut Window) -> Self {
|
||||||
println!("Window info: {:?}", window_info);
|
|
||||||
Self {}
|
Self {}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw(&mut self) {}
|
fn draw(&mut self, window: &mut Window) {}
|
||||||
|
|
||||||
fn on_event(&mut self, event: Event) {
|
fn on_event(&mut self, window: &mut Window, event: Event) {
|
||||||
match event {
|
match event {
|
||||||
Event::CursorMotion(x, y) => {
|
Event::CursorMotion(x, y) => {
|
||||||
println!("Cursor moved, x: {}, y: {}", x, y);
|
println!("Cursor moved, x: {}, y: {}", x, y);
|
||||||
|
@ -69,5 +69,5 @@ impl baseview::AppWindow for MyProgram {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_app_message(&mut self, _message: Self::AppMessage) {}
|
fn on_app_message(&mut self, window: &mut Window, _message: Self::AppMessage) {}
|
||||||
}
|
}
|
||||||
|
|
20
src/lib.rs
20
src/lib.rs
|
@ -36,21 +36,9 @@ pub struct WindowOpenOptions<'a> {
|
||||||
pub trait AppWindow {
|
pub trait AppWindow {
|
||||||
type AppMessage;
|
type AppMessage;
|
||||||
|
|
||||||
fn build(window_handle: RawWindow, window_info: &WindowInfo) -> Self;
|
fn build(window: &mut Window) -> Self;
|
||||||
|
|
||||||
fn draw(&mut self);
|
fn draw(&mut self, window: &mut Window);
|
||||||
fn on_event(&mut self, event: Event);
|
fn on_event(&mut self, window: &mut Window, event: Event);
|
||||||
fn on_app_message(&mut self, message: Self::AppMessage);
|
fn on_app_message(&mut self, window: &mut Window, message: Self::AppMessage);
|
||||||
}
|
|
||||||
|
|
||||||
/// A wrapper for a `RawWindowHandle`. Some context creators expect an `&impl HasRawWindowHandle`.
|
|
||||||
#[derive(Debug, Copy, Clone)]
|
|
||||||
pub struct RawWindow {
|
|
||||||
pub raw_window_handle: raw_window_handle::RawWindowHandle,
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl raw_window_handle::HasRawWindowHandle for RawWindow {
|
|
||||||
fn raw_window_handle(&self) -> raw_window_handle::RawWindowHandle {
|
|
||||||
self.raw_window_handle
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue