Return-To-The-Roots / s25client

Return To The Roots (Settlers II(R) Clone)
http://www.rttr.info
GNU General Public License v2.0
477 stars 75 forks source link

Implement window snapping #1616

Closed falbrechtskirchinger closed 1 year ago

falbrechtskirchinger commented 1 year ago

Make windows align along edges within a certain snap distance.

Fixes #574

To-do:

falbrechtskirchinger commented 1 year ago
falbrechtskirchinger commented 1 year ago

Looks good so far, it's just a bit hard to understand/follow the code. Likely due to how this evolved.

Indeed, I started naming the variables before I knew the specifics of the calculations ahead.

falbrechtskirchinger commented 1 year ago

I still don't understand why we have minDist/minOffset and curMinDist/curMinOffset

I see. Since the lambdas are now called conditionally, there's no need to track distance and offset in temporaries. Additionally, with minDist not being updated the behavior was not as intended.

I've added a unit test to ensure we snap to the closest window.

falbrechtskirchinger commented 1 year ago

introduce a new type alias for the return value

Since I need this in WindowManager.h and IngameWindow.h, where would you prefer I add this alias?

falbrechtskirchinger commented 1 year ago

I've modified your comment suggestions a bit further. See if that's OK.

Edit: Noticed I missed using SnapOffset in the WindowManager unit test. Edit 2: Same in IngameWindow::MouseLeftDown().

falbrechtskirchinger commented 1 year ago

@Flamefire When I force-push the rebased version, there's no way for you to get a diff without the changes that have already been merged to master, right? I.e., both clicking the "Compare" link as well as " Show changes since your last review" in the "Files changed" tab show a diff cluttered with stuff that's already been reviewed.

Would it be easier if you used "Update branch" to merge master yourself and I force-push my changes over that? Then "Compare" should only show my changes made during the rebase (that'd just be the rename SnapWindow() -> snapWindow()).

Flamefire commented 1 year ago

Would it be easier if you used "Update branch" to merge master yourself and I force-push my changes over that? Then "Compare" should only show my changes made during the rebase (that'd just be the rename SnapWindow() -> snapWindow()).

Good idea!

falbrechtskirchinger commented 1 year ago

Would it be easier if you used "Update branch" to merge master yourself and I force-push my changes over that? Then "Compare" should only show my changes made during the rebase (that'd just be the rename SnapWindow() -> snapWindow()).

Good idea!

Done.