google / gxui

An experimental Go cross platform UI library.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TextBox and/or CodeEditor Multi-Directional Scrolling

nelsam opened this issue · comments

I'm trying to figure out how I'd go about updating either the TextBox or CodeEditor type to support scrolling both horizontally and vertically. So far, I'm just planning to loosely base my solution on the implementation in mixins.List, but I thought I should request help here just in case there's a better way.

My current plan:

  1. Add a Horizontal scroll bar to the CodeEditor
  2. Allow the mixins.List orientation to remain vertical
  3. Add a concept of a horizontal offset to CodeEditorLine
  4. Add methods/events to the CodeEditor related to horizontal scrolling and have it update horizontal offsets for any visibile CodeEditorLine values

Does that seem sane? Tagging @ben-clayton in the hopes that he can find a few minutes to answer.

unlurks

Hello there,
That approach sounds like it could work. The tricky bit is knowing the widest line length - you'd have to calculate this for every line, when the whole implementation tries hard to work only with the lines that are on-screen.

Instead of plumbing in horizontal scrolling into the CodeEditor (I'd actually recommend working on the TextBox if you go that path), you could embed the text control in a ScrollLayout which creates a scrollable window on a larger child area. You'll still need to figure out the maximum line width, and have to use that size when calculating the desired TextBox size, but then the whole horizontal scrolling logic could be handled for you.

Feel free to ask more questions. My memory is a bit hazy, and responses may be slow, but I'd still like to help if I can.

Cheers.

Sounds good. I'm working at sticking the code editor in a ScrollLayout and just finding the longest line every edit, since that seems the simplest for the time being. If/when it ends up being too slow, I'll worry about a more sophisticated solution.

I gave the ScrollLayout a shot, but my CodeEditor was having real trouble displaying files over a few hundred lines when it had to render the entire file on every Paint call. I think I'd have to rely on the TextBox's vertical scrolling and turn off the vertical scroll on the ScrollLayout in order to make anything over a few hundred lines display correctly, and then the TextBox's scroll bar would be hidden from view unless you're scrolled all the way to the right. I even tried disabling the logic that checks line lengths, hoping that it was just my inefficient line parsing that was the issue ... but it had no noticeable effect.

I think I'll need to fall back to my previous plan, unless I want to spend ages optimizing my Paint calls.

Yeah, culling away (not rendering) lines that are not on screen is going to be extremely critical for performance when dealing with large files (e.g., a few thousand lines of text).

I gave the ScrollLayout a shot, but my CodeEditor was having real trouble displaying files over a few hundred lines when it had to render the entire file on every Paint call.

I think you misunderstood me. I was suggesting using ScrollLayout.SetScrollAxis so that you continue using TextBox's vertical scrolling for virtualization, and ScrollLayout's horizontal scrolling for what you're after.

@ben-clayton Err, right, I didn't mention things in chronological order, there. I gave that a shot, but with that solution, the TextBox's vertical scroll bar gets scrolled out of frame. So I tried making the ScrollLayout handle all the scrolling, and that's when I ran into performance issues.