Make cStack page forward/backward a member function
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
#include "message.hpp"
|
||||
#include "pict.hpp"
|
||||
#include "scrollbar.hpp"
|
||||
#include "mathutil.hpp"
|
||||
#include <climits>
|
||||
|
||||
bool cStack::hasChild(std::string id) const {
|
||||
@@ -84,6 +85,17 @@ bool cStack::setPage(size_t n) {
|
||||
return !failed;
|
||||
}
|
||||
|
||||
void cStack::doSelectPage(int dir, bool loop) {
|
||||
curPage += dir;
|
||||
if(loop){
|
||||
if(curPage < 0) curPage += nPages;
|
||||
else if(curPage >= nPages) curPage -= nPages;
|
||||
}else{
|
||||
curPage = minmax(0, nPages - 1, curPage);
|
||||
}
|
||||
setPage(curPage);
|
||||
}
|
||||
|
||||
size_t cStack::getPage() const {
|
||||
return curPage;
|
||||
}
|
||||
|
@@ -57,6 +57,10 @@ public:
|
||||
/// @param The new page number
|
||||
/// @return false if the page could not be changed, usually due to a focus handler
|
||||
bool setPage(size_t n);
|
||||
/// Page forward or backward in the stack
|
||||
/// @param dir Usually -1 or 1
|
||||
/// @param loop Beyond the first and last page, loop to the other side
|
||||
void doSelectPage(int dir, bool loop = true);
|
||||
/// Get the current page the stack is displaying.
|
||||
/// @return The current page number
|
||||
size_t getPage() const;
|
||||
|
@@ -1645,11 +1645,7 @@ class cChooseScenario {
|
||||
|
||||
bool doSelectPage(int dir) {
|
||||
auto& stk = dynamic_cast<cStack&>(me["list"]);
|
||||
int curPage = stk.getPage(), nPages = stk.getPageCount();
|
||||
curPage += dir;
|
||||
if(curPage < 0) curPage += nPages;
|
||||
else if(curPage >= nPages) curPage -= nPages;
|
||||
stk.setPage(curPage);
|
||||
stk.doSelectPage(dir, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user