LinkLabel and LinkActivated
Lerking opened this issue · comments
Hi,
I'm quite new to walk, but am familiar with gtk, qt etc.
I'm struggling with the LinkLabel.LinkActivate function. I have searched the web for some examples on using it and I can only find the one from the lxn/walk/examples/linklabel.go which unfortunately only shows an example, using declarative programming.
What I'm trying to do, is to trigger a function, whenever a link is clicked. I used the same logic here, as I would in other gui frameworks.
This is the snippet of my setup function for the link labels.
func SetupLinkBox(parent *walk.Composite) {
//Creates a layout with 2 links at the top - What's new and Contacts
//and 2 links at the bottom - Create component and Send mail
linkbox, _ := walk.NewComposite(parent)
vbox := walk.NewVBoxLayout()
linkbox.SetLayout(vbox)
link_label, _ := walk.NewLinkLabel(linkbox)
link_label.SetText("What's new")
link_label.SetEnabled(true)
link_label.LinkActivated().Attach(func(link *walk.LinkLabelLink) {
log.Println("Link activated:", link.Id())
walk.MsgBox(nil, "What's new", "This is a test", walk.MsgBoxIconInformation)
})
link_label1, _ := walk.NewLinkLabel(linkbox)
link_label1.SetText("Contacts")
spc, _ := walk.NewVSpacer(linkbox)
spc.SetWidth(1)
link_label2, _ := walk.NewLinkLabel(linkbox)
link_label2.SetText("Create component")
link_label3, _ := walk.NewLinkLabel(linkbox)
link_label3.SetText("Send mail")
}
Everything works, all link labels are shown. However no matter how many times I click the 'What's new' link, the LinkActivated code never runs.
Can someone help point me in the right direction.
BR
Hi,
I managed to figure it out.
I had to include an actual link ref in the label text for it to work.
Here's my snippet which actually triggers the msgbox.
func SetupLinkBox(parent *walk.Composite) {
//Creates a layout with 2 links at the top - What's new and Contacts
//and 2 links at the bottom - Create component and Send mail
linkbox, _ := walk.NewComposite(parent)
vbox := walk.NewVBoxLayout()
linkbox.SetLayout(vbox)
link_label, _ := walk.NewLinkLabel(linkbox)
link_label.SetText(`<a id="Whatsnew" href="https://github.com/lxn/walk/issues/%22>What" target="_blank" rel="nofollow's new</a>`)
link_label.SetEnabled(true)
link_label.LinkActivated().Attach(func(link *walk.LinkLabelLink) {
log.Println("Link activated:", link.Id())
walk.MsgBox(nil, "What's new", "This is a test", walk.MsgBoxIconInformation)
})
link_label1, _ := walk.NewLinkLabel(linkbox)
link_label1.SetText("Contacts")
spc, _ := walk.NewVSpacer(linkbox)
spc.SetWidth(1)
link_label2, _ := walk.NewLinkLabel(linkbox)
link_label2.SetText("Create component")
link_label3, _ := walk.NewLinkLabel(linkbox)
link_label3.SetText("Send mail")
}
Maybe this is something others can use as well.