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 5cbdb89
Showing 1 changed file with 20 additions and 23 deletions.
43 changes: 20 additions & 23 deletions src/bin/winit.rs
Original file line number Diff line number Diff line change
@@ -1,47 +1,44 @@
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();

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

event_loop.run(move |event, _, control_flow| {
*control_flow = ControlFlow::Wait;
window.set_inner_size(PhysicalSize::new(100, 100));
window.set_cursor_visible(false);
window.set_visible(true);

pixels.render().unwrap();

if let Event::RedrawRequested(_) = event {
pixels.render().unwrap();
}
event_loop.run_return(move |event, _, control_flow| {
*control_flow = ControlFlow::Wait;

window.set_inner_size(size);
window.set_visible(true);
println!("{:?}", event);

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

0 comments on commit 5cbdb89

Please sign in to comment.