From 0e331ce7e19a07c75c8cc034e71b37ce2540f176 Mon Sep 17 00:00:00 2001 From: white-axe Date: Fri, 6 Oct 2023 18:01:11 +0000 Subject: [PATCH] Tilepicker now uses projection matrix The map editor should now be working in web builds! Except you won't be able to use the keyboard because I haven't put the keyboard handling code into the app runner yet. --- src/components/tilepicker.rs | 12 ++++++++++-- src/tabs/map.rs | 4 ++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/components/tilepicker.rs b/src/components/tilepicker.rs index e5c329dc..c04bf18b 100644 --- a/src/components/tilepicker.rs +++ b/src/components/tilepicker.rs @@ -121,7 +121,7 @@ impl Tilepicker { } } - pub fn ui(&mut self, ui: &mut egui::Ui) -> egui::Response { + pub fn ui(&mut self, ui: &mut egui::Ui, scroll_rect: egui::Rect) -> egui::Response { let time = ui.ctx().input(|i| i.time); if let Some(ani_time) = self.ani_time { if time - ani_time >= 16. / 60. { @@ -143,8 +143,16 @@ impl Tilepicker { let prepare_id = Arc::new(OnceCell::new()); let paint_id = prepare_id.clone(); + resources.viewport.set_proj(glam::Mat4::orthographic_rh( + scroll_rect.left(), + scroll_rect.right(), + scroll_rect.bottom(), + scroll_rect.top(), + -1., + 1., + )); ui.painter().add(egui::PaintCallback { - rect: canvas_rect, + rect: scroll_rect.translate(canvas_rect.min.to_vec2()), callback: Arc::new( egui_wgpu::CallbackFn::new() .prepare(move |_, _, _encoder, paint_callback_resources| { diff --git a/src/tabs/map.rs b/src/tabs/map.rs index fa0c7aae..d364eed3 100644 --- a/src/tabs/map.rs +++ b/src/tabs/map.rs @@ -419,8 +419,8 @@ impl tab::Tab for Tab { .default_width(tilepicker_default_width) .max_width(tilepicker_default_width) .show_inside(ui, |ui| { - egui::ScrollArea::both().show(ui, |ui| { - self.tilepicker.ui(ui); + egui::ScrollArea::both().show_viewport(ui, |ui, rect| { + self.tilepicker.ui(ui, rect); ui.separator(); }); });