Skip to content

Commit

Permalink
Properly handle sprite scrolling
Browse files Browse the repository at this point in the history
  • Loading branch information
melody-rs committed Jun 29, 2024
1 parent f11243c commit e64d80a
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions crates/modals/src/event_graphic_picker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,17 +412,27 @@ impl Modal {
egui::Sense::click(),
);

let absolute_scroll_rect = ui
.ctx()
.screen_rect()
.intersect(viewport.translate(canvas_rect.min.to_vec2()));
let scroll_rect = absolute_scroll_rect.translate(-canvas_rect.min.to_vec2());
sprite.sprite.transform.set_position(
&update_state.graphics.render_state,
glam::vec2(-scroll_rect.left(), -scroll_rect.top()),
);

sprite.viewport.set(
&update_state.graphics.render_state,
glam::vec2(canvas_rect.width(), canvas_rect.height()),
glam::vec2(absolute_scroll_rect.width(), absolute_scroll_rect.height()),
glam::Vec2::ZERO,
glam::Vec2::ONE,
);

let painter = Painter::new(sprite.sprite.prepare(&update_state.graphics));
ui.painter()
.add(luminol_egui_wgpu::Callback::new_paint_callback(
canvas_rect,
absolute_scroll_rect,
painter,
));

Expand Down

0 comments on commit e64d80a

Please sign in to comment.