Skip to content
This repository has been archived by the owner on Nov 5, 2022. It is now read-only.

TextBox and/or CodeEditor Multi-Directional Scrolling #170

Closed
nelsam opened this issue Apr 25, 2016 · 6 comments
Closed

TextBox and/or CodeEditor Multi-Directional Scrolling #170

nelsam opened this issue Apr 25, 2016 · 6 comments

Comments

@nelsam
Copy link

nelsam commented Apr 25, 2016

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.

@ben-clayton
Copy link
Contributor

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.

@nelsam
Copy link
Author

nelsam commented May 1, 2016

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.

@nelsam nelsam closed this as completed May 1, 2016
@nelsam
Copy link
Author

nelsam commented May 1, 2016

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.

@dmitshur
Copy link
Member

dmitshur commented May 1, 2016

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).

@ben-clayton
Copy link
Contributor

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.

@nelsam
Copy link
Author

nelsam commented May 1, 2016

@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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants