fixes for table scroll

This commit is contained in:
Will McGugan
2022-10-04 09:53:48 +01:00
parent 94ff417e1f
commit 38924b3143
5 changed files with 23 additions and 46 deletions

1
docs/widgets/input.md Normal file
View File

@@ -0,0 +1 @@
# Input

View File

@@ -1,11 +1,8 @@
from __future__ import annotations
from typing import Collection
from rich.console import RenderableType
from .geometry import Region, Size
from .geometry import Size
from .widget import Widget
@@ -17,19 +14,12 @@ class ScrollView(Widget):
"""
DEFAULT_CSS = """
ScrollView {
overflow-y: auto;
overflow-x: auto;
overflow-x: auto;
}
"""
def __init__(
self, name: str | None = None, id: str | None = None, classes: str | None = None
) -> None:
super().__init__(name=name, id=id, classes=classes)
@property
def is_scrollable(self) -> bool:
"""Always scrollable."""
@@ -68,25 +58,6 @@ class ScrollView(Widget):
"""
return self.virtual_size.height
def watch_virtual_size(self, virtual_size: Size) -> None:
self._scroll_update(virtual_size)
def watch_show_horizontal_scrollbar(self, value: bool) -> None:
"""Watch function for show_horizontal_scrollbar attribute.
Args:
value (bool): Show horizontal scrollbar flag.
"""
self.refresh(layout=True)
def watch_show_vertical_scrollbar(self, value: bool) -> None:
"""Watch function for show_vertical_scrollbar attribute.
Args:
value (bool): Show vertical scrollbar flag.
"""
self.refresh(layout=True)
def _size_updated(
self, size: Size, virtual_size: Size, container_size: Size
) -> None:
@@ -97,12 +68,16 @@ class ScrollView(Widget):
virtual_size (Size): New virtual size.
container_size (Size): New container size.
"""
if self._size != size or virtual_size != self.virtual_size:
if (
self._size != size
or virtual_size != self.virtual_size
or container_size != self.container_size
):
self._size = size
virtual_size = self.virtual_size
self._container_size = size - self.gutter.totals
self._scroll_update(virtual_size)
self.scroll_to(self.scroll_x, self.scroll_y)
self._container_size = size - self.gutter.totals
self.scroll_to(self.scroll_x, self.scroll_y, animate=False)
self.refresh()
def render(self) -> RenderableType:
@@ -114,13 +89,3 @@ class ScrollView(Widget):
from rich.panel import Panel
return Panel(f"{self.scroll_offset} {self.show_vertical_scrollbar}")
def watch_scroll_x(self, new_value: float) -> None:
"""Called when horizontal bar is scrolled."""
self.horizontal_scrollbar.position = int(new_value)
self.refresh(layout=False)
def watch_scroll_y(self, new_value: float) -> None:
"""Called when vertical bar is scrolled."""
self.vertical_scrollbar.position = int(new_value)
self.refresh(layout=False)

View File

@@ -271,6 +271,7 @@ class ScrollBar(Widget):
async def _on_mouse_up(self, event: events.MouseUp) -> None:
if self.grabbed:
self.release_mouse()
event.stop()
def _on_mouse_capture(self, event: events.MouseCapture) -> None:
self.grabbed = event.mouse_position
@@ -278,6 +279,7 @@ class ScrollBar(Widget):
def _on_mouse_release(self, event: events.MouseRelease) -> None:
self.grabbed = None
event.stop()
async def _on_mouse_move(self, event: events.MouseMove) -> None:
if self.grabbed and self.window_size:
@@ -300,6 +302,10 @@ class ScrollBar(Widget):
)
)
await self.emit(ScrollTo(self, x=x, y=y))
event.stop()
async def _on_click(self, event: events.Click) -> None:
event.stop()
class ScrollBarCorner(Widget):

View File

@@ -1666,7 +1666,11 @@ class Widget(DOMNode):
Returns:
Style: A rich Style object.
"""
offset_x, offset_y = self.screen.get_offset(self)
widget, region = self.screen.get_widget_at(x, y)
if widget is not self:
return Style()
offset_x, offset_y = region.offset
# offset_x, offset_y = self.screen.get_offset(self)
return self.screen.get_style_at(x + offset_x, y + offset_y)
async def _forward_event(self, event: events.Event) -> None:

View File

@@ -256,7 +256,7 @@ class DataTable(ScrollView, Generic[CellType], can_focus=True):
total_width = sum(column.width for column in self.columns)
self.virtual_size = Size(
total_width,
len(self._y_offsets) + (self.header_height if self.show_header else 0),
max(len(self._y_offsets), (self.header_height if self.show_header else 0)),
)
def _get_cell_region(self, row_index: int, column_index: int) -> Region:
@@ -557,6 +557,7 @@ class DataTable(ScrollView, Generic[CellType], can_focus=True):
if meta:
self.cursor_cell = Coord(meta["row"], meta["column"])
self._scroll_cursor_in_to_view()
event.stop()
def key_down(self, event: events.Key):
self.cursor_cell = self.cursor_cell.down()