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