Skip to content

Commit

Permalink
fix gutter
Browse files Browse the repository at this point in the history
  • Loading branch information
willmcgugan committed May 19, 2024
1 parent 99235b0 commit 236d839
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 52 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [0.61.1] - 202405-19

### Fixed

- Fixed auto grid columns ignoring gutter https://github.com/Textualize/textual/issues/4522

## [0.61.0] - 2024-05-18

### Added
Expand Down Expand Up @@ -1966,6 +1972,7 @@ https://textual.textualize.io/blog/2022/11/08/version-040/#version-040
- New handler system for messages that doesn't require inheritance
- Improved traceback handling

[0.61.1]: https://github.com/Textualize/textual/compare/v0.61.0...v0.61.1
[0.61.0]: https://github.com/Textualize/textual/compare/v0.60.1...v0.61.0
[0.60.1]: https://github.com/Textualize/textual/compare/v0.60.0...v0.60.1
[0.60.0]: https://github.com/Textualize/textual/compare/v0.59.0...v0.60.0
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "textual"
version = "0.61.0"
version = "0.61.1"
homepage = "https://github.com/Textualize/textual"
repository = "https://github.com/Textualize/textual"
documentation = "https://textual.textualize.io/"
Expand Down
49 changes: 0 additions & 49 deletions src/textual/fuzzy.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,52 +114,3 @@ def highlight(self, candidate: str) -> Text:
text.stylize(self._match_style, offset, offset + 1)

return text


if __name__ == "__main__":
from itertools import permutations
from string import ascii_lowercase
from time import monotonic

from rich import print
from rich.rule import Rule

matcher = Matcher("foo.bar")
print(Rule())
print("Query is:", matcher.query)
print("Rule is:", matcher.query_pattern)
print(Rule())
candidates = (
"foo.bar",
" foo.bar ",
"Hello foo.bar world",
"f o o . b a r",
"f o o .bar",
"foo. b a r",
"Lots of text before the foo.bar",
"foo.bar up front and then lots of text afterwards",
"This has an o in it but does not have a match",
"Let's find one obvious match. But blat around always roughly.",
)
results = sorted(
[
(matcher.match(candidate), matcher.highlight(candidate))
for candidate in candidates
],
key=lambda pair: pair[0],
reverse=True,
)
for score, highlight in results:
print(f"{score:.15f} '", highlight, "'", sep="")
print(Rule())

RUNS = 5
candidates = [
"".join(permutation) for permutation in permutations(ascii_lowercase[:10])
]
matcher = Matcher(ascii_lowercase[:10])
start = monotonic()
for _ in range(RUNS):
for candidate in candidates:
_ = matcher.match(candidate)
print(f"{RUNS * len(candidates)} matches in {monotonic() - start:.5f} seconds")
5 changes: 3 additions & 2 deletions src/textual/layouts/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,15 @@ def apply_height_limits(widget: Widget, height: int) -> int:
if widget.styles.row_span != 1:
continue
column_width = columns[column][1]
gutter_width, gutter_height = widget.styles.gutter.totals
widget_height = apply_height_limits(
widget,
widget.get_content_height(
size,
viewport,
column_width,
column_width - gutter_width,
)
+ widget.styles.gutter.height,
+ gutter_height,
)
height = max(height, widget_height)
row_scalars[row] = Scalar.from_number(height)
Expand Down
42 changes: 42 additions & 0 deletions tests/snapshot_tests/snapshot_apps/grid_gutter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from rich.markdown import Markdown
from textual.app import App, ComposeResult
from textual.containers import Grid, Vertical
from textual.widgets import Label, TabbedContent, TabPane


class FooApp(App):
TITLE = "Demonstrator"

CSS = """
Screen {
align: center middle;
}
#root {
width: 60;
height: 20;
border: solid $accent;
}
.info-container {
grid-rows: auto;
}
.value {
padding: 0 2;
border: tall $background;
}
"""

def compose(self) -> ComposeResult:
with Vertical(id="root"):
with TabbedContent():
with TabPane("Information"):
with Grid(classes="info-container"):
yield Label(Markdown(long_text()), classes="value")


def long_text() -> str:
return 'aaa naa aaaaa aaa aaaan, aaa\naaa, aaaa?", aa aaa aaaaanaaa *anaaaaaaana* aaaaaaaa aaaaaana aaa aaaaa aa\naaa, aa *aaaaaaaaa* aaa aaaa, "aaaa, an *aaaa* aaa aaaa, a aa". "aaaa, naa\naaaaaaaaaaa, aaa a aaaa aaaaaanaa aaaa aa a aaa!", aaa anaaaa, aaaaa\naaaaaaaa aanaaaaa. "Na! aaa naa. aaaaa. aa aaaaa naa. aaaaa aa na aaa.",\naaa aaaaaaaa aaaanaaaaa DONE.\n'


if __name__ == "__main__":
FooApp().run()
5 changes: 5 additions & 0 deletions tests/snapshot_tests/test_snapshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -1259,3 +1259,8 @@ def test_dynamic_bindings(snap_compare):
assert snap_compare(
SNAPSHOT_APPS_DIR / "dynamic_bindings.py", press=["a", "b", "c"]
)


def test_grid_gutter(snap_compare):
# https://github.com/Textualize/textual/issues/4522
assert snap_compare(SNAPSHOT_APPS_DIR / "grid_gutter.py")

0 comments on commit 236d839

Please sign in to comment.