Clicking a text field now selects it as if you had tabbed into it
This commit is contained in:
@@ -909,8 +909,10 @@ void cDialog::run(){
|
|||||||
std::string itemHit = "";
|
std::string itemHit = "";
|
||||||
dialogNotToast = true;
|
dialogNotToast = true;
|
||||||
// Focus the first text field, if there is one
|
// Focus the first text field, if there is one
|
||||||
if(!tabOrder.empty())
|
if(!tabOrder.empty()) {
|
||||||
tabOrder[0].second->triggerFocusHandler(*this, tabOrder[0].first, false);
|
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.create(sf::VideoMode(winRect.width(), winRect.height()), "Dialog", sf::Style::Titlebar);
|
||||||
win.setActive();
|
win.setActive();
|
||||||
win.setVisible(true);
|
win.setVisible(true);
|
||||||
@@ -1131,6 +1133,19 @@ bool cDialog::toast(bool triggerFocus){
|
|||||||
return true;
|
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) {
|
void cDialog::attachClickHandlers(click_callback_t handler, std::vector<std::string> controls) {
|
||||||
cDialog& me = *this;
|
cDialog& me = *this;
|
||||||
for(std::string control : controls) {
|
for(std::string control : controls) {
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ public:
|
|||||||
void setDefTextClr(sf::Color clr);
|
void setDefTextClr(sf::Color clr);
|
||||||
void setDefBtn(std::string defBtn);
|
void setDefBtn(std::string defBtn);
|
||||||
sf::Color getDefTextClr();
|
sf::Color getDefTextClr();
|
||||||
|
bool setFocus(cTextField* newFocus, bool force = false); // Setting force = true skips focus handlers
|
||||||
bool toast(bool triggerFocus);
|
bool toast(bool triggerFocus);
|
||||||
cControl& getControl(std::string id);
|
cControl& getControl(std::string id);
|
||||||
cControl& operator[](std::string id);
|
cControl& operator[](std::string id);
|
||||||
|
|||||||
@@ -29,6 +29,13 @@ bool cTextField::triggerFocusHandler(cDialog& me, std::string id, bool losingFoc
|
|||||||
return passed;
|
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){
|
void cTextField::setFormat(eFormat prop, short) throw(xUnsupportedProp){
|
||||||
throw xUnsupportedProp(prop);
|
throw xUnsupportedProp(prop);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ public:
|
|||||||
void attachClickHandler(click_callback_t f) throw(xHandlerNotSupported);
|
void attachClickHandler(click_callback_t f) throw(xHandlerNotSupported);
|
||||||
void attachFocusHandler(focus_callback_t f) throw();
|
void attachFocusHandler(focus_callback_t f) throw();
|
||||||
bool triggerFocusHandler(cDialog& me, std::string id, bool losingFocus);
|
bool triggerFocusHandler(cDialog& me, std::string id, bool losingFocus);
|
||||||
|
bool handleClick(location where);
|
||||||
void setFormat(eFormat prop, short val) throw(xUnsupportedProp);
|
void setFormat(eFormat prop, short val) throw(xUnsupportedProp);
|
||||||
short getFormat(eFormat prop) throw(xUnsupportedProp);
|
short getFormat(eFormat prop) throw(xUnsupportedProp);
|
||||||
void setColour(sf::Color clr) throw(xUnsupportedProp);
|
void setColour(sf::Color clr) throw(xUnsupportedProp);
|
||||||
|
|||||||
Reference in New Issue
Block a user