Skip to content

Commit 855bec6

Browse files
authored
Merge pull request #5553 from TomJGooding/fix-border-fix-flipped-title-colors-in-panel-border
fix(border): fix flipped title colors in panel border
2 parents 8029231 + 93fda36 commit 855bec6

File tree

7 files changed

+340
-132
lines changed

7 files changed

+340
-132
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1313
- Fixed height of auto container which contains auto height children https://github.com/Textualize/textual/pull/5552
1414
- Fixed `Content.from_markup` not stripping control codes https://github.com/Textualize/textual/pull/5557
1515
- Fixed `delta_x` and `delta_y` in mouse events when smooth scrolling is enabled https://github.com/Textualize/textual/pull/5556
16+
- Fixed flipped title colors in panel border https://github.com/Textualize/textual/issues/5548
1617
- Fixed detection of smooth scrolling https://github.com/Textualize/textual/pull/5558
1718

19+
1820
### Added
1921

2022
- Added `pointer_x`, `pointer_y`, `pointer_screen_x`, and `pointer_screen_y` attributes to mouse events https://github.com/Textualize/textual/pull/5556

src/textual/_border.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,10 @@ def render_border_label(
385385
assert False
386386

387387
if (flip_top and is_title) or (flip_bottom and not is_title):
388-
base_style = base_style.without_color + Style(reverse=True)
388+
base_style = base_style.without_color + Style(
389+
background=base_style.foreground,
390+
foreground=base_style.background,
391+
)
389392

390393
segments = text_label.render_segments(base_style)
391394
yield from segments

src/textual/_styles_cache.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,11 @@ def post(segments: Iterable[Segment]) -> Iterable[Segment]:
379379
if label_background.a
380380
else TRANSPARENT
381381
),
382-
(base_label_background + border_color + label_color),
382+
(
383+
(base_label_background + label_color)
384+
if label_color.a
385+
else TRANSPARENT
386+
),
383387
)
384388
render_label = (label, style)
385389

tests/snapshot_tests/__snapshots__/test_snapshots/test_border_tab.svg

Lines changed: 56 additions & 57 deletions
Loading

tests/snapshot_tests/__snapshots__/test_snapshots/test_panel_border_title_colors.svg

Lines changed: 153 additions & 0 deletions
Loading

tests/snapshot_tests/__snapshots__/test_snapshots/test_textual_dev_colors_preview.svg

Lines changed: 73 additions & 73 deletions
Loading

tests/snapshot_tests/test_snapshots.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3720,3 +3720,50 @@ def on_mount(self) -> None:
37203720
table.add_rows(rows[1:])
37213721

37223722
assert snap_compare(MyApp())
3723+
3724+
3725+
def test_panel_border_title_colors(snap_compare):
3726+
"""Regression test for https://github.com/Textualize/textual/issues/5548
3727+
3728+
You should see four labels with panel type borders. The border title colors
3729+
should match the description in the label."""
3730+
3731+
class BorderTitleApp(App):
3732+
CSS = """
3733+
Label {
3734+
border: panel red;
3735+
width: 40;
3736+
margin: 1;
3737+
}
3738+
3739+
.with-border-title-color {
3740+
border-title-color: yellow;
3741+
}
3742+
3743+
.with-border-title-background {
3744+
border-title-background: green;
3745+
}
3746+
"""
3747+
3748+
def compose(self) -> ComposeResult:
3749+
yield Label(
3750+
"with default",
3751+
)
3752+
yield Label(
3753+
"with yellow color",
3754+
classes="with-border-title-color",
3755+
)
3756+
yield Label(
3757+
"with green background",
3758+
classes="with-border-title-background",
3759+
)
3760+
yield Label(
3761+
"with yellow color and green background",
3762+
classes="with-border-title-background with-border-title-color",
3763+
)
3764+
3765+
def on_mount(self) -> None:
3766+
for label in self.query(Label):
3767+
label.border_title = "Border title"
3768+
3769+
assert snap_compare(BorderTitleApp())

0 commit comments

Comments
 (0)