Skip to content

Commit

Permalink
feat(ui): Shop keyboard navigation remembers selected column when mov…
Browse files Browse the repository at this point in the history
…ing between differently sized rows (endless-sky#9617)
  • Loading branch information
Koranir authored Dec 23, 2023
1 parent 849f56d commit 221794b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 9 additions & 2 deletions source/ShopPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,8 @@ bool ShopPanel::Click(int x, int y, int /* clicks */)
else
selectedOutfit = zone.GetOutfit();

previousX = zone.Center().X();

return true;
}

Expand Down Expand Up @@ -628,6 +630,9 @@ void ShopPanel::DoFind(const string &text)
selectedShip = best->GetShip();
else
selectedOutfit = best->GetOutfit();

previousX = best->Center().X();

MainAutoScroll(best);
}
}
Expand Down Expand Up @@ -1212,6 +1217,8 @@ void ShopPanel::MainLeft()
MainAutoScroll(it);
}

previousX = it->Center().X();

selectedShip = it->GetShip();
selectedOutfit = it->GetOutfit();
}
Expand All @@ -1234,6 +1241,8 @@ void ShopPanel::MainRight()
else
MainAutoScroll(it);

previousX = it->Center().X();

selectedShip = it->GetShip();
selectedOutfit = it->GetOutfit();
}
Expand All @@ -1250,7 +1259,6 @@ void ShopPanel::MainUp()
if(it == zones.end())
it = zones.begin();

const double previousX = it->Center().X();
const double previousY = it->Center().Y();
while(it != zones.begin() && it->Center().Y() == previousY)
--it;
Expand Down Expand Up @@ -1289,7 +1297,6 @@ void ShopPanel::MainDown()
return;
}

const double previousX = it->Center().X();
const double previousY = it->Center().Y();
++it;
while(it != zones.end() && it->Center().Y() == previousY)
Expand Down
2 changes: 2 additions & 0 deletions source/ShopPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ class ShopPanel : public Panel {
ShopPane activePane = ShopPane::Main;
char hoverButton = '\0';

double previousX = 0.;

std::vector<Zone> zones;
std::vector<ClickZone<const Ship *>> shipZones;
std::vector<ClickZone<std::string>> categoryZones;
Expand Down

0 comments on commit 221794b

Please sign in to comment.