make hyperlinks keyboard navigable with space bar
This commit is contained in:
@@ -8,35 +8,40 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type hyperlinkWrapper struct {
|
type hyperlinkWrapper struct {
|
||||||
widget.BaseWidget
|
widget.Hyperlink
|
||||||
|
|
||||||
h *widget.Hyperlink
|
|
||||||
l *widget.Label
|
l *widget.Label
|
||||||
MaxWidth float32
|
MaxWidth float32
|
||||||
}
|
}
|
||||||
|
|
||||||
func newHyperlinkWrapper() *hyperlinkWrapper {
|
func newHyperlinkWrapper() *hyperlinkWrapper {
|
||||||
h := &hyperlinkWrapper{
|
h := &hyperlinkWrapper{
|
||||||
h: widget.NewHyperlink("", nil),
|
Hyperlink: widget.Hyperlink{
|
||||||
|
Text: "",
|
||||||
|
Wrapping: fyne.TextTruncate,
|
||||||
|
},
|
||||||
l: widget.NewLabel(""),
|
l: widget.NewLabel(""),
|
||||||
}
|
}
|
||||||
h.h.Wrapping = fyne.TextTruncate
|
|
||||||
h.ExtendBaseWidget(h)
|
h.ExtendBaseWidget(h)
|
||||||
return h
|
return h
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *hyperlinkWrapper) MinSize() fyne.Size {
|
func (h *hyperlinkWrapper) MinSize() fyne.Size {
|
||||||
w := fyne.Min(h.MaxWidth, h.l.MinSize().Width)
|
w := fyne.Min(h.MaxWidth, h.l.MinSize().Width)
|
||||||
return fyne.NewSize(w, h.h.MinSize().Height)
|
return fyne.NewSize(w, h.Hyperlink.MinSize().Height)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *hyperlinkWrapper) SetText(text string) {
|
func (h *hyperlinkWrapper) SetText(text string) {
|
||||||
h.h.SetText(text)
|
h.Text = text
|
||||||
h.l.SetText(text)
|
h.l.SetText(text)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *hyperlinkWrapper) CreateRenderer() fyne.WidgetRenderer {
|
func (h *hyperlinkWrapper) TypedKey(e *fyne.KeyEvent) {
|
||||||
return widget.NewSimpleRenderer(h.h)
|
if e.Name == fyne.KeySpace {
|
||||||
|
if h.OnTapped != nil {
|
||||||
|
h.OnTapped()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type CustomHyperlink struct {
|
type CustomHyperlink struct {
|
||||||
@@ -53,7 +58,7 @@ func NewCustomHyperlink() *CustomHyperlink {
|
|||||||
c := &CustomHyperlink{
|
c := &CustomHyperlink{
|
||||||
h: newHyperlinkWrapper(),
|
h: newHyperlinkWrapper(),
|
||||||
}
|
}
|
||||||
c.h.h.OnTapped = func() {
|
c.h.OnTapped = func() {
|
||||||
if c.OnTapped != nil {
|
if c.OnTapped != nil {
|
||||||
c.OnTapped()
|
c.OnTapped()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user