Merge pull request #726 from Textualize/scrollbar-overlap

scrollbar fix
This commit is contained in:
Will McGugan
2022-09-02 14:01:47 +01:00
committed by GitHub
4 changed files with 37 additions and 25 deletions

View File

@@ -8,5 +8,6 @@ Static {
background: blue 20%;
height: 100%;
margin: 2 4;
min-width: 30;
min-width: 80;
min-height: 40;
}

View File

@@ -87,15 +87,19 @@ class ScrollView(Widget):
width, height = self.container_size
if self.show_vertical_scrollbar:
self.vertical_scrollbar.window_virtual_size = virtual_size.height
self.vertical_scrollbar.window_size = height
self.vertical_scrollbar.window_size = (
height - self.scrollbar_size_horizontal
)
if self.show_horizontal_scrollbar:
self.horizontal_scrollbar.window_virtual_size = virtual_size.width
self.horizontal_scrollbar.window_size = width
self.horizontal_scrollbar.window_size = (
width - self.scrollbar_size_vertical
)
self.scroll_x = self.validate_scroll_x(self.scroll_x)
self.scroll_y = self.validate_scroll_y(self.scroll_y)
self.refresh(layout=False)
self.call_later(self.scroll_to, self.scroll_x, self.scroll_y)
self.scroll_to(self.scroll_x, self.scroll_y)
def render(self) -> RenderableType:
"""Render the scrollable region (if `render_lines` is not implemented).

View File

@@ -93,9 +93,9 @@ class ScrollBarRender:
) -> Segments:
if vertical:
bars = [" ", "", "", "", "", "", "", "", ""]
bars = ["", "", "", "", "", "", "", " "]
else:
bars = ["", "", "", "", "", "", "", "", " "]
bars = ["", "", "", "", "", "", "", " "]
back = back_color
bar = bar_color
@@ -110,11 +110,11 @@ class ScrollBarRender:
if window_size and size and virtual_size and size != virtual_size:
step_size = virtual_size / size
start = int(position / step_size * 9)
end = start + max(9, int(ceil(window_size / step_size * 9)))
start = int(position / step_size * 8)
end = start + max(8, int(ceil(window_size / step_size * 8)))
start_index, start_bar = divmod(start, 9)
end_index, end_bar = divmod(end, 9)
start_index, start_bar = divmod(start, 8)
end_index, end_bar = divmod(end, 8)
upper = {"@click": "scroll_up"}
lower = {"@click": "scroll_down"}
@@ -130,19 +130,23 @@ class ScrollBarRender:
] * (end_index - start_index)
if start_index < len(segments):
segments[start_index] = _Segment(
bars[8 - start_bar] * width_thickness,
_Style(bgcolor=back, color=bar, meta=foreground_meta)
if vertical
else _Style(bgcolor=bar, color=back, meta=foreground_meta),
)
bar_character = bars[7 - start_bar]
if bar_character != " ":
segments[start_index] = _Segment(
bar_character * width_thickness,
_Style(bgcolor=back, color=bar, meta=foreground_meta)
if vertical
else _Style(bgcolor=bar, color=back, meta=foreground_meta),
)
if end_index < len(segments):
segments[end_index] = _Segment(
bars[8 - end_bar] * width_thickness,
_Style(bgcolor=bar, color=back, meta=foreground_meta)
if vertical
else _Style(bgcolor=back, color=bar, meta=foreground_meta),
)
bar_character = bars[7 - end_bar]
if bar_character != " ":
segments[end_index] = _Segment(
bar_character * width_thickness,
_Style(bgcolor=bar, color=back, meta=foreground_meta)
if vertical
else _Style(bgcolor=back, color=bar, meta=foreground_meta),
)
else:
style = _Style(bgcolor=back)
segments = [_Segment(blank, style=style)] * int(size)

View File

@@ -1248,16 +1248,19 @@ class Widget(DOMNode):
width, height = self.container_size
if self.show_vertical_scrollbar:
self.vertical_scrollbar.window_virtual_size = virtual_size.height
self.vertical_scrollbar.window_size = height
self.vertical_scrollbar.window_size = (
height - self.scrollbar_size_horizontal
)
if self.show_horizontal_scrollbar:
self.horizontal_scrollbar.window_virtual_size = virtual_size.width
self.horizontal_scrollbar.window_size = width
self.horizontal_scrollbar.window_size = (
width - self.scrollbar_size_vertical
)
self.scroll_x = self.validate_scroll_x(self.scroll_x)
self.scroll_y = self.validate_scroll_y(self.scroll_y)
self.refresh(layout=True)
self.scroll_to(self.scroll_x, self.scroll_y)
# self.call_later(self.scroll_to, self.scroll_x, self.scroll_y)
else:
self.refresh()