ikskuh / kristall

Graphical small-internet client for windows, linux, MacOS X and BSDs. Supports gemini, http, https, gopher, finger.
https://kristall.random-projects.net/
GNU General Public License v3.0
738 stars 42 forks source link

Ideas for better handling of long preformatted text lines #184

Open mikejzx opened 3 years ago

mikejzx commented 3 years ago

The problem

When viewing some pages (e.g gemini://random-projects.net/blog/2021-03-03-distributed-trust.gemini) the preformatted text can sometimes exceed the window/screen width and become unreadable:

image (That's an example of it exceeding window width, but it actually exceeds my screen's width too)

Of course, according to the spec, we aren't supposed to do any line wrapping or anything to preformatted text. Instead the spec encourages an alternative approach - scroll bars:

Graphical clients should use scrolling mechanisms to present preformatted text lines which are longer than the client viewport, in preference to wrapping.

Currently, horizontal scrollbars on the KristallTextBrowser widget are actually disabled (as of #153, see this which I forgot to mention in that PR's description). I chose to disable it because since the text-width stuff (#149) was introduced, if a horizontal scrollbar was visible it would allow a user to "scroll the left/right margins" of the document, which looked really strange and most people would consider it a bug.

I should add that since the text-width stuff was added (before scrollbar was disabled), a horizontal scrollbar would show if there was any preformatted text lines longer than the max text width. The below diagram demonstrates that:

image

In current kristall builds, a curious user will be able to realise that the horizontal scrollbar is in fact just "hidden", because it is actually still possible to scroll horizontally in pages with long preformatted lines, by selecting some text and moving the mouse to the left/right edge of the KristallTextBrowser widget (it demonstrates the "left/right margin scrolling" I discussed above)

Potential solutions

There are two potential ways I can think think of to solve this:

The lagrange method

Lagrange tries to solve this same problem by reducing the font size of long preformatted lines: image (note how the first preformatted text is normal size, and the long line is smaller)

The two problems with this method are obviously:

The other "embedded scrollbars" method

The other method which I think would be ideal is to create a seperate scrollbar for these long preformatted blocks, like demonstrated below (mocked up in GIMP, so it doesn't look super-pretty)

image

However, it might be really tricky to embed one of these into a QTextDocument. I have no idea if it's even possible.

Just some ideas to think about 😉

ikskuh commented 3 years ago

I would definitly prefer the second version, using embedded scroll bars for the text blocks. You can see that this looks pretty neat in the web version of random-projects.net.

I have no idea though how to display it properly. One option would be to write the rendering module for gemtext ourselfs (which i would rather not) or just split the "document view" into multiple QTextBrowser. This would break text selection though...