Added an empty window using winit
This commit is contained in:
parent
a2488d8015
commit
c92592600e
2427
Cargo.lock
generated
2427
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
|
@ -4,3 +4,5 @@ version = "0.1.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
image = "0.25.10"
|
||||||
|
winit = "0.30.13"
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,54 @@
|
||||||
fn main() {
|
use winit::application::ApplicationHandler;
|
||||||
println!("Hello, world!");
|
use winit::event::WindowEvent;
|
||||||
|
use winit::event_loop::{ActiveEventLoop, ControlFlow, EventLoop};
|
||||||
|
use winit::window::{Window, WindowId};
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
|
struct App {
|
||||||
|
window: Option<Window>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ApplicationHandler for App {
|
||||||
|
fn resumed(&mut self, event_loop: &ActiveEventLoop) {
|
||||||
|
let attributes = Window::default_attributes()
|
||||||
|
.with_title("Project Catalyst");
|
||||||
|
|
||||||
|
self.window = Some(event_loop.create_window(attributes).unwrap());
|
||||||
|
}
|
||||||
|
|
||||||
|
fn window_event(&mut self, event_loop: &ActiveEventLoop, _id: WindowId, event: WindowEvent) {
|
||||||
|
match event {
|
||||||
|
WindowEvent::CloseRequested => {
|
||||||
|
event_loop.exit();
|
||||||
|
},
|
||||||
|
WindowEvent::RedrawRequested => {
|
||||||
|
// Redraw the application.
|
||||||
|
//
|
||||||
|
// It's preferable for applications that do not render continuously to render in
|
||||||
|
// this event rather than in AboutToWait, since rendering in here allows
|
||||||
|
// the program to gracefully handle redraws requested by the OS.
|
||||||
|
|
||||||
|
// Draw.
|
||||||
|
|
||||||
|
// Queue a RedrawRequested event.
|
||||||
|
//
|
||||||
|
// You only need to call this if you've determined that you need to redraw in
|
||||||
|
// applications which do not always need to. Applications that redraw continuously
|
||||||
|
// can render here instead.
|
||||||
|
self.window.as_ref().unwrap().request_redraw();
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let event_loop = EventLoop::new().unwrap();
|
||||||
|
|
||||||
|
// ControlFlow::Poll continuously runs the event loop, even if the OS hasn't
|
||||||
|
// dispatched any events. This is ideal for games and similar applications.
|
||||||
|
event_loop.set_control_flow(ControlFlow::Poll);
|
||||||
|
|
||||||
|
let mut app = App::default();
|
||||||
|
event_loop.run_app(&mut app).unwrap();
|
||||||
}
|
}
|
||||||
6
crates/scripting/Cargo.toml
Normal file
6
crates/scripting/Cargo.toml
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
[package]
|
||||||
|
name = "scripting"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
14
crates/scripting/src/lib.rs
Normal file
14
crates/scripting/src/lib.rs
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
pub fn add(left: u64, right: u64) -> u64 {
|
||||||
|
left + right
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn it_works() {
|
||||||
|
let result = add(2, 2);
|
||||||
|
assert_eq!(result, 4);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue