Skip to content

Commit

Permalink
Prevent events from being dragged outside the map
Browse files Browse the repository at this point in the history
(cherry picked from commit 6dc7e7d)
  • Loading branch information
white-axe committed Nov 22, 2023
1 parent 87ea63d commit 142459f
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions crates/ui/src/tabs/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,10 +431,19 @@ impl luminol_core::Tab for Tab {
// after adjusting for drag offset, unless that would put the event
// on the same tile as an existing event
let adjusted_hover_tile = hover_tile + info.offset;
if !map.events.iter().any(|(_, e)| {
adjusted_hover_tile.x == e.x as f32
&& adjusted_hover_tile.y == e.y as f32
}) {
if egui::Rect::from_min_size(
egui::pos2(0., 0.),
egui::vec2(
map.data.xsize() as f32 - 0.5,
map.data.ysize() as f32 - 0.5,
),
)
.contains(adjusted_hover_tile)
&& !map.events.iter().any(|(_, e)| {
adjusted_hover_tile.x == e.x as f32
&& adjusted_hover_tile.y == e.y as f32
})
{
if let Some(selected_event) = map.events.get_mut(selected_event_id)
{
selected_event.x = adjusted_hover_tile.x as i32;
Expand Down

0 comments on commit 142459f

Please sign in to comment.