Change AppWindow::create_context() to AppWindow::build()
This commit is contained in:
parent
93dfe909a8
commit
08390d6004
|
@ -10,24 +10,20 @@ fn main() {
|
||||||
parent: baseview::Parent::None,
|
parent: baseview::Parent::None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let my_program = MyProgram {};
|
|
||||||
|
|
||||||
let (_app_message_tx, app_message_rx) = mpsc::channel::<()>();
|
let (_app_message_tx, app_message_rx) = mpsc::channel::<()>();
|
||||||
|
|
||||||
// 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::open(window_open_options, my_program, app_message_rx);
|
let _ = baseview::Window::<MyProgram>::open(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 create_context(
|
fn build(_window_handle: baseview::RawWindow, window_info: &baseview::WindowInfo) -> Self {
|
||||||
&mut self,
|
println!("Window info: {:?}", window_info);
|
||||||
_window: baseview::RawWindow,
|
Self {}
|
||||||
_window_info: &baseview::WindowInfo,
|
|
||||||
) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw(&mut self) {}
|
fn draw(&mut self) {}
|
||||||
|
|
|
@ -36,7 +36,8 @@ pub struct WindowOpenOptions<'a> {
|
||||||
pub trait AppWindow {
|
pub trait AppWindow {
|
||||||
type AppMessage;
|
type AppMessage;
|
||||||
|
|
||||||
fn create_context(&mut self, window: RawWindow, window_info: &WindowInfo);
|
fn build(window_handle: RawWindow, window_info: &WindowInfo) -> Self;
|
||||||
|
|
||||||
fn draw(&mut self);
|
fn draw(&mut self);
|
||||||
fn on_event(&mut self, event: Event);
|
fn on_event(&mut self, event: Event);
|
||||||
fn on_app_message(&mut self, message: Self::AppMessage);
|
fn on_app_message(&mut self, message: Self::AppMessage);
|
||||||
|
|
|
@ -17,11 +17,7 @@ pub struct Window<A: AppWindow> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<A: AppWindow> Window<A> {
|
impl<A: AppWindow> Window<A> {
|
||||||
pub fn open(
|
pub fn open(options: WindowOpenOptions, app_message_rx: mpsc::Receiver<A::AppMessage>) -> Self {
|
||||||
options: WindowOpenOptions,
|
|
||||||
app_window: A,
|
|
||||||
app_message_rx: mpsc::Receiver<A::AppMessage>,
|
|
||||||
) -> Self {
|
|
||||||
// Convert the parent to a X11 window ID if we're given one
|
// Convert the parent to a X11 window ID if we're given one
|
||||||
let parent = match options.parent {
|
let parent = match options.parent {
|
||||||
Parent::None => None,
|
Parent::None => None,
|
||||||
|
@ -112,6 +108,14 @@ impl<A: AppWindow> Window<A> {
|
||||||
.or(Some(1.0))
|
.or(Some(1.0))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
let window_info = WindowInfo {
|
||||||
|
width: options.width as u32,
|
||||||
|
height: options.height as u32,
|
||||||
|
scale: scaling,
|
||||||
|
};
|
||||||
|
|
||||||
|
let app_window = A::build(raw_window, &window_info);
|
||||||
|
|
||||||
let mut x11_window = Self {
|
let mut x11_window = Self {
|
||||||
scaling,
|
scaling,
|
||||||
xcb_connection,
|
xcb_connection,
|
||||||
|
@ -119,16 +123,6 @@ impl<A: AppWindow> Window<A> {
|
||||||
app_message_rx,
|
app_message_rx,
|
||||||
};
|
};
|
||||||
|
|
||||||
let window_info = WindowInfo {
|
|
||||||
width: options.width as u32,
|
|
||||||
height: options.height as u32,
|
|
||||||
scale: x11_window.scaling,
|
|
||||||
};
|
|
||||||
|
|
||||||
x11_window
|
|
||||||
.app_window
|
|
||||||
.create_context(raw_window, &window_info);
|
|
||||||
|
|
||||||
x11_window.run_event_loop();
|
x11_window.run_event_loop();
|
||||||
|
|
||||||
x11_window
|
x11_window
|
||||||
|
|
Loading…
Reference in a new issue