Merge pull request #1403 from Textualize/nested-height-fix

fix for nested heights
This commit is contained in:
Will McGugan
2022-12-20 11:14:52 +00:00
committed by GitHub
6 changed files with 241 additions and 3 deletions

View File

@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## [0.8.0] - Unreleased
### Fixed
- Fixed issues with nested auto dimensions https://github.com/Textualize/textual/issues/1402
### Added
- Added `textual.actions.SkipAction` exception which can be raised from an action to allow parents to process bindings.

View File

@@ -2176,8 +2176,14 @@ class Widget(DOMNode):
if layout:
self._layout_required = True
if isinstance(self._parent, Widget):
self._parent._clear_arrangement_cache()
for ancestor in self.ancestors:
if not isinstance(ancestor, Widget):
break
if ancestor.styles.auto_dimensions:
for ancestor in self.ancestors_with_self:
if isinstance(ancestor, Widget):
ancestor._clear_arrangement_cache()
break
if repaint:
self._set_dirty(*regions)

View File

@@ -7143,6 +7143,165 @@
'''
# ---
# name: test_nested_auto_heights
'''
<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-2940916684-matrix {
font-family: Fira Code, monospace;
font-size: 20px;
line-height: 24.4px;
font-variant-east-asian: full-width;
}
.terminal-2940916684-title {
font-size: 18px;
font-weight: bold;
font-family: arial;
}
.terminal-2940916684-r1 { fill: #90ee90 }
.terminal-2940916684-r2 { fill: #c5c8c6 }
.terminal-2940916684-r3 { fill: #add8e6 }
.terminal-2940916684-r4 { fill: #808080 }
.terminal-2940916684-r5 { fill: #dddddd }
.terminal-2940916684-r6 { fill: #ffdddd }
</style>
<defs>
<clipPath id="terminal-2940916684-clip-terminal">
<rect x="0" y="0" width="975.0" height="584.5999999999999" />
</clipPath>
<clipPath id="terminal-2940916684-line-0">
<rect x="0" y="1.5" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-2940916684-line-1">
<rect x="0" y="25.9" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-2940916684-line-2">
<rect x="0" y="50.3" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-2940916684-line-3">
<rect x="0" y="74.7" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-2940916684-line-4">
<rect x="0" y="99.1" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-2940916684-line-5">
<rect x="0" y="123.5" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-2940916684-line-6">
<rect x="0" y="147.9" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-2940916684-line-7">
<rect x="0" y="172.3" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-2940916684-line-8">
<rect x="0" y="196.7" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-2940916684-line-9">
<rect x="0" y="221.1" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-2940916684-line-10">
<rect x="0" y="245.5" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-2940916684-line-11">
<rect x="0" y="269.9" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-2940916684-line-12">
<rect x="0" y="294.3" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-2940916684-line-13">
<rect x="0" y="318.7" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-2940916684-line-14">
<rect x="0" y="343.1" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-2940916684-line-15">
<rect x="0" y="367.5" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-2940916684-line-16">
<rect x="0" y="391.9" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-2940916684-line-17">
<rect x="0" y="416.3" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-2940916684-line-18">
<rect x="0" y="440.7" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-2940916684-line-19">
<rect x="0" y="465.1" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-2940916684-line-20">
<rect x="0" y="489.5" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-2940916684-line-21">
<rect x="0" y="513.9" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-2940916684-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-2940916684-title" fill="#c5c8c6" text-anchor="middle" x="496" y="27">NestedAutoApp</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-2940916684-clip-terminal)">
<rect fill="#008000" x="0" y="1.5" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#008000" x="0" y="25.9" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#0000ff" x="12.2" y="25.9" width="207.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#008000" x="219.6" y="25.9" width="744.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#008000" x="963.8" y="25.9" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#008000" x="0" y="50.3" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#0000ff" x="12.2" y="50.3" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#000000" x="24.4" y="50.3" width="183" height="24.65" shape-rendering="crispEdges"/><rect fill="#0000ff" x="207.4" y="50.3" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#008000" x="219.6" y="50.3" width="744.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#008000" x="963.8" y="50.3" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#008000" x="0" y="74.7" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#0000ff" x="12.2" y="74.7" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#000000" x="24.4" y="74.7" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#000000" x="36.6" y="74.7" width="158.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#000000" x="195.2" y="74.7" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#0000ff" x="207.4" y="74.7" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#008000" x="219.6" y="74.7" width="744.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#008000" x="963.8" y="74.7" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#008000" x="0" y="99.1" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#0000ff" x="12.2" y="99.1" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#000000" x="24.4" y="99.1" width="183" height="24.65" shape-rendering="crispEdges"/><rect fill="#0000ff" x="207.4" y="99.1" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#008000" x="219.6" y="99.1" width="744.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#008000" x="963.8" y="99.1" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#008000" x="0" y="123.5" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#0000ff" x="12.2" y="123.5" width="207.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#008000" x="219.6" y="123.5" width="744.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#008000" x="963.8" y="123.5" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#008000" x="0" y="147.9" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#ff0000" x="0" y="172.3" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#ff0000" x="0" y="196.7" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#ff0000" x="0" y="221.1" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#ff0000" x="0" y="245.5" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#ff0000" x="0" y="269.9" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#ff0000" x="0" y="294.3" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#ff0000" x="0" y="318.7" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#ff0000" x="0" y="343.1" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#ff0000" x="0" y="367.5" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#ff0000" x="0" y="391.9" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#ff0000" x="0" y="416.3" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#ff0000" x="0" y="440.7" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#ff0000" x="0" y="465.1" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#ff0000" x="0" y="489.5" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#ff0000" x="0" y="513.9" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#ff0000" x="0" y="538.3" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#ff0000" x="0" y="562.7" width="976" height="24.65" shape-rendering="crispEdges"/>
<g class="terminal-2940916684-matrix">
<text class="terminal-2940916684-r1" x="0" y="20" textLength="976" clip-path="url(#terminal-2940916684-line-0)">┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓</text><text class="terminal-2940916684-r2" x="976" y="20" textLength="12.2" clip-path="url(#terminal-2940916684-line-0)">
</text><text class="terminal-2940916684-r1" x="0" y="44.4" textLength="12.2" clip-path="url(#terminal-2940916684-line-1)">┃</text><text class="terminal-2940916684-r3" x="12.2" y="44.4" textLength="207.4" clip-path="url(#terminal-2940916684-line-1)">┏━━━━━━━━━━━━━━━┓</text><text class="terminal-2940916684-r1" x="963.8" y="44.4" textLength="12.2" clip-path="url(#terminal-2940916684-line-1)">┃</text><text class="terminal-2940916684-r2" x="976" y="44.4" textLength="12.2" clip-path="url(#terminal-2940916684-line-1)">
</text><text class="terminal-2940916684-r1" x="0" y="68.8" textLength="12.2" clip-path="url(#terminal-2940916684-line-2)">┃</text><text class="terminal-2940916684-r3" x="12.2" y="68.8" textLength="12.2" clip-path="url(#terminal-2940916684-line-2)">┃</text><text class="terminal-2940916684-r4" x="24.4" y="68.8" textLength="183" clip-path="url(#terminal-2940916684-line-2)">┏━━━━━━━━━━━━━┓</text><text class="terminal-2940916684-r3" x="207.4" y="68.8" textLength="12.2" clip-path="url(#terminal-2940916684-line-2)">┃</text><text class="terminal-2940916684-r1" x="963.8" y="68.8" textLength="12.2" clip-path="url(#terminal-2940916684-line-2)">┃</text><text class="terminal-2940916684-r2" x="976" y="68.8" textLength="12.2" clip-path="url(#terminal-2940916684-line-2)">
</text><text class="terminal-2940916684-r1" x="0" y="93.2" textLength="12.2" clip-path="url(#terminal-2940916684-line-3)">┃</text><text class="terminal-2940916684-r3" x="12.2" y="93.2" textLength="12.2" clip-path="url(#terminal-2940916684-line-3)">┃</text><text class="terminal-2940916684-r4" x="24.4" y="93.2" textLength="12.2" clip-path="url(#terminal-2940916684-line-3)">┃</text><text class="terminal-2940916684-r5" x="36.6" y="93.2" textLength="158.6" clip-path="url(#terminal-2940916684-line-3)">JUST&#160;ONE&#160;LINE</text><text class="terminal-2940916684-r4" x="195.2" y="93.2" textLength="12.2" clip-path="url(#terminal-2940916684-line-3)">┃</text><text class="terminal-2940916684-r3" x="207.4" y="93.2" textLength="12.2" clip-path="url(#terminal-2940916684-line-3)">┃</text><text class="terminal-2940916684-r1" x="963.8" y="93.2" textLength="12.2" clip-path="url(#terminal-2940916684-line-3)">┃</text><text class="terminal-2940916684-r2" x="976" y="93.2" textLength="12.2" clip-path="url(#terminal-2940916684-line-3)">
</text><text class="terminal-2940916684-r1" x="0" y="117.6" textLength="12.2" clip-path="url(#terminal-2940916684-line-4)">┃</text><text class="terminal-2940916684-r3" x="12.2" y="117.6" textLength="12.2" clip-path="url(#terminal-2940916684-line-4)">┃</text><text class="terminal-2940916684-r4" x="24.4" y="117.6" textLength="183" clip-path="url(#terminal-2940916684-line-4)">┗━━━━━━━━━━━━━┛</text><text class="terminal-2940916684-r3" x="207.4" y="117.6" textLength="12.2" clip-path="url(#terminal-2940916684-line-4)">┃</text><text class="terminal-2940916684-r1" x="963.8" y="117.6" textLength="12.2" clip-path="url(#terminal-2940916684-line-4)">┃</text><text class="terminal-2940916684-r2" x="976" y="117.6" textLength="12.2" clip-path="url(#terminal-2940916684-line-4)">
</text><text class="terminal-2940916684-r1" x="0" y="142" textLength="12.2" clip-path="url(#terminal-2940916684-line-5)">┃</text><text class="terminal-2940916684-r3" x="12.2" y="142" textLength="207.4" clip-path="url(#terminal-2940916684-line-5)">┗━━━━━━━━━━━━━━━┛</text><text class="terminal-2940916684-r1" x="963.8" y="142" textLength="12.2" clip-path="url(#terminal-2940916684-line-5)">┃</text><text class="terminal-2940916684-r2" x="976" y="142" textLength="12.2" clip-path="url(#terminal-2940916684-line-5)">
</text><text class="terminal-2940916684-r1" x="0" y="166.4" textLength="976" clip-path="url(#terminal-2940916684-line-6)">┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛</text><text class="terminal-2940916684-r2" x="976" y="166.4" textLength="12.2" clip-path="url(#terminal-2940916684-line-6)">
</text><text class="terminal-2940916684-r2" x="976" y="190.8" textLength="12.2" clip-path="url(#terminal-2940916684-line-7)">
</text><text class="terminal-2940916684-r2" x="976" y="215.2" textLength="12.2" clip-path="url(#terminal-2940916684-line-8)">
</text><text class="terminal-2940916684-r2" x="976" y="239.6" textLength="12.2" clip-path="url(#terminal-2940916684-line-9)">
</text><text class="terminal-2940916684-r2" x="976" y="264" textLength="12.2" clip-path="url(#terminal-2940916684-line-10)">
</text><text class="terminal-2940916684-r2" x="976" y="288.4" textLength="12.2" clip-path="url(#terminal-2940916684-line-11)">
</text><text class="terminal-2940916684-r2" x="976" y="312.8" textLength="12.2" clip-path="url(#terminal-2940916684-line-12)">
</text><text class="terminal-2940916684-r2" x="976" y="337.2" textLength="12.2" clip-path="url(#terminal-2940916684-line-13)">
</text><text class="terminal-2940916684-r2" x="976" y="361.6" textLength="12.2" clip-path="url(#terminal-2940916684-line-14)">
</text><text class="terminal-2940916684-r2" x="976" y="386" textLength="12.2" clip-path="url(#terminal-2940916684-line-15)">
</text><text class="terminal-2940916684-r2" x="976" y="410.4" textLength="12.2" clip-path="url(#terminal-2940916684-line-16)">
</text><text class="terminal-2940916684-r2" x="976" y="434.8" textLength="12.2" clip-path="url(#terminal-2940916684-line-17)">
</text><text class="terminal-2940916684-r2" x="976" y="459.2" textLength="12.2" clip-path="url(#terminal-2940916684-line-18)">
</text><text class="terminal-2940916684-r2" x="976" y="483.6" textLength="12.2" clip-path="url(#terminal-2940916684-line-19)">
</text><text class="terminal-2940916684-r2" x="976" y="508" textLength="12.2" clip-path="url(#terminal-2940916684-line-20)">
</text><text class="terminal-2940916684-r2" x="976" y="532.4" textLength="12.2" clip-path="url(#terminal-2940916684-line-21)">
</text><text class="terminal-2940916684-r2" x="976" y="556.8" textLength="12.2" clip-path="url(#terminal-2940916684-line-22)">
</text>
</g>
</g>
</svg>
'''
# ---
# name: test_offsets
'''
<svg class="rich-terminal" viewBox="0 0 994 635.5999999999999" xmlns="http://www.w3.org/2000/svg">

View File

@@ -188,7 +188,7 @@ def pytest_terminal_summary(
Displays the link to the snapshot report that was generated in a prior hook.
"""
diffs = getattr(config, "_textual_snapshots", None)
console = Console()
console = Console(legacy_windows=False, force_terminal=True)
if diffs:
snapshot_report_location = config._textual_snapshot_html_report
console.rule("[b red]Textual Snapshot Report", style="red")

View File

@@ -0,0 +1,64 @@
#!/usr/bin/env python3
from __future__ import annotations
from textual.app import App, ComposeResult
from textual.containers import Vertical
from textual.widgets import Static
class NestedAutoApp(App[None]):
CSS = """
Screen {
background: red;
}
#my-static-container {
border: heavy lightgreen;
background: green;
height: auto;
max-height: 10;
}
#my-static-wrapper {
border: heavy lightblue;
background: blue;
width: auto;
height: auto;
}
#my-static {
border: heavy gray;
background: black;
width: auto;
height: auto;
}
"""
BINDINGS = [
("1", "1", "1"),
("2", "2", "2"),
("q", "quit", "Quit"),
]
def compose(self) -> ComposeResult:
self._static = Static("", id="my-static")
yield Vertical(
Vertical(
self._static,
id="my-static-wrapper",
),
id="my-static-container",
)
def action_1(self) -> None:
self._static.update(
"\n".join(f"Lorem {i} Ipsum {i} Sit {i}" for i in range(1, 21))
)
def action_2(self) -> None:
self._static.update("JUST ONE LINE")
if __name__ == "__main__":
app = NestedAutoApp()
app.run()

View File

@@ -162,6 +162,11 @@ def test_offsets(snap_compare):
assert snap_compare("snapshot_apps/offsets.py")
def test_nested_auto_heights(snap_compare):
"""Test refreshing widget within a auto sized container"""
assert snap_compare("snapshot_apps/nested_auto_heights.py", press=["1", "2", "_"])
# --- Other ---