Rename Application tratit to AppWindow
This commit is contained in:
parent
29917b87cd
commit
6cf5966afa
|
@ -20,7 +20,7 @@ fn main() {
|
|||
}
|
||||
struct MyProgram {}
|
||||
|
||||
impl baseview::Application for MyProgram {
|
||||
impl baseview::AppWindow for MyProgram {
|
||||
type AppMessage = ();
|
||||
|
||||
fn create_context(
|
||||
|
|
|
@ -33,7 +33,7 @@ pub struct WindowOpenOptions<'a> {
|
|||
pub parent: Parent,
|
||||
}
|
||||
|
||||
pub trait Application {
|
||||
pub trait AppWindow {
|
||||
type AppMessage;
|
||||
|
||||
fn create_context(
|
||||
|
|
|
@ -6,17 +6,17 @@ use cocoa::appkit::{
|
|||
use cocoa::base::{nil, NO};
|
||||
use cocoa::foundation::{NSAutoreleasePool, NSPoint, NSRect, NSSize, NSString};
|
||||
|
||||
use crate::{Application, Event, MouseButtonID, MouseScroll, WindowOpenOptions};
|
||||
use crate::{AppWindow, Event, MouseButtonID, MouseScroll, WindowOpenOptions};
|
||||
|
||||
pub struct Window<A: Application> {
|
||||
application: A,
|
||||
pub struct Window<A: AppWindow> {
|
||||
app_window: A,
|
||||
app_message_rx: mpsc::Receiver<A::AppMessage>,
|
||||
}
|
||||
|
||||
impl<A: Application> Window<A> {
|
||||
pub fn open(
|
||||
options: WindowOpenOptions,
|
||||
application: A,
|
||||
app_window: A,
|
||||
app_message_rx: mpsc::Receiver<A::AppMessage>,
|
||||
) -> Self {
|
||||
unsafe {
|
||||
|
@ -50,7 +50,7 @@ impl<A: Application> Window<A> {
|
|||
app.run();
|
||||
|
||||
Window {
|
||||
application,
|
||||
app_window,
|
||||
app_message_rx,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ use self::winapi::um::winuser::{
|
|||
use self::winapi::ctypes::c_void;
|
||||
use crate::Parent::WithParent;
|
||||
use crate::{handle_message, WindowOpenOptions};
|
||||
use crate::{Application, Event, MouseButtonID, MouseScroll};
|
||||
use crate::{AppWindow, Event, MouseButtonID, MouseScroll};
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
unsafe fn message_box(title: &str, msg: &str) {
|
||||
|
@ -113,12 +113,12 @@ unsafe fn unregister_wnd_class(wnd_class: ATOM) {
|
|||
|
||||
unsafe fn init_gl_context() {}
|
||||
|
||||
pub struct Window<A: Application> {
|
||||
pub struct Window<A: AppWindow> {
|
||||
pub(crate) hwnd: HWND,
|
||||
hdc: HDC,
|
||||
gl_context: HGLRC,
|
||||
window_class: ATOM,
|
||||
application: A,
|
||||
app_window: A,
|
||||
app_message_rx: mpsc::Receiver<A::AppMessage>,
|
||||
scaling: Option<f64>, // DPI scale, 96.0 is "default".
|
||||
r: f32,
|
||||
|
@ -126,10 +126,10 @@ pub struct Window<A: Application> {
|
|||
b: f32,
|
||||
}
|
||||
|
||||
impl<A: Application> Window<A> {
|
||||
impl<A: AppWindow> Window<A> {
|
||||
pub fn open(
|
||||
options: WindowOpenOptions,
|
||||
application: A,
|
||||
app_window: A,
|
||||
app_message_rx: mpsc::Receiver<A::AppMessage>,
|
||||
) {
|
||||
unsafe {
|
||||
|
@ -138,7 +138,7 @@ impl<A: Application> Window<A> {
|
|||
hdc: null_mut(),
|
||||
gl_context: null_mut(),
|
||||
window_class: 0,
|
||||
application,
|
||||
app_window,
|
||||
app_message_rx,
|
||||
scaling: None,
|
||||
r: 0.3,
|
||||
|
@ -264,7 +264,7 @@ impl<A: Application> Window<A> {
|
|||
}
|
||||
|
||||
pub fn close(&self) {
|
||||
self.application.on_event(Event::WillClose);
|
||||
self.app_window.on_event(Event::WillClose);
|
||||
|
||||
// todo: see https://github.com/wrl/rutabaga/blob/f30ff67e157375cafdbafe5fb549f1790443a3a8/src/platform/win/window.c#L402
|
||||
unsafe {
|
||||
|
@ -289,6 +289,6 @@ impl<A: Application> Window<A> {
|
|||
self.r = r;
|
||||
self.g = g;
|
||||
|
||||
self.application.on_message(Event::CursorMotion(x, y));
|
||||
self.app_window.on_message(Event::CursorMotion(x, y));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,23 +6,21 @@ use ::x11::xlib;
|
|||
// use xcb::dri2; // needed later
|
||||
|
||||
use super::XcbConnection;
|
||||
use crate::{
|
||||
Application, Event, MouseButtonID, MouseScroll, Parent, WindowInfo, WindowOpenOptions,
|
||||
};
|
||||
use crate::{AppWindow, Event, MouseButtonID, MouseScroll, Parent, WindowInfo, WindowOpenOptions};
|
||||
|
||||
use raw_window_handle::RawWindowHandle;
|
||||
|
||||
pub struct Window<A: Application> {
|
||||
pub struct Window<A: AppWindow> {
|
||||
scaling: Option<f64>, // DPI scale, 96.0 is "default".
|
||||
xcb_connection: XcbConnection,
|
||||
application: A,
|
||||
app_window: A,
|
||||
app_message_rx: mpsc::Receiver<A::AppMessage>,
|
||||
}
|
||||
|
||||
impl<A: Application> Window<A> {
|
||||
impl<A: AppWindow> Window<A> {
|
||||
pub fn open(
|
||||
options: WindowOpenOptions,
|
||||
application: A,
|
||||
app_window: A,
|
||||
app_message_rx: mpsc::Receiver<A::AppMessage>,
|
||||
) -> Self {
|
||||
// Convert the parent to a X11 window ID if we're given one
|
||||
|
@ -136,7 +134,7 @@ impl<A: Application> Window<A> {
|
|||
let mut x11_window = Self {
|
||||
scaling: None,
|
||||
xcb_connection,
|
||||
application,
|
||||
app_window,
|
||||
app_message_rx,
|
||||
};
|
||||
|
||||
|
@ -151,7 +149,7 @@ impl<A: Application> Window<A> {
|
|||
};
|
||||
|
||||
x11_window
|
||||
.application
|
||||
.app_window
|
||||
.create_context(raw_handle, &window_info);
|
||||
|
||||
x11_window.run_event_loop();
|
||||
|
@ -191,14 +189,14 @@ impl<A: Application> Window<A> {
|
|||
|
||||
match event_type {
|
||||
xcb::EXPOSE => {
|
||||
self.application.on_event(Event::RenderExpose);
|
||||
self.app_window.on_event(Event::RenderExpose);
|
||||
}
|
||||
xcb::MOTION_NOTIFY => {
|
||||
let event = unsafe { xcb::cast_event::<xcb::MotionNotifyEvent>(&event) };
|
||||
let detail = event.detail();
|
||||
|
||||
if detail != 4 && detail != 5 {
|
||||
self.application.on_event(Event::CursorMotion(
|
||||
self.app_window.on_event(Event::CursorMotion(
|
||||
event.event_x() as i32,
|
||||
event.event_y() as i32,
|
||||
));
|
||||
|
@ -210,20 +208,20 @@ impl<A: Application> Window<A> {
|
|||
|
||||
match detail {
|
||||
4 => {
|
||||
self.application.on_event(Event::MouseScroll(MouseScroll {
|
||||
self.app_window.on_event(Event::MouseScroll(MouseScroll {
|
||||
x_delta: 0.0,
|
||||
y_delta: 1.0,
|
||||
}));
|
||||
}
|
||||
5 => {
|
||||
self.application.on_event(Event::MouseScroll(MouseScroll {
|
||||
self.app_window.on_event(Event::MouseScroll(MouseScroll {
|
||||
x_delta: 0.0,
|
||||
y_delta: -1.0,
|
||||
}));
|
||||
}
|
||||
detail => {
|
||||
let button_id = mouse_id(detail);
|
||||
self.application.on_event(Event::MouseDown(button_id));
|
||||
self.app_window.on_event(Event::MouseDown(button_id));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -233,20 +231,20 @@ impl<A: Application> Window<A> {
|
|||
|
||||
if detail != 4 && detail != 5 {
|
||||
let button_id = mouse_id(detail);
|
||||
self.application.on_event(Event::MouseUp(button_id));
|
||||
self.app_window.on_event(Event::MouseUp(button_id));
|
||||
}
|
||||
}
|
||||
xcb::KEY_PRESS => {
|
||||
let event = unsafe { xcb::cast_event::<xcb::KeyPressEvent>(&event) };
|
||||
let detail = event.detail();
|
||||
|
||||
self.application.on_event(Event::KeyDown(detail));
|
||||
self.app_window.on_event(Event::KeyDown(detail));
|
||||
}
|
||||
xcb::KEY_RELEASE => {
|
||||
let event = unsafe { xcb::cast_event::<xcb::KeyReleaseEvent>(&event) };
|
||||
let detail = event.detail();
|
||||
|
||||
self.application.on_event(Event::KeyUp(detail));
|
||||
self.app_window.on_event(Event::KeyUp(detail));
|
||||
}
|
||||
_ => {
|
||||
println!("Unhandled event type: {:?}", event_type);
|
||||
|
|
Loading…
Reference in a new issue