Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Toggle style order #4752

Merged
merged 3 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/textual/widgets/_toggle_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ def _make_label(self, label: TextType) -> Text:
label = label.split()[0]
except IndexError:
pass

return label

@property
Expand Down Expand Up @@ -216,7 +217,9 @@ def render(self) -> RenderResult:
"""
button = self._button
label = self._label.copy()
label.stylize(self.get_component_rich_style("toggle--label", partial=True))
label.stylize_before(
self.get_component_rich_style("toggle--label", partial=True)
)
spacer = " " if label else ""
return Text.assemble(
*(
Expand Down
164 changes: 164 additions & 0 deletions tests/snapshot_tests/__snapshots__/test_snapshots.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -48054,6 +48054,170 @@

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

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

.terminal-1573700058-r1 { fill: #1e1e1e }
.terminal-1573700058-r2 { fill: #0178d4 }
.terminal-1573700058-r3 { fill: #e1e1e1 }
.terminal-1573700058-r4 { fill: #c5c8c6 }
.terminal-1573700058-r5 { fill: #575757 }
.terminal-1573700058-r6 { fill: #262626;font-weight: bold }
.terminal-1573700058-r7 { fill: #e2e2e2 }
.terminal-1573700058-r8 { fill: #f4005f;font-weight: bold;text-decoration: underline; }
.terminal-1573700058-r9 { fill: #ffffff;text-decoration: underline; }
.terminal-1573700058-r10 { fill: #f4005f;font-weight: bold }
.terminal-1573700058-r11 { fill: #8e8e8e }
</style>

<defs>
<clipPath id="terminal-1573700058-clip-terminal">
<rect x="0" y="0" width="975.0" height="584.5999999999999" />
</clipPath>
<clipPath id="terminal-1573700058-line-0">
<rect x="0" y="1.5" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-1573700058-line-1">
<rect x="0" y="25.9" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-1573700058-line-2">
<rect x="0" y="50.3" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-1573700058-line-3">
<rect x="0" y="74.7" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-1573700058-line-4">
<rect x="0" y="99.1" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-1573700058-line-5">
<rect x="0" y="123.5" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-1573700058-line-6">
<rect x="0" y="147.9" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-1573700058-line-7">
<rect x="0" y="172.3" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-1573700058-line-8">
<rect x="0" y="196.7" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-1573700058-line-9">
<rect x="0" y="221.1" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-1573700058-line-10">
<rect x="0" y="245.5" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-1573700058-line-11">
<rect x="0" y="269.9" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-1573700058-line-12">
<rect x="0" y="294.3" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-1573700058-line-13">
<rect x="0" y="318.7" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-1573700058-line-14">
<rect x="0" y="343.1" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-1573700058-line-15">
<rect x="0" y="367.5" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-1573700058-line-16">
<rect x="0" y="391.9" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-1573700058-line-17">
<rect x="0" y="416.3" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-1573700058-line-18">
<rect x="0" y="440.7" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-1573700058-line-19">
<rect x="0" y="465.1" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-1573700058-line-20">
<rect x="0" y="489.5" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-1573700058-line-21">
<rect x="0" y="513.9" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-1573700058-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-1573700058-title" fill="#c5c8c6" text-anchor="middle" x="496" y="27">CheckboxApp</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-1573700058-clip-terminal)">
<rect fill="#0178d4" x="0" y="1.5" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#262626" x="12.2" y="1.5" width="353.8" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="366" y="1.5" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="378.2" y="1.5" width="597.8" height="24.65" shape-rendering="crispEdges"/><rect fill="#0178d4" x="0" y="25.9" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#262626" x="12.2" y="25.9" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#262626" x="24.4" y="25.9" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#575757" x="36.6" y="25.9" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#262626" x="48.8" y="25.9" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#262626" x="61" y="25.9" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#262626" x="73.2" y="25.9" width="146.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#262626" x="219.6" y="25.9" width="134.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#262626" x="353.8" y="25.9" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="366" y="25.9" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="378.2" y="25.9" width="597.8" height="24.65" shape-rendering="crispEdges"/><rect fill="#0178d4" x="0" y="50.3" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#262626" x="12.2" y="50.3" width="353.8" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="366" y="50.3" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="378.2" y="50.3" width="597.8" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="74.7" width="146.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="146.4" y="74.7" width="134.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="280.6" y="74.7" width="695.4" 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="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="147.9" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="172.3" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="196.7" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="221.1" width="976" 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-1573700058-matrix">
<text class="terminal-1573700058-r1" x="0" y="20" textLength="12.2" clip-path="url(#terminal-1573700058-line-0)">▊</text><text class="terminal-1573700058-r2" x="12.2" y="20" textLength="353.8" clip-path="url(#terminal-1573700058-line-0)">▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔</text><text class="terminal-1573700058-r2" x="366" y="20" textLength="12.2" clip-path="url(#terminal-1573700058-line-0)">▎</text><text class="terminal-1573700058-r4" x="976" y="20" textLength="12.2" clip-path="url(#terminal-1573700058-line-0)">
</text><text class="terminal-1573700058-r1" x="0" y="44.4" textLength="12.2" clip-path="url(#terminal-1573700058-line-1)">▊</text><text class="terminal-1573700058-r5" x="24.4" y="44.4" textLength="12.2" clip-path="url(#terminal-1573700058-line-1)">▐</text><text class="terminal-1573700058-r6" x="36.6" y="44.4" textLength="12.2" clip-path="url(#terminal-1573700058-line-1)">X</text><text class="terminal-1573700058-r5" x="48.8" y="44.4" textLength="12.2" clip-path="url(#terminal-1573700058-line-1)">▌</text><text class="terminal-1573700058-r8" x="73.2" y="44.4" textLength="146.4" clip-path="url(#terminal-1573700058-line-1)">This&#160;is&#160;just</text><text class="terminal-1573700058-r9" x="219.6" y="44.4" textLength="134.2" clip-path="url(#terminal-1573700058-line-1)">&#160;some&#160;text.</text><text class="terminal-1573700058-r2" x="366" y="44.4" textLength="12.2" clip-path="url(#terminal-1573700058-line-1)">▎</text><text class="terminal-1573700058-r4" x="976" y="44.4" textLength="12.2" clip-path="url(#terminal-1573700058-line-1)">
</text><text class="terminal-1573700058-r1" x="0" y="68.8" textLength="12.2" clip-path="url(#terminal-1573700058-line-2)">▊</text><text class="terminal-1573700058-r2" x="12.2" y="68.8" textLength="353.8" clip-path="url(#terminal-1573700058-line-2)">▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁</text><text class="terminal-1573700058-r2" x="366" y="68.8" textLength="12.2" clip-path="url(#terminal-1573700058-line-2)">▎</text><text class="terminal-1573700058-r4" x="976" y="68.8" textLength="12.2" clip-path="url(#terminal-1573700058-line-2)">
</text><text class="terminal-1573700058-r10" x="0" y="93.2" textLength="146.4" clip-path="url(#terminal-1573700058-line-3)">This&#160;is&#160;just</text><text class="terminal-1573700058-r11" x="146.4" y="93.2" textLength="134.2" clip-path="url(#terminal-1573700058-line-3)">&#160;some&#160;text.</text><text class="terminal-1573700058-r4" x="976" y="93.2" textLength="12.2" clip-path="url(#terminal-1573700058-line-3)">
</text><text class="terminal-1573700058-r4" x="976" y="117.6" textLength="12.2" clip-path="url(#terminal-1573700058-line-4)">
</text><text class="terminal-1573700058-r4" x="976" y="142" textLength="12.2" clip-path="url(#terminal-1573700058-line-5)">
</text><text class="terminal-1573700058-r4" x="976" y="166.4" textLength="12.2" clip-path="url(#terminal-1573700058-line-6)">
</text><text class="terminal-1573700058-r4" x="976" y="190.8" textLength="12.2" clip-path="url(#terminal-1573700058-line-7)">
</text><text class="terminal-1573700058-r4" x="976" y="215.2" textLength="12.2" clip-path="url(#terminal-1573700058-line-8)">
</text><text class="terminal-1573700058-r4" x="976" y="239.6" textLength="12.2" clip-path="url(#terminal-1573700058-line-9)">
</text><text class="terminal-1573700058-r4" x="976" y="264" textLength="12.2" clip-path="url(#terminal-1573700058-line-10)">
</text><text class="terminal-1573700058-r4" x="976" y="288.4" textLength="12.2" clip-path="url(#terminal-1573700058-line-11)">
</text><text class="terminal-1573700058-r4" x="976" y="312.8" textLength="12.2" clip-path="url(#terminal-1573700058-line-12)">
</text><text class="terminal-1573700058-r4" x="976" y="337.2" textLength="12.2" clip-path="url(#terminal-1573700058-line-13)">
</text><text class="terminal-1573700058-r4" x="976" y="361.6" textLength="12.2" clip-path="url(#terminal-1573700058-line-14)">
</text><text class="terminal-1573700058-r4" x="976" y="386" textLength="12.2" clip-path="url(#terminal-1573700058-line-15)">
</text><text class="terminal-1573700058-r4" x="976" y="410.4" textLength="12.2" clip-path="url(#terminal-1573700058-line-16)">
</text><text class="terminal-1573700058-r4" x="976" y="434.8" textLength="12.2" clip-path="url(#terminal-1573700058-line-17)">
</text><text class="terminal-1573700058-r4" x="976" y="459.2" textLength="12.2" clip-path="url(#terminal-1573700058-line-18)">
</text><text class="terminal-1573700058-r4" x="976" y="483.6" textLength="12.2" clip-path="url(#terminal-1573700058-line-19)">
</text><text class="terminal-1573700058-r4" x="976" y="508" textLength="12.2" clip-path="url(#terminal-1573700058-line-20)">
</text><text class="terminal-1573700058-r4" x="976" y="532.4" textLength="12.2" clip-path="url(#terminal-1573700058-line-21)">
</text><text class="terminal-1573700058-r4" x="976" y="556.8" textLength="12.2" clip-path="url(#terminal-1573700058-line-22)">
</text>
</g>
</g>
</svg>

'''
# ---
# name: test_tooltips_in_compound_widgets
'''
<svg class="rich-terminal" viewBox="0 0 994 635.5999999999999" xmlns="http://www.w3.org/2000/svg">
Expand Down
19 changes: 19 additions & 0 deletions tests/snapshot_tests/snapshot_apps/toggle_style_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from textual.app import App
from textual.widgets import Checkbox, Label


class CheckboxApp(App):
CSS = """
Checkbox > .toggle--label, Label {
color: white;
text-opacity: 50%;
}
"""

def compose(self):
yield Checkbox("[red bold]This is just[/] some text.")
yield Label("[red bold]This is just[/] some text.")


if __name__ == "__main__":
CheckboxApp().run()
4 changes: 4 additions & 0 deletions tests/snapshot_tests/test_snapshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -1329,7 +1329,11 @@ async def run_before(pilot: Pilot) -> None:
SNAPSHOT_APPS_DIR / "programmatic_disable_button.py", run_before=run_before
)

def test_toggle_style_order(snap_compare):
"""Regression test for https://github.com/Textualize/textual/issues/3421"""
assert snap_compare(SNAPSHOT_APPS_DIR / "toggle_style_order.py")

def test_component_text_opacity(snap_compare):
"""Regression test for https://github.com/Textualize/textual/issues/3413"""
assert snap_compare(SNAPSHOT_APPS_DIR / "component_text_opacity.py")

Loading