From 395f8953e34974fa09abe36f6f3f96c61c04c514 Mon Sep 17 00:00:00 2001 From: Drew Weymouth Date: Wed, 4 Jan 2023 11:39:20 -0800 Subject: [PATCH] fix hyperlink truncating at fixed width --- ui/widgets/customhyperlink.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/ui/widgets/customhyperlink.go b/ui/widgets/customhyperlink.go index 99367fe..193989b 100644 --- a/ui/widgets/customhyperlink.go +++ b/ui/widgets/customhyperlink.go @@ -12,14 +12,13 @@ type hyperlinkWrapper struct { h *widget.Hyperlink l *widget.Label - maxWidth float32 + MaxWidth float32 } -func newHyperlinkWrapper(maxWidth float32) *hyperlinkWrapper { +func newHyperlinkWrapper() *hyperlinkWrapper { h := &hyperlinkWrapper{ - h: widget.NewHyperlink("", nil), - l: widget.NewLabel(""), - maxWidth: maxWidth, + h: widget.NewHyperlink("", nil), + l: widget.NewLabel(""), } h.h.Wrapping = fyne.TextTruncate h.ExtendBaseWidget(h) @@ -27,7 +26,7 @@ func newHyperlinkWrapper(maxWidth float32) *hyperlinkWrapper { } 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) } @@ -52,7 +51,7 @@ type CustomHyperlink struct { func NewCustomHyperlink() *CustomHyperlink { c := &CustomHyperlink{ - h: newHyperlinkWrapper(200), + h: newHyperlinkWrapper(), } c.h.h.OnTapped = func() { if c.OnTapped != nil { @@ -71,6 +70,11 @@ func (c *CustomHyperlink) SetText(text string) { c.Refresh() } +func (c *CustomHyperlink) Resize(size fyne.Size) { + c.h.MaxWidth = size.Width + c.BaseWidget.Resize(size) +} + func (c *CustomHyperlink) Refresh() { c.container.Refresh() }