mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-09 05:06:43 +01:00
start testing suil/winit
This commit is contained in:
parent
dacce119c4
commit
278b213f12
8 changed files with 1071 additions and 6 deletions
47
crates/suil/src/test.rs
Normal file
47
crates/suil/src/test.rs
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
use crate::*;
|
||||
|
||||
#[test]
|
||||
fn panics () {
|
||||
self::ui::UI::run().join();
|
||||
panic!();
|
||||
}
|
||||
|
||||
mod ui {
|
||||
use std::thread::{spawn, JoinHandle};
|
||||
use ::winit::{
|
||||
application::ApplicationHandler,
|
||||
event::WindowEvent,
|
||||
event_loop::{ActiveEventLoop, ControlFlow, EventLoop},
|
||||
window::{Window, WindowId},
|
||||
platform::x11::EventLoopBuilderExtX11
|
||||
};
|
||||
pub struct UI(Option<Window>);
|
||||
impl UI {
|
||||
pub fn new () -> Self { Self(None) }
|
||||
pub fn run () -> JoinHandle<()> {
|
||||
let mut ui = Self::new();
|
||||
spawn(move||{
|
||||
let event_loop = EventLoop::builder().with_x11().with_any_thread(true).build().unwrap();
|
||||
event_loop.set_control_flow(ControlFlow::Wait);
|
||||
event_loop.run_app(&mut ui).unwrap()
|
||||
})
|
||||
}
|
||||
}
|
||||
impl ApplicationHandler for UI {
|
||||
fn resumed (&mut self, event_loop: &ActiveEventLoop) {
|
||||
self.0 = Some(event_loop.create_window(Window::default_attributes()).unwrap());
|
||||
}
|
||||
fn window_event (&mut self, event_loop: &ActiveEventLoop, id: WindowId, event: WindowEvent) {
|
||||
match event {
|
||||
WindowEvent::CloseRequested => {
|
||||
self.0.as_ref().unwrap().set_visible(false);
|
||||
event_loop.exit();
|
||||
},
|
||||
WindowEvent::RedrawRequested => {
|
||||
self.0.as_ref().unwrap().request_redraw();
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue