Skip to content

Commit 1f64127

Browse files
committed
snapshot
1 parent 3c425c3 commit 1f64127

File tree

6 files changed

+209
-3
lines changed

6 files changed

+209
-3
lines changed

src/textual/_compositor.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,9 @@ def add_widget(
371371
)
372372

373373
# Container region is minus border
374-
container_region = region.shrink(widget.styles.gutter)
374+
container_region = region.shrink(widget.styles.gutter).translate(
375+
layout_offset
376+
)
375377
container_size = container_region.size
376378

377379
# Widgets with scrollbars (containers or scroll view) require additional processing
@@ -393,7 +395,7 @@ def add_widget(
393395
widgets.update(arranged_widgets)
394396

395397
# An offset added to all placements
396-
placement_offset = container_region.offset + layout_offset
398+
placement_offset = container_region.offset
397399
placement_scroll_offset = placement_offset - widget.scroll_offset
398400

399401
_layers = widget.layers

src/textual/_styles_cache.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ def render(
198198
if crop is None:
199199
crop = size.region
200200

201-
width, height = size
201+
width, _height = size
202202
if width != self._width:
203203
self.clear()
204204
self._width = width

src/textual/geometry.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,7 @@ def contains_region(self, other: Region) -> bool:
635635
and (y2 >= oy2 >= y1)
636636
)
637637

638+
@lru_cache(maxsize=1024)
638639
def translate(self, offset: tuple[int, int]) -> Region:
639640
"""Move the offset of the Region.
640641

tests/snapshot_tests/__snapshots__/test_snapshots.ambr

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6962,6 +6962,163 @@
69626962

69636963
'''
69646964
# ---
6965+
# name: test_offsets
6966+
'''
6967+
<svg class="rich-terminal" viewBox="0 0 994 635.5999999999999" xmlns="http://www.w3.org/2000/svg">
6968+
<!-- Generated with Rich https://www.textualize.io -->
6969+
<style>
6970+
6971+
@font-face {
6972+
font-family: "Fira Code";
6973+
src: local("FiraCode-Regular"),
6974+
url("https://cdnjs.cloudflare.com/ajax/libs/firacode/6.2.0/woff2/FiraCode-Regular.woff2") format("woff2"),
6975+
url("https://cdnjs.cloudflare.com/ajax/libs/firacode/6.2.0/woff/FiraCode-Regular.woff") format("woff");
6976+
font-style: normal;
6977+
font-weight: 400;
6978+
}
6979+
@font-face {
6980+
font-family: "Fira Code";
6981+
src: local("FiraCode-Bold"),
6982+
url("https://cdnjs.cloudflare.com/ajax/libs/firacode/6.2.0/woff2/FiraCode-Bold.woff2") format("woff2"),
6983+
url("https://cdnjs.cloudflare.com/ajax/libs/firacode/6.2.0/woff/FiraCode-Bold.woff") format("woff");
6984+
font-style: bold;
6985+
font-weight: 700;
6986+
}
6987+
6988+
.terminal-1996000257-matrix {
6989+
font-family: Fira Code, monospace;
6990+
font-size: 20px;
6991+
line-height: 24.4px;
6992+
font-variant-east-asian: full-width;
6993+
}
6994+
6995+
.terminal-1996000257-title {
6996+
font-size: 18px;
6997+
font-weight: bold;
6998+
font-family: arial;
6999+
}
7000+
7001+
.terminal-1996000257-r1 { fill: #e1e1e1 }
7002+
.terminal-1996000257-r2 { fill: #c5c8c6 }
7003+
.terminal-1996000257-r3 { fill: #ffffff }
7004+
.terminal-1996000257-r4 { fill: #ddddef }
7005+
</style>
7006+
7007+
<defs>
7008+
<clipPath id="terminal-1996000257-clip-terminal">
7009+
<rect x="0" y="0" width="975.0" height="584.5999999999999" />
7010+
</clipPath>
7011+
<clipPath id="terminal-1996000257-line-0">
7012+
<rect x="0" y="1.5" width="976" height="24.65"/>
7013+
</clipPath>
7014+
<clipPath id="terminal-1996000257-line-1">
7015+
<rect x="0" y="25.9" width="976" height="24.65"/>
7016+
</clipPath>
7017+
<clipPath id="terminal-1996000257-line-2">
7018+
<rect x="0" y="50.3" width="976" height="24.65"/>
7019+
</clipPath>
7020+
<clipPath id="terminal-1996000257-line-3">
7021+
<rect x="0" y="74.7" width="976" height="24.65"/>
7022+
</clipPath>
7023+
<clipPath id="terminal-1996000257-line-4">
7024+
<rect x="0" y="99.1" width="976" height="24.65"/>
7025+
</clipPath>
7026+
<clipPath id="terminal-1996000257-line-5">
7027+
<rect x="0" y="123.5" width="976" height="24.65"/>
7028+
</clipPath>
7029+
<clipPath id="terminal-1996000257-line-6">
7030+
<rect x="0" y="147.9" width="976" height="24.65"/>
7031+
</clipPath>
7032+
<clipPath id="terminal-1996000257-line-7">
7033+
<rect x="0" y="172.3" width="976" height="24.65"/>
7034+
</clipPath>
7035+
<clipPath id="terminal-1996000257-line-8">
7036+
<rect x="0" y="196.7" width="976" height="24.65"/>
7037+
</clipPath>
7038+
<clipPath id="terminal-1996000257-line-9">
7039+
<rect x="0" y="221.1" width="976" height="24.65"/>
7040+
</clipPath>
7041+
<clipPath id="terminal-1996000257-line-10">
7042+
<rect x="0" y="245.5" width="976" height="24.65"/>
7043+
</clipPath>
7044+
<clipPath id="terminal-1996000257-line-11">
7045+
<rect x="0" y="269.9" width="976" height="24.65"/>
7046+
</clipPath>
7047+
<clipPath id="terminal-1996000257-line-12">
7048+
<rect x="0" y="294.3" width="976" height="24.65"/>
7049+
</clipPath>
7050+
<clipPath id="terminal-1996000257-line-13">
7051+
<rect x="0" y="318.7" width="976" height="24.65"/>
7052+
</clipPath>
7053+
<clipPath id="terminal-1996000257-line-14">
7054+
<rect x="0" y="343.1" width="976" height="24.65"/>
7055+
</clipPath>
7056+
<clipPath id="terminal-1996000257-line-15">
7057+
<rect x="0" y="367.5" width="976" height="24.65"/>
7058+
</clipPath>
7059+
<clipPath id="terminal-1996000257-line-16">
7060+
<rect x="0" y="391.9" width="976" height="24.65"/>
7061+
</clipPath>
7062+
<clipPath id="terminal-1996000257-line-17">
7063+
<rect x="0" y="416.3" width="976" height="24.65"/>
7064+
</clipPath>
7065+
<clipPath id="terminal-1996000257-line-18">
7066+
<rect x="0" y="440.7" width="976" height="24.65"/>
7067+
</clipPath>
7068+
<clipPath id="terminal-1996000257-line-19">
7069+
<rect x="0" y="465.1" width="976" height="24.65"/>
7070+
</clipPath>
7071+
<clipPath id="terminal-1996000257-line-20">
7072+
<rect x="0" y="489.5" width="976" height="24.65"/>
7073+
</clipPath>
7074+
<clipPath id="terminal-1996000257-line-21">
7075+
<rect x="0" y="513.9" width="976" height="24.65"/>
7076+
</clipPath>
7077+
<clipPath id="terminal-1996000257-line-22">
7078+
<rect x="0" y="538.3" width="976" height="24.65"/>
7079+
</clipPath>
7080+
</defs>
7081+
7082+
<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-1996000257-title" fill="#c5c8c6" text-anchor="middle" x="496" y="27">OffsetsApp</text>
7083+
<g transform="translate(26,22)">
7084+
<circle cx="0" cy="0" r="7" fill="#ff5f57"/>
7085+
<circle cx="22" cy="0" r="7" fill="#febc2e"/>
7086+
<circle cx="44" cy="0" r="7" fill="#28c840"/>
7087+
</g>
7088+
7089+
<g transform="translate(9, 41)" clip-path="url(#terminal-1996000257-clip-terminal)">
7090+
<rect fill="#1e1e1e" x="0" y="1.5" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="25.9" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="50.3" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="74.7" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="99.1" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="123.5" width="61" height="24.65" shape-rendering="crispEdges"/><rect fill="#00008b" x="61" y="123.5" width="195.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="256.2" y="123.5" width="719.8" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="147.9" width="61" height="24.65" shape-rendering="crispEdges"/><rect fill="#00008b" x="61" y="147.9" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#00008b" x="73.2" y="147.9" width="36.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#00008b" x="109.8" y="147.9" width="134.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#00008b" x="244" y="147.9" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="256.2" y="147.9" width="719.8" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="172.3" width="61" height="24.65" shape-rendering="crispEdges"/><rect fill="#00008b" x="61" y="172.3" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#00008b" x="73.2" y="172.3" width="36.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#00008b" x="109.8" y="172.3" width="134.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#00008b" x="244" y="172.3" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="256.2" y="172.3" width="719.8" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="196.7" width="61" height="24.65" shape-rendering="crispEdges"/><rect fill="#00008b" x="61" y="196.7" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#00008b" x="73.2" y="196.7" width="36.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#00008b" x="109.8" y="196.7" width="134.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#00008b" x="244" y="196.7" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="256.2" y="196.7" width="719.8" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="221.1" width="61" height="24.65" shape-rendering="crispEdges"/><rect fill="#00008b" x="61" y="221.1" width="195.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="256.2" y="221.1" width="719.8" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="245.5" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="269.9" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="294.3" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="318.7" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="343.1" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="367.5" width="183" height="24.65" shape-rendering="crispEdges"/><rect fill="#00008b" x="183" y="367.5" width="195.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="378.2" y="367.5" width="597.8" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="391.9" width="183" height="24.65" shape-rendering="crispEdges"/><rect fill="#00008b" x="183" y="391.9" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#00008b" x="195.2" y="391.9" width="36.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#00008b" x="231.8" y="391.9" width="134.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#00008b" x="366" y="391.9" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="378.2" y="391.9" width="597.8" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="416.3" width="183" height="24.65" shape-rendering="crispEdges"/><rect fill="#00008b" x="183" y="416.3" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#00008b" x="195.2" y="416.3" width="36.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#00008b" x="231.8" y="416.3" width="134.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#00008b" x="366" y="416.3" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="378.2" y="416.3" width="597.8" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="440.7" width="183" height="24.65" shape-rendering="crispEdges"/><rect fill="#00008b" x="183" y="440.7" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#00008b" x="195.2" y="440.7" width="36.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#00008b" x="231.8" y="440.7" width="134.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#00008b" x="366" y="440.7" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="378.2" y="440.7" width="597.8" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="465.1" width="183" height="24.65" shape-rendering="crispEdges"/><rect fill="#00008b" x="183" y="465.1" width="195.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="378.2" y="465.1" width="597.8" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="489.5" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="513.9" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="538.3" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="562.7" width="976" height="24.65" shape-rendering="crispEdges"/>
7091+
<g class="terminal-1996000257-matrix">
7092+
<text class="terminal-1996000257-r2" x="976" y="20" textLength="12.2" clip-path="url(#terminal-1996000257-line-0)">
7093+
</text><text class="terminal-1996000257-r2" x="976" y="44.4" textLength="12.2" clip-path="url(#terminal-1996000257-line-1)">
7094+
</text><text class="terminal-1996000257-r2" x="976" y="68.8" textLength="12.2" clip-path="url(#terminal-1996000257-line-2)">
7095+
</text><text class="terminal-1996000257-r2" x="976" y="93.2" textLength="12.2" clip-path="url(#terminal-1996000257-line-3)">
7096+
</text><text class="terminal-1996000257-r2" x="976" y="117.6" textLength="12.2" clip-path="url(#terminal-1996000257-line-4)">
7097+
</text><text class="terminal-1996000257-r3" x="61" y="142" textLength="195.2" clip-path="url(#terminal-1996000257-line-5)">┌──────────────┐</text><text class="terminal-1996000257-r2" x="976" y="142" textLength="12.2" clip-path="url(#terminal-1996000257-line-5)">
7098+
</text><text class="terminal-1996000257-r3" x="61" y="166.4" textLength="12.2" clip-path="url(#terminal-1996000257-line-6)">│</text><text class="terminal-1996000257-r4" x="73.2" y="166.4" textLength="36.6" clip-path="url(#terminal-1996000257-line-6)">FOO</text><text class="terminal-1996000257-r3" x="244" y="166.4" textLength="12.2" clip-path="url(#terminal-1996000257-line-6)">│</text><text class="terminal-1996000257-r2" x="976" y="166.4" textLength="12.2" clip-path="url(#terminal-1996000257-line-6)">
7099+
</text><text class="terminal-1996000257-r3" x="61" y="190.8" textLength="12.2" clip-path="url(#terminal-1996000257-line-7)">│</text><text class="terminal-1996000257-r4" x="73.2" y="190.8" textLength="36.6" clip-path="url(#terminal-1996000257-line-7)">BAR</text><text class="terminal-1996000257-r3" x="244" y="190.8" textLength="12.2" clip-path="url(#terminal-1996000257-line-7)">│</text><text class="terminal-1996000257-r2" x="976" y="190.8" textLength="12.2" clip-path="url(#terminal-1996000257-line-7)">
7100+
</text><text class="terminal-1996000257-r3" x="61" y="215.2" textLength="12.2" clip-path="url(#terminal-1996000257-line-8)">│</text><text class="terminal-1996000257-r4" x="73.2" y="215.2" textLength="36.6" clip-path="url(#terminal-1996000257-line-8)">BAZ</text><text class="terminal-1996000257-r3" x="244" y="215.2" textLength="12.2" clip-path="url(#terminal-1996000257-line-8)">│</text><text class="terminal-1996000257-r2" x="976" y="215.2" textLength="12.2" clip-path="url(#terminal-1996000257-line-8)">
7101+
</text><text class="terminal-1996000257-r3" x="61" y="239.6" textLength="195.2" clip-path="url(#terminal-1996000257-line-9)">└──────────────┘</text><text class="terminal-1996000257-r2" x="976" y="239.6" textLength="12.2" clip-path="url(#terminal-1996000257-line-9)">
7102+
</text><text class="terminal-1996000257-r2" x="976" y="264" textLength="12.2" clip-path="url(#terminal-1996000257-line-10)">
7103+
</text><text class="terminal-1996000257-r2" x="976" y="288.4" textLength="12.2" clip-path="url(#terminal-1996000257-line-11)">
7104+
</text><text class="terminal-1996000257-r2" x="976" y="312.8" textLength="12.2" clip-path="url(#terminal-1996000257-line-12)">
7105+
</text><text class="terminal-1996000257-r2" x="976" y="337.2" textLength="12.2" clip-path="url(#terminal-1996000257-line-13)">
7106+
</text><text class="terminal-1996000257-r2" x="976" y="361.6" textLength="12.2" clip-path="url(#terminal-1996000257-line-14)">
7107+
</text><text class="terminal-1996000257-r3" x="183" y="386" textLength="195.2" clip-path="url(#terminal-1996000257-line-15)">┌──────────────┐</text><text class="terminal-1996000257-r2" x="976" y="386" textLength="12.2" clip-path="url(#terminal-1996000257-line-15)">
7108+
</text><text class="terminal-1996000257-r3" x="183" y="410.4" textLength="12.2" clip-path="url(#terminal-1996000257-line-16)">│</text><text class="terminal-1996000257-r4" x="195.2" y="410.4" textLength="36.6" clip-path="url(#terminal-1996000257-line-16)">FOO</text><text class="terminal-1996000257-r3" x="366" y="410.4" textLength="12.2" clip-path="url(#terminal-1996000257-line-16)">│</text><text class="terminal-1996000257-r2" x="976" y="410.4" textLength="12.2" clip-path="url(#terminal-1996000257-line-16)">
7109+
</text><text class="terminal-1996000257-r3" x="183" y="434.8" textLength="12.2" clip-path="url(#terminal-1996000257-line-17)">│</text><text class="terminal-1996000257-r4" x="195.2" y="434.8" textLength="36.6" clip-path="url(#terminal-1996000257-line-17)">BAR</text><text class="terminal-1996000257-r3" x="366" y="434.8" textLength="12.2" clip-path="url(#terminal-1996000257-line-17)">│</text><text class="terminal-1996000257-r2" x="976" y="434.8" textLength="12.2" clip-path="url(#terminal-1996000257-line-17)">
7110+
</text><text class="terminal-1996000257-r3" x="183" y="459.2" textLength="12.2" clip-path="url(#terminal-1996000257-line-18)">│</text><text class="terminal-1996000257-r4" x="195.2" y="459.2" textLength="36.6" clip-path="url(#terminal-1996000257-line-18)">BAZ</text><text class="terminal-1996000257-r3" x="366" y="459.2" textLength="12.2" clip-path="url(#terminal-1996000257-line-18)">│</text><text class="terminal-1996000257-r2" x="976" y="459.2" textLength="12.2" clip-path="url(#terminal-1996000257-line-18)">
7111+
</text><text class="terminal-1996000257-r3" x="183" y="483.6" textLength="195.2" clip-path="url(#terminal-1996000257-line-19)">└──────────────┘</text><text class="terminal-1996000257-r2" x="976" y="483.6" textLength="12.2" clip-path="url(#terminal-1996000257-line-19)">
7112+
</text><text class="terminal-1996000257-r2" x="976" y="508" textLength="12.2" clip-path="url(#terminal-1996000257-line-20)">
7113+
</text><text class="terminal-1996000257-r2" x="976" y="532.4" textLength="12.2" clip-path="url(#terminal-1996000257-line-21)">
7114+
</text><text class="terminal-1996000257-r2" x="976" y="556.8" textLength="12.2" clip-path="url(#terminal-1996000257-line-22)">
7115+
</text>
7116+
</g>
7117+
</g>
7118+
</svg>
7119+
7120+
'''
7121+
# ---
69657122
# name: test_order_independence
69667123
'''
69677124
<svg class="rich-terminal" viewBox="0 0 994 635.5999999999999" xmlns="http://www.w3.org/2000/svg">
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
from textual.app import App, ComposeResult
2+
from textual.containers import Vertical
3+
from textual.widgets import Label, Static
4+
5+
6+
class Box(Static):
7+
DEFAULT_CSS = """
8+
Box {
9+
border: solid white;
10+
background: darkblue;
11+
width: 16;
12+
height: auto;
13+
}
14+
"""
15+
16+
def compose(self) -> ComposeResult:
17+
yield Label("FOO\nBAR\nBAZ")
18+
19+
20+
class OffsetsApp(App):
21+
22+
CSS = """
23+
24+
#box1 {
25+
offset: 5 5;
26+
}
27+
28+
#box2 {
29+
offset: 15 10;
30+
}
31+
32+
"""
33+
34+
def compose(self) -> ComposeResult:
35+
yield Box(id="box1")
36+
yield Box(id="box2")
37+
38+
39+
if __name__ == "__main__":
40+
app = OffsetsApp()
41+
app.run()

tests/snapshot_tests/test_snapshots.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,11 @@ def test_columns_height(snap_compare):
151151
assert snap_compare("snapshot_apps/columns_height.py")
152152

153153

154+
def test_offsets(snap_compare):
155+
"""Test offsets of containers"""
156+
assert snap_compare("snapshot_apps/offsets.py")
157+
158+
154159
# --- Other ---
155160

156161

0 commit comments

Comments
 (0)