Convert five more dialogs and fix the string choice dialog

(The latter was always returning 0)
This commit is contained in:
2014-12-02 03:05:08 -05:00
parent d64770b1e0
commit d61c0a5c1e
8 changed files with 450 additions and 272 deletions

View File

@@ -11,6 +11,7 @@
#include <algorithm>
#include <functional>
#include <boost/lexical_cast.hpp>
#include "dialog.h"
#include "dlogutil.h"
#include "mathutil.h"
@@ -131,11 +132,7 @@ cStringChoice::cStringChoice(
std::string title,
cDialog* parent
) : dlg("choose-string.xml",parent) {
using namespace std::placeholders;
dlg["left"].attachClickHandler(std::bind(&cStringChoice::onLeft,this,_1,_2));
dlg["right"].attachClickHandler(std::bind(&cStringChoice::onRight,this,_1,_2));
dlg["done"].attachClickHandler(std::bind(&cStringChoice::onOkay,this,_1,_2));
dlg["cancel"].attachClickHandler(std::bind(&cStringChoice::onCancel,this,_1,_2));
attachHandlers();
if(!title.empty()) dlg["title"].setText(title);
strings = strs;
}
@@ -146,13 +143,19 @@ cStringChoice::cStringChoice(
std::string title,
cDialog* parent
) : dlg("choose-string.xml",parent) {
attachHandlers();
if(!title.empty()) dlg["title"].setText(title);
copy(begin,end,std::inserter(strings, strings.begin()));
}
void cStringChoice::attachHandlers() {
using namespace std::placeholders;
dlg["left"].attachClickHandler(std::bind(&cStringChoice::onLeft,this,_1,_2));
dlg["right"].attachClickHandler(std::bind(&cStringChoice::onRight,this,_1,_2));
dlg["done"].attachClickHandler(std::bind(&cStringChoice::onOkay,this,_1,_2));
dlg["cancel"].attachClickHandler(std::bind(&cStringChoice::onCancel,this,_1,_2));
if(!title.empty()) dlg["title"].setText(title);
copy(begin,end,std::inserter(strings, strings.begin()));
leds = &dynamic_cast<cLedGroup&>(dlg["strings"]);
leds->attachFocusHandler(std::bind(&cStringChoice::onSelect,this,_1,_3));
}
size_t cStringChoice::show(std::string select){
@@ -215,6 +218,13 @@ bool cStringChoice::onOkay(cDialog& me, std::string id __attribute__((unused))){
return true;
}
bool cStringChoice::onSelect(cDialog& me, bool losing) {
if(losing) return true;
int i = boost::lexical_cast<int>(leds->getSelected().substr(3));
cur = page * 40 + i - 1;
return true;
}
cChoiceDlog::cChoiceDlog(std::string file, std::vector<std::string> buttons, cDialog* p) : dlg(file, p) {
using namespace std::placeholders;
std::vector<std::string>::iterator iter = buttons.begin();

View File

@@ -86,9 +86,12 @@ class cStringChoice {
bool onRight(cDialog& me, std::string id);
bool onCancel(cDialog& me, std::string id);
bool onOkay(cDialog& me, std::string id);
bool onSelect(cDialog& me, bool losing);
void attachHandlers();
void fillPage();
std::vector<std::string> strings;
size_t page, cur;
cLedGroup* leds;
public:
explicit cStringChoice(std::vector<std::string>& strs, std::string title, cDialog* parent = NULL);
cStringChoice(std::vector<std::string>::iterator begin, std::vector<std::string>::iterator end, std::string title, cDialog* parent = NULL);