Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes and improvements relating to scrolling #1902

Merged
merged 3 commits into from
Mar 1, 2023

Conversation

davep
Copy link
Contributor

@davep davep commented Feb 28, 2023

The changes here roll two issues into one change. With this PR:


A question remains about if we should apply the changes here to scroll_to_widget too, but it's a wee bit involved so we're going to backlog that and review that later (note that scroll_visible is a common way into scroll_to_widget and it has always done a call after refresh anyway).

The changes here roll two issues into one change. With this commit:

- Scrolling up/down/etc using the keyboard now moves just one cell, rather
  than moving the number of cells specified by the scroll sensitivity that's
  intended for pointing devices. Textualize#1897
- Where appropriate the scrolling is done lazily; that is it is done after
  the next refresh, helping to ensure that the scroll will take into account
  any updates in the same parent call. Textualize#1774
@davep davep added bug Something isn't working enhancement New feature or request Task labels Feb 28, 2023
Nuked and recloned my repo earlier and forgot to set up pre-commit again.
Copy link
Contributor

@rodrigogiraoserrao rodrigogiraoserrao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docstrings just need a little bit of trimming! Otherwise, good to go :)

Comment on lines +1510 to +1517
x: X coordinate (column) to scroll to, or None for no change. Defaults to None.
y: Y coordinate (row) to scroll to, or None for no change. Defaults to None.
animate: Animate to new scroll position. Defaults to True.
speed: Speed of scroll if animate is True. Or None to use duration.
duration: Duration of animation, if animate is True and speed is None.
easing: An easing method for the scrolling animation. Defaults to "None",
which will result in Textual choosing the default scrolling easing function.
force: Force scrolling even when prohibited by overflow styling. Defaults to `False`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove all the defaults from the docstring :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see this was likely a copy & paste from other methods, like scroll_relative.
If you want, you can also delete the defaults from there 😆

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make this a followup "clean widget.py docs" PR in that case (although I do tend to like to see something in the docstring that makes it clear it's optional and what the default may be and why).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. Explaining what the default does or why it is a specific value makes more sense than just writing "Defaults to x".
I don't like "Defaults to x" because it ages badly: in a couple of iterations it will become a lie and it is easy to forget updating that.

A more complete sentence saying something like "Defaults to None, which will result in Textual [...]" is more sensible but it can also be rewritten in a way that doesn't even specify the default, e.g., "An easing method for the scrolling animation to replace the one Textual chooses by default".

What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But given the follow-up issue, I think this can be merged.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think?

I think if we explain that something is optional, but don't say what the default is and means, that makes more work for the reader. So "An easing method for the scrolling animation to replace the one Textual chooses by default" means either a) we've got to somehow link to somewhere that says what that default is (and so the reader ends up being taken out of their current context and then has to remember they need to go back rather than disappear down a documentation rabbit hole) or b) the reader has to make a note to go find how and where that default behaviour is documented.

I'm totally on board with the whole thing of not repeating facts of the code in the docs, for fear if it going stale, but I do worry that we end up leaving the docs lacking in useful information.

(and now I've seen I've written a fair bit here perhaps this is a consideration for us to spin out into its own issue)

Comment on lines +1650 to +1655
animate: Animate scroll. Defaults to True.
speed: Speed of scroll if animate is True. Or None to use duration.
duration: Duration of animation, if animate is True and speed is None.
easing: An easing method for the scrolling animation. Defaults to "None",
which will result in Textual choosing the configured default scrolling easing function.
force: Force scrolling even when prohibited by overflow styling. Defaults to `False`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove defaults.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto followup widget.py docstring cleanup.

Comment on lines +1713 to +1718
animate: Animate scroll. Defaults to True.
speed: Speed of scroll if animate is True. Or None to use duration.
duration: Duration of animation, if animate is True and speed is None.
easing: An easing method for the scrolling animation. Defaults to "None",
which will result in Textual choosing the configured default scrolling easing function.
force: Force scrolling even when prohibited by overflow styling. Defaults to `False`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😁

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto followup widget.py docstring cleanup.

Comment on lines +1776 to +1781
animate: Animate scroll. Defaults to True.
speed: Speed of scroll if animate is True. Or None to use duration.
duration: Duration of animation, if animate is True and speed is None.
easing: An easing method for the scrolling animation. Defaults to "None",
which will result in Textual choosing the configured default scrolling easing function.
force: Force scrolling even when prohibited by overflow styling. Defaults to `False`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😬

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto followup widget.py docstring cleanup.

Comment on lines +1839 to +1844
animate: Animate scroll. Defaults to True.
speed: Speed of scroll if animate is True. Or None to use duration.
duration: Duration of animation, if animate is True and speed is None.
easing: An easing method for the scrolling animation. Defaults to "None",
which will result in Textual choosing the configured default scrolling easing function.
force: Force scrolling even when prohibited by overflow styling. Defaults to `False`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧐

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto followup widget.py docstring cleanup.

Copy link
Collaborator

@willmcgugan willmcgugan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one request

src/textual/widget.py Outdated Show resolved Hide resolved
@davep davep merged commit b4da48a into Textualize:main Mar 1, 2023
@davep davep deleted the lazy-scrolling branch March 1, 2023 11:13
@davep
Copy link
Contributor Author

davep commented Mar 1, 2023

PS: Currently working on #1811 so will roll the scroll_* docstring trimming into that.

This was referenced Mar 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request Task
Projects
None yet
3 participants