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 border issue #2074

Merged
merged 2 commits into from
Mar 16, 2023
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
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

- Dropped "loading-indicator--dot" component style from LoadingIndicator https://github.com/Textualize/textual/pull/2050

## Unreleased
### Fixed

- Fixed borders not rendering correctly. https://github.com/Textualize/textual/pull/2074

### Changed

Expand Down
10 changes: 4 additions & 6 deletions src/textual/dom.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,9 +609,8 @@ def background_colors(self) -> tuple[Color, Color]:
base_background = background = BLACK
for node in reversed(self.ancestors_with_self):
styles = node.styles
if styles.has_rule("background"):
base_background = background
background += styles.background
base_background = background
background += styles.background
return (base_background, background)

@property
Expand All @@ -621,9 +620,8 @@ def colors(self) -> tuple[Color, Color, Color, Color]:
base_color = color = BLACK
for node in reversed(self.ancestors_with_self):
styles = node.styles
if styles.has_rule("background"):
base_background = background
background += styles.background
base_background = background
background += styles.background
if styles.has_rule("color"):
base_color = color
if styles.auto_color:
Expand Down
356 changes: 176 additions & 180 deletions tests/snapshot_tests/__snapshots__/test_snapshots.ambr

Large diffs are not rendered by default.

63 changes: 30 additions & 33 deletions tests/snapshot_tests/snapshot_apps/border_alpha.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,40 @@
from textual.app import App, ComposeResult
from textual.containers import Grid
from textual.widget import Widget
from textual.containers import Vertical
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rewrote this snapshot test, because it wasn't clear to me what it should look like.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem I see with the rewrite is that it doesn't exercise the CSS parser in quite the same way. The original test was designed to try out a good combination of styles, colours and alpha values to ensure it all worked together.

That looks to have been lost.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True. But those are better captured with a unit test. Snapshots should be used to validate that things look correct only, where you can't tell from the data alone.

from textual.widgets import Label

class BorderAlphaApp(App[None]):

CSS = """
Grid {
height: 100%;
class BorderAlphaApp(App[None]):
CSS = """
.boxes {
height: 3;
width: 100%;
grid-size: 2 2;
}

#b00 { border: 0%; }
#b01 { border: 33%; }
#b02 { border: 66%; }
#b03 { border: 100%; }

#b10 { border: solid 0%; }
#b11 { border: dashed 33%; }
#b12 { border: round 66%; }
#b13 { border: ascii 100%; }

#b20 { border: 0% red; }
#b21 { border: 33% orange; }
#b22 { border: 66% green; }
#b23 { border: 100% blue; }

#b30 { border: solid 0% red; }
#b31 { border: dashed 33% orange; }
#b32 { border: round 66% green; }
#b33 { border: ascii 100% blue; }

#box0 {
border: heavy green 0%;
}
#box1 {
border: heavy green 20%;
}
#box2 {
border: heavy green 40%;
}
#box3 {
border: heavy green 60%;
}
#box4 {
border: heavy green 80%;
}
#box5 {
border: heavy green 100%;
}
"""

def compose( self ) -> ComposeResult:
with Grid():
for outer in range(4):
with Grid():
for inner in range(4):
yield Widget(id=f"b{outer}{inner}")
def compose(self) -> ComposeResult:
with Vertical():
for box in range(6):
yield Label(id=f"box{box}", classes="boxes")


if __name__ == "__main__":
BorderAlphaApp().run()