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

Added scroll_to_widget #483

Merged
merged 11 commits into from
May 10, 2022
Merged

Added scroll_to_widget #483

merged 11 commits into from
May 10, 2022

Conversation

willmcgugan
Copy link
Collaborator

@willmcgugan willmcgugan commented May 6, 2022

  • Adds a scroll_to_widget method which scrolls a container to make a widget visible.
  • Renamed RenderRegion to MapGeometry which is more descriptive.
  • Added a few properties on Region class

@willmcgugan willmcgugan marked this pull request as draft May 6, 2022 15:13
@@ -52,17 +52,17 @@ class ReflowResult(NamedTuple):
resized: set[Widget] # Widgets that have been resized


class RenderRegion(NamedTuple):
class RegionGeometry(NamedTuple):
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

A better name...

@willmcgugan willmcgugan marked this pull request as ready for review May 9, 2022 07:50
Copy link

@olivierphi olivierphi left a comment

Choose a reason for hiding this comment

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

Awesome! 😊

Once the "integration test" foundation will be merged I guess we could add a test that starts an app with a series of Placeholders, calls this scroll_to_widget method, waits a bit, and then check that the content did scroll? 🙂

@willmcgugan
Copy link
Collaborator Author

Yeah, that would be great. Hard to unit test some of that logic.

src/textual/widget.py Outdated Show resolved Hide resolved
Co-authored-by: Darren Burns <[email protected]>
return self.scroll_to(
x=self.scroll_target_x + self.container_size.width, animate=animate
)

def scroll_to_widget(self, widget: Widget, *, animate: bool = True) -> bool:
Copy link
Member

Choose a reason for hiding this comment

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

If a widget is taller than the container, and you scroll up to it, it scrolls such that the bottom of the widget aligns with the bottom of the container (and the top of the widget is out of view). I suspect we want the top of the widget to be in view.

Copy link
Member

@darrenburns darrenburns 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 comment. Also noticed the scroll animation is a constant speed (it feels very slow as well), so if you wrap focus from the bottom to the top it's taking multiple seconds.

@willmcgugan
Copy link
Collaborator Author

Good point. It should be a fixed time.

@willmcgugan
Copy link
Collaborator Author

I've exposed duration on scroll. The scroll_to_widget will use a duration of 200ms.

@willmcgugan willmcgugan merged commit 6bfe065 into css May 10, 2022
@willmcgugan willmcgugan deleted the scroll_to_widget branch May 10, 2022 12:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants