Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

collision overall - support for swap #1621

Merged
merged 1 commit into from
Feb 15, 2021
Merged

Conversation

adumesny
Copy link
Member

@adumesny adumesny commented Feb 15, 2021

Description

big overall of the collision detection code - you can now:

  • swap items of same size vertically/horizontally when grid is full (maxRow)
    this has been 5.5years in the making and the most asked question
    It is now also the default in float:false as it feels more natural than pushing new row
    (could add Alt-key to get either behavior of push vs swap ?)
  • moving items down or up behave the same way (used to have to push WAY past to insert after)
  • optimized the collision code to not do extra work multiple times and only check
    if change and not tried before
  • heuristics now checks for >50% past the grid mid point (taking margin into account)a

TODO part II: handle mid point of dragged over items rather 50% of row/column
and check for the most covered when multiple items collide.

Checklist

  • Created tests which fail without the change (if possible)
  • All tests passing (yarn test)
  • Extended the README / documentation, if necessary

big overall of the collision dectection code - you can now:
* swap items of same size vertically/horizontally when grid is full (maxRow)
***** this has been 5.5years in the making and the most asked question ****
It is now also the default in float:false as it feels more natural than pushing new row
(could add Alt-key to get either behavior of push vs swap ?)
* moving items down or up behave the same way (used to have to push WAY past to insert after)
* optimized the collision code to not do extra work multiple times and only check
if change and not tried before
* heuristics now checks for >50% past the grid mid point (taking margin into account)a

TODO part II:  handle mid point of dragged over items rather 50% of row/column
and check for the most covered when multiple items collide.

* fix gridstack#149 gridstack#1605 and partial gridstack#1094 (need better support for larger items mid point)
@adumesny adumesny merged commit 6d122cd into gridstack:develop Feb 15, 2021
@adumesny
Copy link
Member Author

default float:false (top gravity)

20210215_102443.mp4

float:true case

20210215_103145.mp4

maxRow:3 for full grid, even if float=true

20210215_103416.mp4

adumesny added a commit to adumesny/gridstack.js that referenced this pull request Feb 20, 2021
more fix for gridstack#1094 (part II of gridstack#1621)
* we now check for >50% coverage (using pixel drag vs target region) before
we collide during a drag to replace
* this means we now support larger size swapping at their mid point.
target is always used for mid point.

Note: web demo (gridstack#1094) is still not totally ideal as item 9 goes side way for some reason...
@harrington101
Copy link

Is there a workaround for the float true case? I do not have a max rows and would like to drag row 3 to 4 and have them swap. Instead, 4 is pushed down and an empty space is left where 3 was.

@adumesny
Copy link
Member Author

@harrington101 that is not the design, so no 'workaround'. if you don't want empty spaces, that is what float:true is for (no empty vertical spaces). If you want some hybrid, you can write your own collision with 5.x letting you specify you own engine...

@harrington101
Copy link

I'm not looking for a hybrid. Instead, I'm looking to have box 1 swap with box 2 rather than running away from it. I do want empty spaces which is why I set float to true. The issue is that box 2 moves unexpectedly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot move widget horizontally (Allow horizontal swapping without creating new rows)
2 participants