Clicking a text field now selects it as if you had tabbed into it

This commit is contained in:
2014-12-04 14:17:20 -05:00
parent 04cba387d5
commit d45a7d1c1b
4 changed files with 25 additions and 1 deletions

View File

@@ -909,8 +909,10 @@ void cDialog::run(){
std::string itemHit = "";
dialogNotToast = true;
// Focus the first text field, if there is one
if(!tabOrder.empty())
if(!tabOrder.empty()) {
tabOrder[0].second->triggerFocusHandler(*this, tabOrder[0].first, false);
currentFocus = tabOrder[0].first;
}
win.create(sf::VideoMode(winRect.width(), winRect.height()), "Dialog", sf::Style::Titlebar);
win.setActive();
win.setVisible(true);
@@ -1131,6 +1133,19 @@ bool cDialog::toast(bool triggerFocus){
return true;
}
bool cDialog::setFocus(cTextField* newFocus, bool force) {
if(!force) {
if(!this->getControl(currentFocus).triggerFocusHandler(*this, currentFocus, true)) return false;
}
auto iter = find_if(controls.begin(), controls.end(), [newFocus](std::pair<const std::string, cControl*> p){
return p.second == newFocus;
});
if(iter == controls.end()) return false;
if(!force && !newFocus->triggerFocusHandler(*this, iter->first, false)) return false;
currentFocus = iter->first;
return true;
}
void cDialog::attachClickHandlers(click_callback_t handler, std::vector<std::string> controls) {
cDialog& me = *this;
for(std::string control : controls) {

View File

@@ -61,6 +61,7 @@ public:
void setDefTextClr(sf::Color clr);
void setDefBtn(std::string defBtn);
sf::Color getDefTextClr();
bool setFocus(cTextField* newFocus, bool force = false); // Setting force = true skips focus handlers
bool toast(bool triggerFocus);
cControl& getControl(std::string id);
cControl& operator[](std::string id);

View File

@@ -29,6 +29,13 @@ bool cTextField::triggerFocusHandler(cDialog& me, std::string id, bool losingFoc
return passed;
}
bool cTextField::handleClick(location) {
// TODO: Set the insertion point, handle selection, etc
if(parent && !parent->setFocus(this)) return true;
haveFocus = true;
return true;
}
void cTextField::setFormat(eFormat prop, short) throw(xUnsupportedProp){
throw xUnsupportedProp(prop);
}

View File

@@ -22,6 +22,7 @@ public:
void attachClickHandler(click_callback_t f) throw(xHandlerNotSupported);
void attachFocusHandler(focus_callback_t f) throw();
bool triggerFocusHandler(cDialog& me, std::string id, bool losingFocus);
bool handleClick(location where);
void setFormat(eFormat prop, short val) throw(xUnsupportedProp);
short getFormat(eFormat prop) throw(xUnsupportedProp);
void setColour(sf::Color clr) throw(xUnsupportedProp);