Skip to content

Commit

Permalink
Tilepicker now uses projection matrix
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
white-axe committed Oct 6, 2023
1 parent 717c148 commit 0e331ce
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
12 changes: 10 additions & 2 deletions src/components/tilepicker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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. {
Expand All @@ -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| {
Expand Down
4 changes: 2 additions & 2 deletions src/tabs/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
Expand Down

0 comments on commit 0e331ce

Please sign in to comment.