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 c8f963d
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/bin/winit.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use winit::{
dpi::PhysicalSize,
event::{Event, WindowEvent},
dpi::{PhysicalSize, PhysicalPosition},
event::Event,
event_loop::{ControlFlow, EventLoop},
window::{Window, WindowBuilder},
platform::run_return::EventLoopExtRunReturn,
window::WindowBuilder,
};

use pixels::{Pixels, SurfaceTexture};
Expand All @@ -11,11 +12,12 @@ 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_position(PhysicalPosition::new(0, 0))
.with_visible(false)
.build(&event_loop)
.unwrap();
Expand All @@ -28,20 +30,24 @@ fn main() {
)
.unwrap();

window.set_inner_size(size);
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 c8f963d

Please sign in to comment.