fyne-io / fyne

Cross platform GUI toolkit in Go inspired by Material Design
https://fyne.io/
Other
24.59k stars 1.37k forks source link

RichText Hyperlink segments do not wrap #3393

Open Elara6331 opened 1 year ago

Elara6331 commented 1 year ago

Checklist

Describe the bug

When using a hyperlink segment in RichText, it does not wrap the text, despite TextWrapWord being set. Normal text does wrap.

How to reproduce

  1. Create a RichText widget with a hyperlink long enough that it should get wrapped.
  2. The hyperlink does not get wrapped.

Screenshots

With hyperlink:

image

Without hyperlink:

image

Example code

package main

import (
    "fyne.io/fyne/v2"
    "fyne.io/fyne/v2/app"
    "fyne.io/fyne/v2/widget"
)

func main() {
    a := app.New()
    w := a.NewWindow("test")

    rt := widget.NewRichTextFromMarkdown(`Lorem [ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore](https://example.com) et dolore magna aliqua. Porttitor leo a diam sollicitudin tempor. Nunc faucibus a pellentesque sit amet porttitor eget.`)
    rt.Wrapping = fyne.TextWrapWord

    w.SetContent(rt)
    w.ShowAndRun()
}

Fyne version

2.2.4

Go compiler version

1.19.3

Operating system

Linux

Operating system version

Arch Linux

Additional Information

No response

d4x1 commented 1 year ago

I run this code and it can be reproduced. I think it may be caused by lineBounds in richtext.

@andydotxyz Do you have any design doc for richtext? It will be easier to fix it if there are more details.

andydotxyz commented 1 year ago

@andydotxyz Do you have any design doc for richtext? It will be easier to fix it if there are more details.

The high level proposal is at https://github.com/fyne-io/proposals/blob/main/richtext.md.

The problem is fairly complex, because we're not just adding wrap to hyperlink, but asking it to wrap with an initial offset as well (when the hyperlink wraps on a line it was not the first item of). There are some if _, ok; obj.(*canvas.Text); ok in the rich text code as we assumed only text would wrap. Potentially we need to split hyperlink into two different objects when rendering to simulate the wrap?

d4x1 commented 1 year ago

@andydotxyz Do you have any design doc for richtext? It will be easier to fix it if there are more details.

The high level proposal is at https://github.com/fyne-io/proposals/blob/main/richtext.md.

The problem is fairly complex, because we're not just adding wrap to hyperlink, but asking it to wrap with an initial offset as well (when the hyperlink wraps on a line it was not the first item of). There are some if _, ok; obj.(*canvas.Text); ok in the rich text code as we assumed only text would wrap. Potentially we need to split hyperlink into two different objects when rendering to simulate the wrap?

Agreed. Splitting hyperlink into some objects is a practical way, another problem is when the mouse cursor is hovering it, these split objects should share the same an underline.
In short, implementing a rich text it is really very trivial.

ablegao commented 1 year ago

Is there a good solution available at the moment?

andydotxyz commented 1 year ago

This is an open bug, until it is fixed there isn't a fix. You could use shorter text in your hyperlinks I guess?

ablegao commented 1 year ago

I'm developing an epub reader and some of the books have a problem with excessively long links.