From 96f5c959eb9598ed68161d9a69837f5866bcc6e0 Mon Sep 17 00:00:00 2001 From: Isaiah Odhner Date: Tue, 5 Sep 2023 19:45:38 -0400 Subject: [PATCH] Clean up ASCIIScrollBarRender --- src/textual_paint/scrollbars.py | 38 +++------------------------------ 1 file changed, 3 insertions(+), 35 deletions(-) diff --git a/src/textual_paint/scrollbars.py b/src/textual_paint/scrollbars.py index 03f18f5..72588a7 100644 --- a/src/textual_paint/scrollbars.py +++ b/src/textual_paint/scrollbars.py @@ -7,7 +7,7 @@ from textual.scrollbar import ScrollBarRender class ASCIIScrollBarRender(ScrollBarRender): - """A scrollbar renderer that uses ASCII characters.""" + """A scrollbar renderer that uses only ASCII space characters.""" @classmethod def render_bar( cls, @@ -20,20 +20,10 @@ class ASCIIScrollBarRender(ScrollBarRender): back_color: Color = Color.parse("#555555"), bar_color: Color = Color.parse("bright_magenta"), ) -> Segments: - if vertical: - # bars = ["▁", "▂", "▃", "▄", "▅", "▆", "▇", " "] - # bars = ["_", "=", "#", " "] - bars = [" "] - else: - # bars = ["▉", "▊", "▋", "▌", "▍", "▎", "▏", " "] - # bars = ["#", " "] - bars = [" "] back = back_color bar = bar_color - len_bars = len(bars) - width_thickness = thickness if vertical else 1 _Segment = Segment @@ -48,11 +38,8 @@ class ASCIIScrollBarRender(ScrollBarRender): position_ratio = position / (virtual_size - window_size) position = (size - thumb_size) * position_ratio - start = int(position * len_bars) - end = start + ceil(thumb_size * len_bars) - - start_index, start_bar = divmod(max(0, start), len_bars) - end_index, end_bar = divmod(max(0, end), len_bars) + start_index = max(0, int(position)) + end_index = max(0, start_index + ceil(thumb_size)) upper = {"@mouse.up": "scroll_up"} lower = {"@mouse.up": "scroll_down"} @@ -67,25 +54,6 @@ class ASCIIScrollBarRender(ScrollBarRender): _Segment(blank, _Style(bgcolor=bar, meta=foreground_meta)) ] * (end_index - start_index) - # Apply the smaller bar characters to head and tail of scrollbar for more "granularity" - if start_index < len(segments): - bar_character = bars[len_bars - 1 - 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): - bar_character = bars[len_bars - 1 - 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)