Skip to content

Commit

Permalink
add: mouse hide and lock test
Browse files Browse the repository at this point in the history
  • Loading branch information
luftaquila committed Apr 21, 2024
1 parent 9424dea commit 3fe5cb2
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions src/bin/winit.rs
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
use winit::{
dpi::PhysicalSize,
event::{Event, WindowEvent},
dpi::{PhysicalPosition, PhysicalSize},
event::Event,
event_loop::{ControlFlow, EventLoop},
window::{Window, WindowBuilder},
platform::run_return::EventLoopExtRunReturn,
window::WindowBuilder,
};

use pixels::{Pixels, SurfaceTexture};

fn main() {
let size_i = PhysicalSize::new(1, 1);
let size = PhysicalSize::new(100, 100);

let event_loop = EventLoop::new();
let mut event_loop = EventLoop::new();
let window = WindowBuilder::new()
.with_transparent(true)
.with_decorations(false)
.with_inner_size(size_i)
.with_inner_size(PhysicalSize::new(1, 1))
.with_position(PhysicalPosition::new(0, 0))
.with_visible(false)
.build(&event_loop)
.unwrap();
window.set_cursor_visible(false);

let mut pixels = Pixels::new(
size_i.width,
size_i.height,
SurfaceTexture::new(size_i.width, size_i.height, &window),
)
.unwrap();
let mut pixels = Pixels::new(1, 1, SurfaceTexture::new(1, 1, &window)).unwrap();

window.set_inner_size(PhysicalSize::new(100, 100));
window.set_visible(true);

for pixel in pixels.frame_mut().chunks_exact_mut(4) {
pixel.copy_from_slice(&[0x00, 0x00, 0x00, 0x80]);
}
// window.request_redraw();

event_loop.run(move |event, _, control_flow| {
event_loop.run_return(move |event, _, control_flow| {
*control_flow = ControlFlow::Wait;

println!("{:?}", event);

if let Event::RedrawRequested(_) = event {
pixels.render().unwrap();
}

window.set_inner_size(size);
window.set_visible(true);

window.request_redraw();
window
.set_cursor_position(PhysicalPosition::new(50, 50))
.unwrap();
// *control_flow = ControlFlow::Exit;
});
}

0 comments on commit 3fe5cb2

Please sign in to comment.