Canary egui harness cursor input

This commit is contained in:
mars 2022-07-25 18:27:18 -06:00
parent 77465dab6e
commit 495fb40c9f
1 changed files with 19 additions and 16 deletions

View File

@ -1,4 +1,4 @@
use canary::ScriptInstance;
use canary::{CursorEventKind, ScriptInstance};
use eframe::egui;
use std::time::Instant;
@ -56,27 +56,30 @@ impl eframe::App for App {
let sense = egui::Sense {
click: true,
drag: true,
focusable: false,
focusable: true,
};
let (rect, response) = ui.allocate_at_least(size, sense);
// TODO input events
/*let input = ui.input();
for event in input.events.iter() {
let event = match event {
egui::Event::PointerMoved(pos) => {
if input.pointer.primary_down() {
Some(())
}
}
_ => None,
if let Some(hover_pos) = response.hover_pos() {
let local = (hover_pos - rect.left_top()) / rect.size();
let norm = local * 2.0 - egui::vec2(1.0, 1.0);
let x = norm.x;
let y = -norm.y;
let pos = canary::Vec2 { x, y };
let kind = if response.drag_started() {
CursorEventKind::Select
} else if response.drag_released() {
CursorEventKind::Deselect
} else if response.dragged() {
CursorEventKind::Drag
} else {
CursorEventKind::Hover
};
if let Some((kind, x, y)) = event {
self.script.on_cursor_event(kind, canary::Vec2 { x, y });
}
}*/
self.script.on_cursor_event(kind, pos);
}
let texture = egui::TextureId::Managed(0);
let uv = egui::pos2(0.0, 0.0);