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

fix(footer): enable spacing between key and description #4651

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
f83a905
fix(footer): enable padding between key and description
TomJGooding Jun 14, 2024
b78b23e
add snapshot test for compact footer
TomJGooding Jun 18, 2024
61add04
change space between key and description to margin
TomJGooding Jun 21, 2024
1a26506
change hardcoded key padding to component CSS
TomJGooding Jun 21, 2024
f9fa144
simplify space between FooterKeys to grid gutter
TomJGooding Jun 21, 2024
36ecb04
update snapshot tests that contain a footer
TomJGooding Jun 21, 2024
1cf34fd
simplify by removing now unnecessary if/else
TomJGooding Jun 21, 2024
122adff
tweak regression test docstring wording
TomJGooding Jun 21, 2024
1a1f44f
Merge branch 'main' into fix-footer-enable-padding-between-key-and-de…
TomJGooding Jun 21, 2024
b0076d1
update changelog
TomJGooding Jun 21, 2024
ab24e6f
Revert "update snapshot tests that contain a footer"
TomJGooding Jun 27, 2024
ddb45c0
Merge branch 'main' into fix-footer-enable-padding-between-key-and-de…
TomJGooding Jun 27, 2024
5a19ab0
Merge branch 'main' of github.com:Textualize/textual into fix-footer-…
darrenburns Jul 11, 2024
3dd8afd
Update snapshots using latest Textual version.
darrenburns Jul 11, 2024
d1064bb
update the changelog
TomJGooding Jul 11, 2024
a5363aa
fix sizing issue by setting reactive layout
TomJGooding Jul 11, 2024
d4d684a
revert grid-gutter change
TomJGooding Jul 11, 2024
dcaa33d
change key margin to description padding
TomJGooding Jul 11, 2024
8fdd51b
add footer hover snapshot tests
TomJGooding Jul 11, 2024
79d2de8
update snapshots
TomJGooding Jul 11, 2024
3f2c7de
update changelog description
TomJGooding Jul 11, 2024
6b1fa48
remove old commented out code
TomJGooding Jul 11, 2024
ae8c1ca
remove now unnecessary reactive layout update
TomJGooding Jul 11, 2024
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

- "Discover" hits in the command palette are no longer sorted alphabetically https://github.com/Textualize/textual/pull/4720

### Added

- Added `Footer` component style handling of padding for the key/description https://github.com/Textualize/textual/pull/4651

## [0.72.0] - 2024-07-09

### Changed
Expand All @@ -42,7 +46,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Fixed link inside markdown table not posting a `Markdown.LinkClicked` message https://github.com/Textualize/textual/issues/4683
- Fixed issue with mouse movements on non-active screen https://github.com/Textualize/textual/pull/4688


## [0.70.0] - 2024-06-19

### Fixed
Expand Down
37 changes: 29 additions & 8 deletions src/textual/widgets/_footer.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ class FooterKey(Widget):
color: $secondary;
background: $panel;
text-style: bold;
padding: 0 1;
}

.footer-key--description {
padding: 0 1 0 0;
}

&:light .footer-key--key {
Expand All @@ -57,6 +62,14 @@ class FooterKey(Widget):
}
}

