1
0
mirror of https://github.com/emilk/egui.git synced 2026-06-26 22:53:14 -04:00

Listen to scroll wheel (glium only)

This commit is contained in:
Emil Ernerfeldt
2020-04-22 20:01:49 +02:00
parent 9b404159c5
commit a8d9c3fc42
6 changed files with 77 additions and 38 deletions

View File

@@ -20,6 +20,14 @@ fn main() {
let context = glutin::ContextBuilder::new();
let display = glium::Display::new(window, context, &events_loop).unwrap();
display
.gl_window()
.set_inner_size(glutin::dpi::LogicalSize {
width: 1200.0,
height: 800.0,
});
display.gl_window().set_position((16, 32).into()); // Useful when debugging and constantly restarting it
let pixels_per_point = display.gl_window().get_hidpi_factor() as f32;
let mut emigui = Emigui::new(pixels_per_point);
@@ -54,34 +62,44 @@ fn main() {
}
raw_input.time = start_time.elapsed().as_nanos() as f64 * 1e-9;
raw_input.scroll_delta = vec2(0.0, 0.0);
events_loop.poll_events(|event| {
match event {
glutin::Event::WindowEvent { event, .. } => match event {
glutin::WindowEvent::CloseRequested => quit = true,
events_loop.poll_events(|event| match event {
glutin::Event::WindowEvent { event, .. } => match event {
glutin::WindowEvent::CloseRequested => quit = true,
glutin::WindowEvent::Resized(glutin::dpi::LogicalSize { width, height }) => {
raw_input.screen_size = vec2(width as f32, height as f32);
glutin::WindowEvent::Resized(glutin::dpi::LogicalSize { width, height }) => {
raw_input.screen_size = vec2(width as f32, height as f32);
}
glutin::WindowEvent::MouseInput { state, .. } => {
raw_input.mouse_down = state == glutin::ElementState::Pressed;
}
glutin::WindowEvent::CursorMoved { position, .. } => {
raw_input.mouse_pos = Some(pos2(position.x as f32, position.y as f32));
}
glutin::WindowEvent::KeyboardInput { input, .. } => {
if input.virtual_keycode == Some(glutin::VirtualKeyCode::Q)
&& input.modifiers.logo
{
quit = true;
}
glutin::WindowEvent::MouseInput { state, .. } => {
raw_input.mouse_down = state == glutin::ElementState::Pressed;
}
glutin::WindowEvent::CursorMoved { position, .. } => {
raw_input.mouse_pos = Some(pos2(position.x as f32, position.y as f32));
}
glutin::WindowEvent::KeyboardInput { input, .. } => {
if input.virtual_keycode == Some(glutin::VirtualKeyCode::Q)
&& input.modifiers.logo
{
quit = true;
}
glutin::WindowEvent::MouseWheel { delta, .. } => {
match delta {
glutin::MouseScrollDelta::LineDelta(x, y) => {
raw_input.scroll_delta = vec2(x, y) * 24.0;
}
glutin::MouseScrollDelta::PixelDelta(delta) => {
// Actually point delta
raw_input.scroll_delta = vec2(delta.x as f32, delta.y as f32);
}
}
_ => {
// dbg!(event);
}
},
_ => (),
}
}
_ => {
// dbg!(event);
}
},
_ => (),
});
emigui.new_frame(raw_input);
@@ -93,14 +111,15 @@ fn main() {
quit = true;
}
Window::new("Example APP")
.default_pos(pos2(200.0, 100.0))
Window::new("Examples")
.default_pos(pos2(100.0, 100.0))
.default_size(vec2(300.0, 400.0))
.show(region.ctx(), |region| {
example_app.ui(region);
});
Window::new("Emigui settings")
.default_pos(pos2(200.0, 500.0))
.default_pos(pos2(100.0, 550.0))
.show(region.ctx(), |region| {
emigui.ui(region);
});
@@ -113,7 +132,7 @@ fn main() {
region.add_label("This window can be reisized, but not smaller than the contents.");
});
Window::new("Resize me!")
.default_pos(pos2(600.0, 500.0))
.default_pos(pos2(600.0, 550.0))
.expand_to_fit_content(false)
.show(region.ctx(), |region| {
region