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

Grid gutter fix #4219

Merged
merged 2 commits into from
Feb 26, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Simplified tree-sitter highlight queries for HTML, which also seems to fix segfault issue https://github.com/Textualize/textual/pull/4195
- Fixed `DirectoryTree.path` no longer reacting to new values https://github.com/Textualize/textual/issues/4208
- Fixed content size cache with Pretty widget https://github.com/Textualize/textual/pull/4211
- Fixed `grid-gutter` interaction with Pretty widget https://github.com/Textualize/textual/pull/4219

## [0.52.1] - 2024-02-20

Expand Down
2 changes: 1 addition & 1 deletion src/textual/layouts/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def apply_height_limits(widget: Widget, height: int) -> int:
widget.get_content_height(
size,
viewport,
column_width - parent.styles.grid_gutter_vertical,
column_width,
)
+ widget.styles.gutter.height,
)
Expand Down
91 changes: 91 additions & 0 deletions tests/snapshot_tests/__snapshots__/test_snapshots.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -27297,6 +27297,97 @@

'''
# ---
# name: test_pretty_grid_gutter_interaction
'''
<svg class="rich-terminal" viewBox="0 0 1007 220.79999999999998" 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-4031343223-matrix {
font-family: Fira Code, monospace;
font-size: 20px;
line-height: 24.4px;
font-variant-east-asian: full-width;
}

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

.terminal-4031343223-r1 { fill: #ffdddd;font-weight: bold }
.terminal-4031343223-r2 { fill: #879a3b }
.terminal-4031343223-r3 { fill: #ddeedd }
.terminal-4031343223-r4 { fill: #c5c8c6 }
.terminal-4031343223-r5 { fill: #ddddff }
.terminal-4031343223-r6 { fill: #e1e1e1 }
</style>

<defs>
<clipPath id="terminal-4031343223-clip-terminal">
<rect x="0" y="0" width="987.1999999999999" height="169.79999999999998" />
</clipPath>
<clipPath id="terminal-4031343223-line-0">
<rect x="0" y="1.5" width="988.2" height="24.65"/>
</clipPath>
<clipPath id="terminal-4031343223-line-1">
<rect x="0" y="25.9" width="988.2" height="24.65"/>
</clipPath>
<clipPath id="terminal-4031343223-line-2">
<rect x="0" y="50.3" width="988.2" height="24.65"/>
</clipPath>
<clipPath id="terminal-4031343223-line-3">
<rect x="0" y="74.7" width="988.2" height="24.65"/>
</clipPath>
<clipPath id="terminal-4031343223-line-4">
<rect x="0" y="99.1" width="988.2" height="24.65"/>
</clipPath>
<clipPath id="terminal-4031343223-line-5">
<rect x="0" y="123.5" width="988.2" height="24.65"/>
</clipPath>
</defs>

<rect fill="#292929" stroke="rgba(255,255,255,0.35)" stroke-width="1" x="1" y="1" width="1005" height="218.8" rx="8"/><text class="terminal-4031343223-title" fill="#c5c8c6" text-anchor="middle" x="502" y="27">MyApp</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-4031343223-clip-terminal)">
<rect fill="#ff0000" x="0" y="1.5" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#ff0000" x="12.2" y="1.5" width="463.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#ff0000" x="475.8" y="1.5" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#008000" x="488" y="1.5" width="500.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#008000" x="0" y="25.9" width="988.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#0000ff" x="0" y="50.3" width="402.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#008000" x="402.6" y="50.3" width="585.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="74.7" width="988.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="99.1" width="988.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="123.5" width="988.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="147.9" width="988.2" height="24.65" shape-rendering="crispEdges"/>
<g class="terminal-4031343223-matrix">
<text class="terminal-4031343223-r1" x="0" y="20" textLength="12.2" clip-path="url(#terminal-4031343223-line-0)">[</text><text class="terminal-4031343223-r2" x="12.2" y="20" textLength="463.6" clip-path="url(#terminal-4031343223-line-0)">&#x27;This&#160;is&#160;a&#160;string&#160;that&#160;has&#160;some&#160;chars&#x27;</text><text class="terminal-4031343223-r1" x="475.8" y="20" textLength="12.2" clip-path="url(#terminal-4031343223-line-0)">]</text><text class="terminal-4031343223-r4" x="988.2" y="20" textLength="12.2" clip-path="url(#terminal-4031343223-line-0)">
</text><text class="terminal-4031343223-r4" x="988.2" y="44.4" textLength="12.2" clip-path="url(#terminal-4031343223-line-1)">
</text><text class="terminal-4031343223-r5" x="0" y="68.8" textLength="402.6" clip-path="url(#terminal-4031343223-line-2)">This&#160;should&#160;be&#160;1&#160;cell&#160;away&#160;from&#160;^</text><text class="terminal-4031343223-r4" x="988.2" y="68.8" textLength="12.2" clip-path="url(#terminal-4031343223-line-2)">
</text><text class="terminal-4031343223-r4" x="988.2" y="93.2" textLength="12.2" clip-path="url(#terminal-4031343223-line-3)">
</text><text class="terminal-4031343223-r4" x="988.2" y="117.6" textLength="12.2" clip-path="url(#terminal-4031343223-line-4)">
</text><text class="terminal-4031343223-r4" x="988.2" y="142" textLength="12.2" clip-path="url(#terminal-4031343223-line-5)">
</text>
</g>
</g>
</svg>

'''
# ---
# name: test_print_capture
'''
<svg class="rich-terminal" viewBox="0 0 994 635.5999999999999" xmlns="http://www.w3.org/2000/svg">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""App used as regression test for https://github.com/Textualize/textual/pull/4219."""

from __future__ import annotations

from textual.app import App, ComposeResult
from textual.containers import Grid
from textual.widgets import Pretty, Label


class MyGrid(Grid):
"""A simple grid with 2 columns and 2 rows."""


class MyApp(App[None]):
DEFAULT_CSS = """
MyGrid {
height: auto;
grid-rows: auto;
grid-size: 2;
grid-gutter: 1;
background: green;
}

Pretty {
background: red;
}

Label {
background: blue;
}
"""

def compose(self) -> ComposeResult:
with MyGrid():
yield Pretty(["This is a string that has some chars"])
yield Label()
yield Label("This should be 1 cell away from ^")


if __name__ == "__main__":
MyApp().run()
11 changes: 10 additions & 1 deletion tests/snapshot_tests/test_snapshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,9 @@ async def run_before(pilot) -> None:
pilot.app.screen.query_one(Input).cursor_blink = False
await pilot.app.screen.workers.wait_for_complete()

assert snap_compare(SNAPSHOT_APPS_DIR / "command_palette_discovery.py", run_before=run_before)
assert snap_compare(
SNAPSHOT_APPS_DIR / "command_palette_discovery.py", run_before=run_before
)


# --- textual-dev library preview tests ---
Expand Down Expand Up @@ -1052,3 +1054,10 @@ def test_input_percentage_width(snap_compare):
"""Check percentage widths work correctly."""
# https://github.com/Textualize/textual/issues/3721
assert snap_compare(SNAPSHOT_APPS_DIR / "input_percentage_width.py")


def test_pretty_grid_gutter_interaction(snap_compare):
"""Regression test for https://github.com/Textualize/textual/pull/4219."""
assert snap_compare(
SNAPSHOT_APPS_DIR / "pretty_grid_gutter_interaction.py", terminal_size=(81, 7)
)
Loading