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
|
||||
|
Reference in New Issue
Block a user