Merge branch 'main' into force-directed-graph
This commit is contained in:
commit
eac404e976
|
@ -2,10 +2,10 @@ use std::collections::HashMap;
|
|||
use std::path::PathBuf;
|
||||
use std::time::Instant;
|
||||
|
||||
use canary::{Panel, Runtime, Vec2};
|
||||
use canary::{CursorEventKind, Panel, Runtime, Vec2, PX_PER_MM};
|
||||
use glium::backend::glutin::DisplayCreationError;
|
||||
use glium::{glutin, Surface};
|
||||
use glutin::event::{Event, WindowEvent};
|
||||
use glutin::event::{ElementState, Event, MouseButton, WindowEvent};
|
||||
use glutin::event_loop::{ControlFlow, EventLoop, EventLoopProxy, EventLoopWindowTarget};
|
||||
use glutin::window::WindowId;
|
||||
|
||||
|
@ -26,6 +26,7 @@ pub struct Window {
|
|||
pub graphics: Graphics,
|
||||
pub panel: Panel,
|
||||
pub last_update: Instant,
|
||||
pub cursor_pos: Vec2,
|
||||
}
|
||||
|
||||
impl Window {
|
||||
|
@ -42,6 +43,7 @@ impl Window {
|
|||
graphics,
|
||||
panel,
|
||||
last_update,
|
||||
cursor_pos: Vec2::ZERO,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -75,9 +77,26 @@ impl Window {
|
|||
pub fn on_event(&mut self, event: WindowEvent) {
|
||||
match event {
|
||||
WindowEvent::Resized(size) => {
|
||||
self.resize(Vec2::new(size.width as f32, size.height as f32) * canary::PX_PER_MM);
|
||||
self.resize(Vec2::new(size.width as f32, size.height as f32) * PX_PER_MM);
|
||||
self.request_redraw()
|
||||
}
|
||||
WindowEvent::CursorMoved { position, .. } => {
|
||||
let x = position.x as f32 * PX_PER_MM;
|
||||
let y = position.y as f32 * PX_PER_MM;
|
||||
self.cursor_pos = Vec2::new(x, y);
|
||||
}
|
||||
WindowEvent::MouseInput {
|
||||
state,
|
||||
button: MouseButton::Left,
|
||||
..
|
||||
} => {
|
||||
let event = match state {
|
||||
ElementState::Pressed => CursorEventKind::Select,
|
||||
ElementState::Released => CursorEventKind::Deselect,
|
||||
};
|
||||
|
||||
self.panel.on_cursor_event(event, self.cursor_pos);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue