Skip to content

Commit

Permalink
Merge pull request #4317 from Textualize/button-width-fix
Browse files Browse the repository at this point in the history
Fixed auto-sizing of buttons in auto containers
  • Loading branch information
willmcgugan authored Mar 20, 2024
2 parents 3c3b66a + 4ff172a commit 9286175
Show file tree
Hide file tree
Showing 4 changed files with 192 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/textual/_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,7 @@ def get_content_width(self, widget: Widget, container: Size, viewport: Size) ->
if not widget._nodes:
width = 0
else:
# Use a size of 0, 0 to ignore relative sizes, since those are flexible anyway
arrangement = widget._arrange(Size(0, 0))
arrangement = widget._arrange(Size(container.width, 0))
return arrangement.total_region.right
return width

Expand Down
160 changes: 160 additions & 0 deletions tests/snapshot_tests/__snapshots__/test_snapshots.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -2161,6 +2161,166 @@

'''
# ---
# name: test_button_widths
'''
<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-898715-matrix {
font-family: Fira Code, monospace;
font-size: 20px;
line-height: 24.4px;
font-variant-east-asian: full-width;
}

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

.terminal-898715-r1 { fill: #ff0000 }
.terminal-898715-r2 { fill: #e1e1e1 }
.terminal-898715-r3 { fill: #c5c8c6 }
.terminal-898715-r4 { fill: #454a50 }
.terminal-898715-r5 { fill: #24292f;font-weight: bold }
.terminal-898715-r6 { fill: #000000 }
.terminal-898715-r7 { fill: #e2e3e3;font-weight: bold }
</style>

<defs>
<clipPath id="terminal-898715-clip-terminal">
<rect x="0" y="0" width="975.0" height="584.5999999999999" />
</clipPath>
<clipPath id="terminal-898715-line-0">
<rect x="0" y="1.5" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-898715-line-1">
<rect x="0" y="25.9" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-898715-line-2">
<rect x="0" y="50.3" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-898715-line-3">
<rect x="0" y="74.7" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-898715-line-4">
<rect x="0" y="99.1" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-898715-line-5">
<rect x="0" y="123.5" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-898715-line-6">
<rect x="0" y="147.9" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-898715-line-7">
<rect x="0" y="172.3" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-898715-line-8">
<rect x="0" y="196.7" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-898715-line-9">
<rect x="0" y="221.1" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-898715-line-10">
<rect x="0" y="245.5" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-898715-line-11">
<rect x="0" y="269.9" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-898715-line-12">
<rect x="0" y="294.3" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-898715-line-13">
<rect x="0" y="318.7" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-898715-line-14">
<rect x="0" y="343.1" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-898715-line-15">
<rect x="0" y="367.5" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-898715-line-16">
<rect x="0" y="391.9" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-898715-line-17">
<rect x="0" y="416.3" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-898715-line-18">
<rect x="0" y="440.7" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-898715-line-19">
<rect x="0" y="465.1" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-898715-line-20">
<rect x="0" y="489.5" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-898715-line-21">
<rect x="0" y="513.9" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-898715-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-898715-title" fill="#c5c8c6" text-anchor="middle" x="496" y="27">HorizontalWidthAutoApp</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-898715-clip-terminal)">
<rect fill="#1e1e1e" x="0" y="1.5" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="12.2" y="1.5" width="341.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="353.8" y="1.5" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="366" y="1.5" width="610" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="25.9" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#24292f" x="12.2" y="25.9" width="341.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="353.8" y="25.9" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="366" y="25.9" width="610" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="50.3" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#e2e3e3" x="12.2" y="50.3" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#e2e3e3" x="24.4" y="50.3" width="317.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#e2e3e3" x="341.6" y="50.3" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="353.8" y="50.3" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="366" y="50.3" width="610" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="74.7" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#24292f" x="12.2" y="74.7" width="341.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="353.8" y="74.7" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="366" y="74.7" width="610" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="99.1" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="12.2" y="99.1" width="341.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="353.8" y="99.1" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="366" y="99.1" width="610" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="123.5" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="12.2" y="123.5" width="683.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="695.4" y="123.5" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="707.6" y="123.5" width="268.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="147.9" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#24292f" x="12.2" y="147.9" width="341.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#24292f" x="353.8" y="147.9" width="341.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="695.4" y="147.9" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="707.6" y="147.9" width="268.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="172.3" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#24292f" x="12.2" y="172.3" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#24292f" x="24.4" y="172.3" width="317.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#24292f" x="341.6" y="172.3" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#24292f" x="353.8" y="172.3" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#24292f" x="366" y="172.3" width="317.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#24292f" x="683.2" y="172.3" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="695.4" y="172.3" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="707.6" y="172.3" width="268.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="196.7" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#24292f" x="12.2" y="196.7" width="341.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#24292f" x="353.8" y="196.7" width="341.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="695.4" y="196.7" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="707.6" y="196.7" width="268.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="221.1" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="12.2" y="221.1" width="683.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="695.4" y="221.1" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="707.6" y="221.1" width="268.4" 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="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="391.9" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="416.3" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="440.7" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="465.1" width="976" 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"/>
<g class="terminal-898715-matrix">
<text class="terminal-898715-r1" x="0" y="20" textLength="12.2" clip-path="url(#terminal-898715-line-0)">┌</text><text class="terminal-898715-r1" x="12.2" y="20" textLength="341.6" clip-path="url(#terminal-898715-line-0)">────────────────────────────</text><text class="terminal-898715-r1" x="353.8" y="20" textLength="12.2" clip-path="url(#terminal-898715-line-0)">┐</text><text class="terminal-898715-r3" x="976" y="20" textLength="12.2" clip-path="url(#terminal-898715-line-0)">
</text><text class="terminal-898715-r1" x="0" y="44.4" textLength="12.2" clip-path="url(#terminal-898715-line-1)">│</text><text class="terminal-898715-r4" x="12.2" y="44.4" textLength="341.6" clip-path="url(#terminal-898715-line-1)">▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔</text><text class="terminal-898715-r1" x="353.8" y="44.4" textLength="12.2" clip-path="url(#terminal-898715-line-1)">│</text><text class="terminal-898715-r3" x="976" y="44.4" textLength="12.2" clip-path="url(#terminal-898715-line-1)">
</text><text class="terminal-898715-r1" x="0" y="68.8" textLength="12.2" clip-path="url(#terminal-898715-line-2)">│</text><text class="terminal-898715-r5" x="24.4" y="68.8" textLength="317.2" clip-path="url(#terminal-898715-line-2)">This&#160;is&#160;a&#160;very&#160;wide&#160;button</text><text class="terminal-898715-r1" x="353.8" y="68.8" textLength="12.2" clip-path="url(#terminal-898715-line-2)">│</text><text class="terminal-898715-r3" x="976" y="68.8" textLength="12.2" clip-path="url(#terminal-898715-line-2)">
</text><text class="terminal-898715-r1" x="0" y="93.2" textLength="12.2" clip-path="url(#terminal-898715-line-3)">│</text><text class="terminal-898715-r6" x="12.2" y="93.2" textLength="341.6" clip-path="url(#terminal-898715-line-3)">▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁</text><text class="terminal-898715-r1" x="353.8" y="93.2" textLength="12.2" clip-path="url(#terminal-898715-line-3)">│</text><text class="terminal-898715-r3" x="976" y="93.2" textLength="12.2" clip-path="url(#terminal-898715-line-3)">
</text><text class="terminal-898715-r1" x="0" y="117.6" textLength="12.2" clip-path="url(#terminal-898715-line-4)">└</text><text class="terminal-898715-r1" x="12.2" y="117.6" textLength="341.6" clip-path="url(#terminal-898715-line-4)">────────────────────────────</text><text class="terminal-898715-r1" x="353.8" y="117.6" textLength="12.2" clip-path="url(#terminal-898715-line-4)">┘</text><text class="terminal-898715-r3" x="976" y="117.6" textLength="12.2" clip-path="url(#terminal-898715-line-4)">
</text><text class="terminal-898715-r1" x="0" y="142" textLength="12.2" clip-path="url(#terminal-898715-line-5)">┌</text><text class="terminal-898715-r1" x="12.2" y="142" textLength="683.2" clip-path="url(#terminal-898715-line-5)">────────────────────────────────────────────────────────</text><text class="terminal-898715-r1" x="695.4" y="142" textLength="12.2" clip-path="url(#terminal-898715-line-5)">┐</text><text class="terminal-898715-r3" x="976" y="142" textLength="12.2" clip-path="url(#terminal-898715-line-5)">
</text><text class="terminal-898715-r1" x="0" y="166.4" textLength="12.2" clip-path="url(#terminal-898715-line-6)">│</text><text class="terminal-898715-r4" x="12.2" y="166.4" textLength="341.6" clip-path="url(#terminal-898715-line-6)">▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔</text><text class="terminal-898715-r4" x="353.8" y="166.4" textLength="341.6" clip-path="url(#terminal-898715-line-6)">▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔</text><text class="terminal-898715-r1" x="695.4" y="166.4" textLength="12.2" clip-path="url(#terminal-898715-line-6)">│</text><text class="terminal-898715-r3" x="976" y="166.4" textLength="12.2" clip-path="url(#terminal-898715-line-6)">
</text><text class="terminal-898715-r1" x="0" y="190.8" textLength="12.2" clip-path="url(#terminal-898715-line-7)">│</text><text class="terminal-898715-r7" x="24.4" y="190.8" textLength="317.2" clip-path="url(#terminal-898715-line-7)">This&#160;is&#160;a&#160;very&#160;wide&#160;button</text><text class="terminal-898715-r7" x="366" y="190.8" textLength="317.2" clip-path="url(#terminal-898715-line-7)">This&#160;is&#160;a&#160;very&#160;wide&#160;button</text><text class="terminal-898715-r1" x="695.4" y="190.8" textLength="12.2" clip-path="url(#terminal-898715-line-7)">│</text><text class="terminal-898715-r3" x="976" y="190.8" textLength="12.2" clip-path="url(#terminal-898715-line-7)">
</text><text class="terminal-898715-r1" x="0" y="215.2" textLength="12.2" clip-path="url(#terminal-898715-line-8)">│</text><text class="terminal-898715-r6" x="12.2" y="215.2" textLength="341.6" clip-path="url(#terminal-898715-line-8)">▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁</text><text class="terminal-898715-r6" x="353.8" y="215.2" textLength="341.6" clip-path="url(#terminal-898715-line-8)">▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁</text><text class="terminal-898715-r1" x="695.4" y="215.2" textLength="12.2" clip-path="url(#terminal-898715-line-8)">│</text><text class="terminal-898715-r3" x="976" y="215.2" textLength="12.2" clip-path="url(#terminal-898715-line-8)">
</text><text class="terminal-898715-r1" x="0" y="239.6" textLength="12.2" clip-path="url(#terminal-898715-line-9)">└</text><text class="terminal-898715-r1" x="12.2" y="239.6" textLength="683.2" clip-path="url(#terminal-898715-line-9)">────────────────────────────────────────────────────────</text><text class="terminal-898715-r1" x="695.4" y="239.6" textLength="12.2" clip-path="url(#terminal-898715-line-9)">┘</text><text class="terminal-898715-r3" x="976" y="239.6" textLength="12.2" clip-path="url(#terminal-898715-line-9)">
</text><text class="terminal-898715-r3" x="976" y="264" textLength="12.2" clip-path="url(#terminal-898715-line-10)">
</text><text class="terminal-898715-r3" x="976" y="288.4" textLength="12.2" clip-path="url(#terminal-898715-line-11)">
</text><text class="terminal-898715-r3" x="976" y="312.8" textLength="12.2" clip-path="url(#terminal-898715-line-12)">
</text><text class="terminal-898715-r3" x="976" y="337.2" textLength="12.2" clip-path="url(#terminal-898715-line-13)">
</text><text class="terminal-898715-r3" x="976" y="361.6" textLength="12.2" clip-path="url(#terminal-898715-line-14)">
</text><text class="terminal-898715-r3" x="976" y="386" textLength="12.2" clip-path="url(#terminal-898715-line-15)">
</text><text class="terminal-898715-r3" x="976" y="410.4" textLength="12.2" clip-path="url(#terminal-898715-line-16)">
</text><text class="terminal-898715-r3" x="976" y="434.8" textLength="12.2" clip-path="url(#terminal-898715-line-17)">
</text><text class="terminal-898715-r3" x="976" y="459.2" textLength="12.2" clip-path="url(#terminal-898715-line-18)">
</text><text class="terminal-898715-r3" x="976" y="483.6" textLength="12.2" clip-path="url(#terminal-898715-line-19)">
</text><text class="terminal-898715-r3" x="976" y="508" textLength="12.2" clip-path="url(#terminal-898715-line-20)">
</text><text class="terminal-898715-r3" x="976" y="532.4" textLength="12.2" clip-path="url(#terminal-898715-line-21)">
</text><text class="terminal-898715-r3" x="976" y="556.8" textLength="12.2" clip-path="url(#terminal-898715-line-22)">
</text>
</g>
</g>
</svg>

'''
# ---
# name: test_buttons_render
'''
<svg class="rich-terminal" viewBox="0 0 994 635.5999999999999" xmlns="http://www.w3.org/2000/svg">
Expand Down
Loading

0 comments on commit 9286175

Please sign in to comment.