-
Notifications
You must be signed in to change notification settings - Fork 814
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
Conversation
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
Nuked and recloned my repo earlier and forgot to set up pre-commit again.
There was a problem hiding this 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 :)
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`. |
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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 😆
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
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`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove defaults.
There was a problem hiding this comment.
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.
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`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😁
There was a problem hiding this comment.
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.
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`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😬
There was a problem hiding this comment.
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.
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`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧐
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one request
PS: Currently working on #1811 so will roll the |
The changes here roll two issues into one change. With this PR:
scroll_*
doesn't work immediately after loading aSyntax
into aStatic
#1774A 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 thatscroll_visible
is a common way intoscroll_to_widget
and it has always done a call after refresh anyway).