Skip to content

Commit

Permalink
fix for zero width scrollbars (#3887)
Browse files Browse the repository at this point in the history
* fix for zero width scrollbars

* changelog

* snapshot fix

* simplify

* change wait

* early out, test fix

* no early out

* increase wait

* auto pilot

* increase wait

* skip windoze

* disable test

* restore test

* flush events

* another flush

* maybe fix race condition

* uderline fix

* simplify

* remove flush events
  • Loading branch information
willmcgugan authored Dec 17, 2023
1 parent 1ce6473 commit 32b916f
Show file tree
Hide file tree
Showing 6 changed files with 207 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Fixed

- Disabled radio buttons could be selected with the keyboard https://github.com/Textualize/textual/issues/3839
- Fixed zero width scrollbars causing content to disappear https://github.com/Textualize/textual/issues/3886

### Changed

Expand Down
17 changes: 15 additions & 2 deletions src/textual/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -1392,8 +1392,7 @@ def scrollbars_enabled(self) -> tuple[bool, bool]:
if not self.is_scrollable:
return False, False

enabled = self.show_vertical_scrollbar, self.show_horizontal_scrollbar
return enabled
return (self.show_vertical_scrollbar, self.show_horizontal_scrollbar)

@property
def scrollbars_space(self) -> tuple[int, int]:
Expand Down Expand Up @@ -2756,6 +2755,13 @@ def _get_scrollable_region(self, region: Region) -> Region:
scrollbar_size_horizontal = styles.scrollbar_size_horizontal
scrollbar_size_vertical = styles.scrollbar_size_vertical

show_vertical_scrollbar: bool = (
show_vertical_scrollbar and scrollbar_size_vertical
)
show_horizontal_scrollbar: bool = (
show_horizontal_scrollbar and scrollbar_size_horizontal
)

if styles.scrollbar_gutter == "stable":
# Let's _always_ reserve some space, whether the scrollbar is actually displayed or not:
show_vertical_scrollbar = True
Expand Down Expand Up @@ -2786,6 +2792,13 @@ def _arrange_scrollbars(self, region: Region) -> Iterable[tuple[Widget, Region]]
scrollbar_size_horizontal = self.scrollbar_size_horizontal
scrollbar_size_vertical = self.scrollbar_size_vertical

show_vertical_scrollbar: bool = (
show_vertical_scrollbar and scrollbar_size_vertical
)
show_horizontal_scrollbar: bool = (
show_horizontal_scrollbar and scrollbar_size_horizontal
)

if show_horizontal_scrollbar and show_vertical_scrollbar:
(
window_region,
Expand Down
13 changes: 11 additions & 2 deletions src/textual/widgets/_tabs.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,8 +593,17 @@ def _highlight_active(self, animate: bool = True) -> None:

def animate_underline() -> None:
"""Animate the underline."""
underline.animate("highlight_start", start, duration=0.3)
underline.animate("highlight_end", end, duration=0.3)
try:
active_tab = self.query_one(f"#tabs-list > Tab.-active")
except NoMatches:
pass
else:
tab_region = active_tab.virtual_region.shrink(
active_tab.styles.gutter
)
start, end = tab_region.column_span
underline.animate("highlight_start", start, duration=0.3)
underline.animate("highlight_end", end, duration=0.3)

self.set_timer(0.02, lambda: self.call_after_refresh(animate_underline))
else:
Expand Down
155 changes: 155 additions & 0 deletions tests/snapshot_tests/__snapshots__/test_snapshots.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -38206,3 +38206,158 @@

'''
# ---
# name: test_zero_scrollbar_size
'''
<svg class="rich-terminal" viewBox="0 0 994 635.5999999999999" xmlns="http://www.w3.org/2000/svg">
<!-- Generated with Rich https://www.textualize.io -->
<style>

@font-face {
font-family: "Fira Code";
src: local("FiraCode-Regular"),
url("https://cdnjs.cloudflare.com/ajax/libs/firacode/6.2.0/woff2/FiraCode-Regular.woff2") format("woff2"),
url("https://cdnjs.cloudflare.com/ajax/libs/firacode/6.2.0/woff/FiraCode-Regular.woff") format("woff");
font-style: normal;
font-weight: 400;
}
@font-face {
font-family: "Fira Code";
src: local("FiraCode-Bold"),
url("https://cdnjs.cloudflare.com/ajax/libs/firacode/6.2.0/woff2/FiraCode-Bold.woff2") format("woff2"),
url("https://cdnjs.cloudflare.com/ajax/libs/firacode/6.2.0/woff/FiraCode-Bold.woff") format("woff");
font-style: bold;
font-weight: 700;
}

.terminal-2277926227-matrix {
font-family: Fira Code, monospace;
font-size: 20px;
line-height: 24.4px;
font-variant-east-asian: full-width;
}

.terminal-2277926227-title {
font-size: 18px;
font-weight: bold;
font-family: arial;
}

.terminal-2277926227-r1 { fill: #e1e1e1 }
.terminal-2277926227-r2 { fill: #c5c8c6 }
</style>

<defs>
<clipPath id="terminal-2277926227-clip-terminal">
<rect x="0" y="0" width="975.0" height="584.5999999999999" />
</clipPath>
<clipPath id="terminal-2277926227-line-0">
<rect x="0" y="1.5" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-2277926227-line-1">
<rect x="0" y="25.9" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-2277926227-line-2">
<rect x="0" y="50.3" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-2277926227-line-3">
<rect x="0" y="74.7" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-2277926227-line-4">
<rect x="0" y="99.1" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-2277926227-line-5">
<rect x="0" y="123.5" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-2277926227-line-6">
<rect x="0" y="147.9" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-2277926227-line-7">
<rect x="0" y="172.3" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-2277926227-line-8">
<rect x="0" y="196.7" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-2277926227-line-9">
<rect x="0" y="221.1" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-2277926227-line-10">
<rect x="0" y="245.5" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-2277926227-line-11">
<rect x="0" y="269.9" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-2277926227-line-12">
<rect x="0" y="294.3" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-2277926227-line-13">
<rect x="0" y="318.7" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-2277926227-line-14">
<rect x="0" y="343.1" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-2277926227-line-15">
<rect x="0" y="367.5" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-2277926227-line-16">
<rect x="0" y="391.9" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-2277926227-line-17">
<rect x="0" y="416.3" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-2277926227-line-18">
<rect x="0" y="440.7" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-2277926227-line-19">
<rect x="0" y="465.1" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-2277926227-line-20">
<rect x="0" y="489.5" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-2277926227-line-21">
<rect x="0" y="513.9" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-2277926227-line-22">
<rect x="0" y="538.3" width="976" height="24.65"/>
</clipPath>
</defs>

<rect fill="#292929" stroke="rgba(255,255,255,0.35)" stroke-width="1" x="1" y="1" width="992" height="633.6" rx="8"/><text class="terminal-2277926227-title" fill="#c5c8c6" text-anchor="middle" x="496" y="27">TestApp</text>
<g transform="translate(26,22)">
<circle cx="0" cy="0" r="7" fill="#ff5f57"/>
<circle cx="22" cy="0" r="7" fill="#febc2e"/>
<circle cx="44" cy="0" r="7" fill="#28c840"/>
</g>

<g transform="translate(9, 41)" clip-path="url(#terminal-2277926227-clip-terminal)">
<rect fill="#1e1e1e" x="0" y="1.5" width="158.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="158.6" y="1.5" width="817.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="25.9" width="158.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="158.6" y="25.9" width="817.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="50.3" width="158.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="158.6" y="50.3" width="817.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="74.7" width="158.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="158.6" y="74.7" width="817.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="99.1" width="158.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="158.6" y="99.1" width="817.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="123.5" width="158.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="158.6" y="123.5" width="817.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="147.9" width="158.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="158.6" y="147.9" width="817.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="172.3" width="158.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="158.6" y="172.3" width="817.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="196.7" width="158.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="158.6" y="196.7" width="817.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="221.1" width="158.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="158.6" y="221.1" width="817.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="245.5" width="158.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="158.6" y="245.5" width="817.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="269.9" width="158.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="158.6" y="269.9" width="817.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="294.3" width="158.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="158.6" y="294.3" width="817.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="318.7" width="158.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="158.6" y="318.7" width="817.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="343.1" width="158.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="158.6" y="343.1" width="817.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="367.5" width="158.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="158.6" y="367.5" width="817.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="391.9" width="158.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="158.6" y="391.9" width="817.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="416.3" width="158.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="158.6" y="416.3" width="817.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="440.7" width="158.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="158.6" y="440.7" width="817.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="465.1" width="158.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="158.6" y="465.1" width="817.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="489.5" width="158.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="158.6" y="489.5" width="817.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="513.9" width="158.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="158.6" y="513.9" width="817.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="538.3" width="158.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="158.6" y="538.3" width="817.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="562.7" width="158.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="158.6" y="562.7" width="817.4" height="24.65" shape-rendering="crispEdges"/>
<g class="terminal-2277926227-matrix">
<text class="terminal-2277926227-r1" x="0" y="20" textLength="158.6" clip-path="url(#terminal-2277926227-line-0)">Hello,&#160;world!</text><text class="terminal-2277926227-r2" x="976" y="20" textLength="12.2" clip-path="url(#terminal-2277926227-line-0)">
</text><text class="terminal-2277926227-r1" x="0" y="44.4" textLength="158.6" clip-path="url(#terminal-2277926227-line-1)">Hello,&#160;world!</text><text class="terminal-2277926227-r2" x="976" y="44.4" textLength="12.2" clip-path="url(#terminal-2277926227-line-1)">
</text><text class="terminal-2277926227-r1" x="0" y="68.8" textLength="158.6" clip-path="url(#terminal-2277926227-line-2)">Hello,&#160;world!</text><text class="terminal-2277926227-r2" x="976" y="68.8" textLength="12.2" clip-path="url(#terminal-2277926227-line-2)">
</text><text class="terminal-2277926227-r1" x="0" y="93.2" textLength="158.6" clip-path="url(#terminal-2277926227-line-3)">Hello,&#160;world!</text><text class="terminal-2277926227-r2" x="976" y="93.2" textLength="12.2" clip-path="url(#terminal-2277926227-line-3)">
</text><text class="terminal-2277926227-r1" x="0" y="117.6" textLength="158.6" clip-path="url(#terminal-2277926227-line-4)">Hello,&#160;world!</text><text class="terminal-2277926227-r2" x="976" y="117.6" textLength="12.2" clip-path="url(#terminal-2277926227-line-4)">
</text><text class="terminal-2277926227-r1" x="0" y="142" textLength="158.6" clip-path="url(#terminal-2277926227-line-5)">Hello,&#160;world!</text><text class="terminal-2277926227-r2" x="976" y="142" textLength="12.2" clip-path="url(#terminal-2277926227-line-5)">
</text><text class="terminal-2277926227-r1" x="0" y="166.4" textLength="158.6" clip-path="url(#terminal-2277926227-line-6)">Hello,&#160;world!</text><text class="terminal-2277926227-r2" x="976" y="166.4" textLength="12.2" clip-path="url(#terminal-2277926227-line-6)">
</text><text class="terminal-2277926227-r1" x="0" y="190.8" textLength="158.6" clip-path="url(#terminal-2277926227-line-7)">Hello,&#160;world!</text><text class="terminal-2277926227-r2" x="976" y="190.8" textLength="12.2" clip-path="url(#terminal-2277926227-line-7)">
</text><text class="terminal-2277926227-r1" x="0" y="215.2" textLength="158.6" clip-path="url(#terminal-2277926227-line-8)">Hello,&#160;world!</text><text class="terminal-2277926227-r2" x="976" y="215.2" textLength="12.2" clip-path="url(#terminal-2277926227-line-8)">
</text><text class="terminal-2277926227-r1" x="0" y="239.6" textLength="158.6" clip-path="url(#terminal-2277926227-line-9)">Hello,&#160;world!</text><text class="terminal-2277926227-r2" x="976" y="239.6" textLength="12.2" clip-path="url(#terminal-2277926227-line-9)">
</text><text class="terminal-2277926227-r1" x="0" y="264" textLength="158.6" clip-path="url(#terminal-2277926227-line-10)">Hello,&#160;world!</text><text class="terminal-2277926227-r2" x="976" y="264" textLength="12.2" clip-path="url(#terminal-2277926227-line-10)">
</text><text class="terminal-2277926227-r1" x="0" y="288.4" textLength="158.6" clip-path="url(#terminal-2277926227-line-11)">Hello,&#160;world!</text><text class="terminal-2277926227-r2" x="976" y="288.4" textLength="12.2" clip-path="url(#terminal-2277926227-line-11)">
</text><text class="terminal-2277926227-r1" x="0" y="312.8" textLength="158.6" clip-path="url(#terminal-2277926227-line-12)">Hello,&#160;world!</text><text class="terminal-2277926227-r2" x="976" y="312.8" textLength="12.2" clip-path="url(#terminal-2277926227-line-12)">
</text><text class="terminal-2277926227-r1" x="0" y="337.2" textLength="158.6" clip-path="url(#terminal-2277926227-line-13)">Hello,&#160;world!</text><text class="terminal-2277926227-r2" x="976" y="337.2" textLength="12.2" clip-path="url(#terminal-2277926227-line-13)">
</text><text class="terminal-2277926227-r1" x="0" y="361.6" textLength="158.6" clip-path="url(#terminal-2277926227-line-14)">Hello,&#160;world!</text><text class="terminal-2277926227-r2" x="976" y="361.6" textLength="12.2" clip-path="url(#terminal-2277926227-line-14)">
</text><text class="terminal-2277926227-r1" x="0" y="386" textLength="158.6" clip-path="url(#terminal-2277926227-line-15)">Hello,&#160;world!</text><text class="terminal-2277926227-r2" x="976" y="386" textLength="12.2" clip-path="url(#terminal-2277926227-line-15)">
</text><text class="terminal-2277926227-r1" x="0" y="410.4" textLength="158.6" clip-path="url(#terminal-2277926227-line-16)">Hello,&#160;world!</text><text class="terminal-2277926227-r2" x="976" y="410.4" textLength="12.2" clip-path="url(#terminal-2277926227-line-16)">
</text><text class="terminal-2277926227-r1" x="0" y="434.8" textLength="158.6" clip-path="url(#terminal-2277926227-line-17)">Hello,&#160;world!</text><text class="terminal-2277926227-r2" x="976" y="434.8" textLength="12.2" clip-path="url(#terminal-2277926227-line-17)">
</text><text class="terminal-2277926227-r1" x="0" y="459.2" textLength="158.6" clip-path="url(#terminal-2277926227-line-18)">Hello,&#160;world!</text><text class="terminal-2277926227-r2" x="976" y="459.2" textLength="12.2" clip-path="url(#terminal-2277926227-line-18)">
</text><text class="terminal-2277926227-r1" x="0" y="483.6" textLength="158.6" clip-path="url(#terminal-2277926227-line-19)">Hello,&#160;world!</text><text class="terminal-2277926227-r2" x="976" y="483.6" textLength="12.2" clip-path="url(#terminal-2277926227-line-19)">
</text><text class="terminal-2277926227-r1" x="0" y="508" textLength="158.6" clip-path="url(#terminal-2277926227-line-20)">Hello,&#160;world!</text><text class="terminal-2277926227-r2" x="976" y="508" textLength="12.2" clip-path="url(#terminal-2277926227-line-20)">
</text><text class="terminal-2277926227-r1" x="0" y="532.4" textLength="158.6" clip-path="url(#terminal-2277926227-line-21)">Hello,&#160;world!</text><text class="terminal-2277926227-r2" x="976" y="532.4" textLength="12.2" clip-path="url(#terminal-2277926227-line-21)">
</text><text class="terminal-2277926227-r1" x="0" y="556.8" textLength="158.6" clip-path="url(#terminal-2277926227-line-22)">Hello,&#160;world!</text><text class="terminal-2277926227-r2" x="976" y="556.8" textLength="12.2" clip-path="url(#terminal-2277926227-line-22)">
</text><text class="terminal-2277926227-r1" x="0" y="581.2" textLength="158.6" clip-path="url(#terminal-2277926227-line-23)">Hello,&#160;world!</text>
</g>
</g>
</svg>

'''
# ---
17 changes: 17 additions & 0 deletions tests/snapshot_tests/snapshot_apps/zero_scrollbar_size.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from textual.app import App, ComposeResult
from textual.widgets import Static


class TestApp(App):
DEFAULT_CSS = """
Screen {
scrollbar-size: 0 0;
}
"""

def compose(self) -> ComposeResult:
yield Static("Hello, world!\n" * 100)


if __name__ == "__main__":
TestApp().run()
Loading

0 comments on commit 32b916f

Please sign in to comment.