Skip to content
This repository has been archived by the owner on Dec 22, 2023. It is now read-only.

Experiment: Let wx.ScrolledView handle scrolling to enable horizontal scrolling #72

Closed
wants to merge 3 commits into from

Conversation

janopae
Copy link

@janopae janopae commented Apr 7, 2023

In order to enable zooming (#20), we need to implement horizontal scrolling first.

Currently, scrolling is implemented by saving the first line to be displayed (called topLine) on the Screenplay object. The rendering code always renders the page beginning with that line until the screen is filled. So you just need to change the current topLine to make the page scroll. This is what all scrolling-related code does currently.

Opposed to that, the wx.ScrolledWindow knows the size of its child and its own size and implements scrolling automatically based on that. It saves the current scroll position internally (based on pixels). This allows it to reuse a lot of the implementation from the native toolkits (e. g. Gtk), which gives us goodies as:

  • horizontal scrolling: if the window is to narrow (or the screenplay is too wide), it will scroll horizontally
  • the scroll bar will be shown and hidden automatically depending on whether you're able to scroll (in the current implementation, you can always scroll, even if it's of no use as the whole document fits on the screen)
  • "precise scrolling" on Gtk: Have you ever noticed that when holding down a Gtk scroll bar, it scrolls slower and more precisely? This would have never been possible with the previous line-based scrolling, using wx.ScrolledView, we get it for free
  • Smoother scrolling: in the current implementation, Trelby can only scroll in line steps, which doesn't look so smooth. wx.ScrolledView scrolls in pixel steps which looks a bit smoother
  • Inertial scrolling on Gtk: On Gtk, we even get inertial scrolling for free
  • Touch screen scrolling on Gtk: On Gtk, we also get touch screen scrolling for free
  • Visualisation if the page continues on Gtk: On Gtk, we get shadows that indicate that the page is still scrollable in a certain direction (that disappear when the end is reached)

Unsolved problems

Trelby's implementation relies heavily on the current line-based scrolling. Unsolved problems include (and might not be limited to):

  • The rendering code of all view modes need to be adjusted to support this (I only adjusted the "Draft" view mode in this PR)
  • The "makeLineVisible" code (that automatically scrolls to make a certain line visible, imagine you scrolled away from the current text cursor position and start typing again) needs to be adjusted (I fiddled around with this in this PR, but it's certainly not ready)
  • Instead of only rendering the visible parts of the document, we now render the whole document, keep it in memory and scroll in it. I haven't done benchmarks on this, but this certainly takes more memory on large documents.
  • Probably there is more lacking that I don't see yet

Because of these reasons, I'm not sure if I will ever finish this. But I wanted to share this anyway.

@janopae janopae mentioned this pull request Apr 7, 2023
By putting the Control into a ScrolledWindow, we get scroll bars whenever the Control's container is smaller than its minimum size.

Vertical scrolling of the ScrolledWindow currently is deactivated, as we still have our custom implementation for vertical scrolling.

This, however, raises some issues: At first, the vertical scroll bar gets scrolled away along with the Screenplay Control while scrolling horizontally, as it is part of the contents of the ScrolledWindow.

Also, the hand-made scrollbar lacks some features, such as auto-hiding or the "precise scrolling mode" on Gtk.

Eventually, the custom scrolling implementation is probably going to get in our way when implementing  limburgher#20 anyway, so we should try to port vertical scrolling to the ScrolledWindow scrolling mechanism.
This makes our panel render the full document (rather than just the part which is currently visible due to the scroll position), and then let wx.ScrollView scroll through that fully-rendered view.

This is still incomplete, as it lacks
- porting the remaining scrolling functionality from our panel to wx.ScrolledView (e. g. `makeLineVisible`, which should automatically scroll to the current line)
- port all views over to render the full document rather than only the currently visible parts, and provide information about size and line height

It also has the draw-back that it always renders the full document, which might lead to performance problems with really large documents and/or older computers (not tested yet and no issues know, but theoretically, it increases the use of resources).
@limburgher
Copy link
Owner

Please close this PR and reopen again https://github.com/trelby/trelby, as the project is merging into that project. Thank you!

@limburgher limburgher closed this Dec 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants