link controls auto-add click handler

This commit is contained in:
2024-11-19 15:06:43 -06:00
parent bf91f41675
commit cd6c0a0a30
4 changed files with 18 additions and 20 deletions

View File

@@ -434,6 +434,16 @@ std::string cControl::parse(ticpp::Element& who, std::string fname) {
frame.height() = height > 0 ? height : bestSz.y; frame.height() = height > 0 ? height : bestSz.y;
setBounds(frame); setBounds(frame);
validatePostParse(who, fname, foundAttrs, foundNodes); 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; return id;
} }
@@ -540,6 +550,8 @@ bool cControl::parseAttribute(ticpp::Attribute& attr, std::string tagName, std::
setColour({0x7f, 0xd7, 0xFF}); setColour({0x7f, 0xd7, 0xFF});
if(parent->getBg() == cDialog::BG_LIGHT) if(parent->getBg() == cDialog::BG_LIGHT)
setColour({0x00, 0x00, 0xFF}); setColour({0x00, 0x00, 0xFF});
is_link = true;
} else try { } else try {
sf::Color clr = parseColor(val); sf::Color clr = parseColor(val);
setColour(clr); setColour(clr);

View File

@@ -32,6 +32,9 @@ namespace ticpp {
class Node; class Node;
} }
// Hyperlink forward declaration
void launchURL(std::string url);
/// Formatting properties /// Formatting properties
enum eFormat { enum eFormat {
TXT_FRAME, ///< The control's frame style. Should be an enum from @ref eFrameStyle. 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 // Transient values only used during parsing
ePosition horz = POS_ABS, vert = POS_ABS; ePosition horz = POS_ABS, vert = POS_ABS;
std::string anchor; std::string anchor;
bool is_link = false;
}; };
#endif #endif

View File

@@ -246,17 +246,7 @@ void show_dialog_action(std::string xml_file) {
record_action("show_dialog_action", xml_file); record_action("show_dialog_action", xml_file);
} }
cChoiceDlog dlog(xml_file); cChoiceDlog(xml_file).show();
// 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();
} }
bool prime_time() { bool prime_time() {

View File

@@ -689,15 +689,7 @@ void init_boe(int argc, char* argv[]) {
} }
void showWelcome() { void showWelcome() {
if(recording){ show_dialog_action("welcome");
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();
} }
using Key = sf::Keyboard::Key; using Key = sf::Keyboard::Key;