google / gxui

An experimental Go cross platform UI library.
BSD 3-Clause "New" or "Revised" License
4.44k stars 298 forks source link

Textbox/CodeEditor don't display long lines #114

Open andrebq opened 9 years ago

andrebq commented 9 years ago

The current implementation of TextBox (and CodeEditor) don't display lines that are too long to fit into the textbox visible area.

The text is there and the caret moves to the end but you can't see it.

Apparently this could be solved by adjusting the painting routine to know about a horizontal scroll (not necessarly adding a horizontal scroll bar) and removing that position from the x-coordiante when rendring the glyphs textures.

I tried to search the code but didn't found anything to point me in the right direction.

ben-clayton commented 9 years ago

Hi @andrebq. You are correct - this is a missing feature of the textbox control. The difficulty here is that the textbox control is virtualized (only the visible lines are resident in memory) and in order to correctly implement horizontal scrolling we need to know the maximum width of all lines. However, this is just complexity and is certainly achievable. I'll have a think about solutions.

andrebq commented 9 years ago

@ben-clayton Since I had that problem with the Textbox and didn't understand the code enough to come up with a patch, I made a custom control that uses TextBoxTextController but re-implements all the rendering and key handling code.

To solve the scroll problem I made something like vim. For every Paint call I get: the position of the cursor; the size of the canvas; and a offset. Then I check if the cursor is visible in the canvas at the current offset. If not, the offset is adjusted to show the cursor.

Then for every line that I render, instead of using a rect starting at (0,0), I use a rect starting at (-offset.X, -offset.Y).

This would work with singe line textboxes (which shouldn't have a scrollbar) and possibly to multi-line textboxes (but without the offset.Y since they already have a vertical scrollbar).