Skip to content

Commit

Permalink
Move the scrollbar check/post into the widget base class
Browse files Browse the repository at this point in the history
  • Loading branch information
davep committed Mar 13, 2024
1 parent bae8eb8 commit b684ae5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 22 deletions.
24 changes: 2 additions & 22 deletions src/textual/screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -762,26 +762,6 @@ def _refresh_layout(
self._update_timer.pause()
ResizeEvent = events.Resize

def _message_visibility(
widget: Widget, event: events.Show | events.Hide
) -> None:
"""Send a Show or Hide event to the given widget.
Args:
widget: The widget to send the event to.
event: The event to be sent.
Note:
This function ensures that any scrollbars attached to the
widget also get the messages; these are needed to help
update the grabbed status.
"""
widget.post_message(event)
if widget.show_vertical_scrollbar:
widget.vertical_scrollbar.post_message(event)
if widget.show_horizontal_scrollbar:
widget.horizontal_scrollbar.post_message(event)

try:
if scroll:
exposed_widgets = self._compositor.reflow_visible(self, size)
Expand Down Expand Up @@ -812,7 +792,7 @@ def _message_visibility(
Show = events.Show

for widget in hidden:
_message_visibility(widget, Hide())
widget.post_message(Hide())

# We want to send a resize event to widgets that were just added or change since last layout
send_resize = shown | resized
Expand All @@ -834,7 +814,7 @@ def _message_visibility(
)

for widget in shown:
_message_visibility(widget, Show())
widget.post_message(Show())

except Exception as error:
self.app._handle_exception(error)
Expand Down
10 changes: 10 additions & 0 deletions src/textual/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -3706,7 +3706,17 @@ def _on_scroll_right(self, event: ScrollRight) -> None:
self.scroll_page_right()
event.stop()

def _on_show(self, event: events.Show) -> None:
if self.show_horizontal_scrollbar:
self.horizontal_scrollbar.post_message(event)
if self.show_vertical_scrollbar:
self.vertical_scrollbar.post_message(event)

def _on_hide(self, event: events.Hide) -> None:
if self.show_horizontal_scrollbar:
self.horizontal_scrollbar.post_message(event)
if self.show_vertical_scrollbar:
self.vertical_scrollbar.post_message(event)
if self.has_focus:
self.blur()

Expand Down

0 comments on commit b684ae5

Please sign in to comment.