link controls auto-add click handler
This commit is contained in:
@@ -434,6 +434,16 @@ std::string cControl::parse(ticpp::Element& who, std::string fname) {
|
||||
frame.height() = height > 0 ? height : bestSz.y;
|
||||
setBounds(frame);
|
||||
validatePostParse(who, fname, foundAttrs, foundNodes);
|
||||
|
||||
// Wire links to function:
|
||||
// TODO links are identified only by having the color 'link', and can only link to their text value.
|
||||
if(is_link){
|
||||
attachClickHandler([](cDialog& self, std::string clicked, eKeyMod) {
|
||||
launchURL(self[clicked].getText());
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
@@ -540,6 +550,8 @@ bool cControl::parseAttribute(ticpp::Attribute& attr, std::string tagName, std::
|
||||
setColour({0x7f, 0xd7, 0xFF});
|
||||
if(parent->getBg() == cDialog::BG_LIGHT)
|
||||
setColour({0x00, 0x00, 0xFF});
|
||||
|
||||
is_link = true;
|
||||
} else try {
|
||||
sf::Color clr = parseColor(val);
|
||||
setColour(clr);
|
||||
|
@@ -32,6 +32,9 @@ namespace ticpp {
|
||||
class Node;
|
||||
}
|
||||
|
||||
// Hyperlink forward declaration
|
||||
void launchURL(std::string url);
|
||||
|
||||
/// Formatting properties
|
||||
enum eFormat {
|
||||
TXT_FRAME, ///< The control's frame style. Should be an enum from @ref eFrameStyle.
|
||||
@@ -462,6 +465,7 @@ private:
|
||||
// Transient values only used during parsing
|
||||
ePosition horz = POS_ABS, vert = POS_ABS;
|
||||
std::string anchor;
|
||||
bool is_link = false;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@@ -246,17 +246,7 @@ void show_dialog_action(std::string xml_file) {
|
||||
record_action("show_dialog_action", xml_file);
|
||||
}
|
||||
|
||||
cChoiceDlog dlog(xml_file);
|
||||
|
||||
// Dialogs with hyperlinks need special handling:
|
||||
if(xml_file == "about-boe"){
|
||||
dlog->attachClickHandlers([](cDialog& self, std::string clicked, eKeyMod) {
|
||||
launchURL(self[clicked].getText());
|
||||
return false;
|
||||
}, {"src", "issues"});
|
||||
}
|
||||
|
||||
dlog.show();
|
||||
cChoiceDlog(xml_file).show();
|
||||
}
|
||||
|
||||
bool prime_time() {
|
||||
|
@@ -689,15 +689,7 @@ void init_boe(int argc, char* argv[]) {
|
||||
}
|
||||
|
||||
void showWelcome() {
|
||||
if(recording){
|
||||
record_action("showWelcome", "");
|
||||
}
|
||||
cChoiceDlog welcome("welcome");
|
||||
welcome->attachClickHandlers([](cDialog& self, std::string clicked, eKeyMod) {
|
||||
launchURL(self[clicked].getText());
|
||||
return false;
|
||||
}, {"spidweb", "scen", "forum", "home", "src"});
|
||||
welcome.show();
|
||||
show_dialog_action("welcome");
|
||||
}
|
||||
|
||||
using Key = sf::Keyboard::Key;
|
||||
|
Reference in New Issue
Block a user