&.-compact {
.footer-key--key {
padding: 0;
}
.footer-key--description {
padding: 0 0 0 1;
}
}
}
"""

Expand All @@ -83,19 +96,27 @@ def render(self) -> Text:
key_style = self.get_component_rich_style("footer-key--key")
description_style = self.get_component_rich_style("footer-key--description")
key_display = self.key_display
key_padding = self.get_component_styles("footer-key--key").padding
description_padding = self.get_component_styles(
"footer-key--description"
).padding
if self.upper_case_keys:
key_display = key_display.upper()
if self.ctrl_to_caret and key_display.lower().startswith("ctrl+"):
key_display = "^" + key_display.split("+", 1)[1]
description = self.description
if self.compact:
label_text = Text.assemble(
(key_display, key_style), " ", (description, description_style)
)
else:
label_text = Text.assemble(
(f" {key_display} ", key_style), (description, description_style), " "
)
label_text = Text.assemble(
(
" " * key_padding.left + key_display + " " * key_padding.right,
key_style,
),
(
" " * description_padding.left
+ description
+ " " * description_padding.right,
description_style,
),
)
label_text.stylize_before(self.rich_style)
return label_text

Expand Down
791 changes: 791 additions & 0 deletions tests/snapshot_tests/__snapshots__/test_snapshots.ambr

Large diffs are not rendered by default.

50 changes: 50 additions & 0 deletions tests/snapshot_tests/snapshot_apps/footer_classic_styling.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from textual.app import App, ComposeResult
from textual.widgets import Footer


class ClassicFooterStylingApp(App):
"""
This app attempts to replicate the styling of the classic footer in
Textual before v0.63.0, in particular the distinct background color
for the binding keys and spacing between the key and binding description.
Regression test for https://github.com/Textualize/textual/issues/4557
"""

CSS = """
Footer {
background: $accent;
FooterKey {
background: $accent;
color: $text;
.footer-key--key {
background: $accent-darken-2;
color: $text;
}
.footer-key--description {
padding: 0 1;
}
}
}
"""

BINDINGS = [
("ctrl+t", "app.toggle_dark", "Toggle Dark mode"),
("ctrl+q", "quit", "Quit"),
]

def compose(self) -> ComposeResult:
yield Footer()

def on_mount(self) -> None:
footer = self.query_one(Footer)
footer.upper_case_keys = True
footer.ctrl_to_caret = False


if __name__ == "__main__":
app = ClassicFooterStylingApp()
app.run()
34 changes: 34 additions & 0 deletions tests/snapshot_tests/snapshot_apps/footer_toggle_compact.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from textual.app import App, ComposeResult
from textual.widgets import Footer, Label


class ToggleCompactFooterApp(App):
CSS = """
Screen {
align: center middle;
}
"""

BINDINGS = [
("ctrl+t", "toggle_compact_footer", "Toggle Compact Footer"),
("ctrl+q", "quit", "Quit"),
]

def compose(self) -> ComposeResult:
yield Label("Compact Footer")
yield Footer()

def on_mount(self) -> None:
footer = self.query_one(Footer)
footer.compact = True

def action_toggle_compact_footer(self) -> None:
footer = self.query_one(Footer)
footer.compact = not footer.compact
footer_type = "Compact" if footer.compact else "Standard"
self.query_one(Label).update(f"{footer_type} Footer")


if __name__ == "__main__":
app = ToggleCompactFooterApp()
app.run()
40 changes: 40 additions & 0 deletions tests/snapshot_tests/test_snapshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -1296,6 +1296,46 @@ def test_grid_auto(snap_compare):
assert snap_compare(SNAPSHOT_APPS_DIR / "grid_auto.py")


def test_footer_compact(snap_compare):
"""Test Footer in the compact style"""
assert snap_compare(SNAPSHOT_APPS_DIR / "footer_toggle_compact.py")


def test_footer_compact_with_hover(snap_compare):
"""Test Footer in the compact style when the mouse is hovering over a keybinding"""

async def run_before(pilot) -> None:
await pilot.hover("Footer", offset=(0, 0))

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


def test_footer_standard_after_reactive_change(snap_compare):
"""Test Footer in the standard style after `compact` reactive change"""
assert snap_compare(
SNAPSHOT_APPS_DIR / "footer_toggle_compact.py", press=["ctrl+t"]
)


def test_footer_standard_with_hover(snap_compare):
"""Test Footer in the standard style when the mouse is hovering over a keybinding"""

async def run_before(pilot) -> None:
await pilot.press("ctrl+t")
await pilot.hover("Footer", offset=(0, 0))

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


def test_footer_classic_styling(snap_compare):
"""Regression test for https://github.com/Textualize/textual/issues/4557"""
assert snap_compare(SNAPSHOT_APPS_DIR / "footer_classic_styling.py")


def test_option_list_scrolling_with_multiline_options(snap_compare):
# https://github.com/Textualize/textual/issues/4705
assert snap_compare(WIDGET_EXAMPLES_DIR / "option_list_tables.py", press=["up"])
Expand Down
Loading