this may actually work

This commit is contained in:
2025-07-01 02:43:35 +02:00
parent b2a874da29
commit 9a626fb1bc
5 changed files with 250 additions and 1785 deletions
-44
View File
@@ -1,44 +0,0 @@
use winit::application::ApplicationHandler;
use winit::dpi::LogicalSize;
use winit::event::WindowEvent;
use winit::event_loop::{ActiveEventLoop, ControlFlow, EventLoop};
use winit::window::{Window, WindowAttributes, WindowId};
struct App {
window: Option<Window>,
attr: WindowAttributes,
}
impl App {
pub fn new(attr: WindowAttributes) -> App {
App { window: None, attr }
}
}
impl ApplicationHandler for App {
fn resumed(&mut self, event_loop: &ActiveEventLoop) {
self.window = Some(event_loop.create_window(self.attr.clone()).unwrap());
}
fn window_event(&mut self, event_loop: &ActiveEventLoop, _id: WindowId, event: WindowEvent) {
match event {
WindowEvent::CloseRequested => {
event_loop.exit();
}
WindowEvent::RedrawRequested => {
self.window.as_ref().unwrap().request_redraw();
}
_ => (),
}
}
}
pub fn run(width: f64, height: f64) {
let event_loop = EventLoop::new().unwrap();
event_loop.set_control_flow(ControlFlow::Poll);
event_loop.set_control_flow(ControlFlow::Wait);
let mut w = WindowAttributes::default();
w.inner_size = Some(winit::dpi::Size::Logical(LogicalSize::new(width, height)));
let mut app = App::new(w);
event_loop.run_app(&mut app).unwrap();
}
+21 -11
View File
@@ -1,19 +1,29 @@
mod app;
use minifb::Window;
pub struct Window {
width: f64,
height: f64,
pub struct App {
window: Window,
}
impl Window {
pub fn new() -> Window {
Window {
width: 1000.0,
height: 650.0,
impl App {
pub fn new(win: Window) -> Self {
Self { window: win }
}
pub fn run(&mut self) {
while self.window.is_open() {
self.render();
}
}
pub fn run(&self) {
app::run(self.width, self.height);
fn render(&mut self) {
let (w, h) = self.window.get_size();
let mut buffer = vec![0; w * h];
for y in 100..200 {
for x in 150..300 {
buffer[y * h + x] = 0xFF00FF;
}
}
self.window.update_with_buffer(&buffer, w, h).unwrap();
}
}
+6 -3
View File
@@ -1,7 +1,10 @@
use osgui::Window;
use minifb::{Window, WindowOptions};
use osgui::App;
fn main() {
let win = Window::new();
let window = Window::new("minifb example", 500, 500, WindowOptions::default()).unwrap();
win.run();
let mut app = App::new(window);
app.run();
}