test fixes

This commit is contained in:
Will McGugan
2022-07-09 17:21:27 +01:00
parent f47629623c
commit d514193ea9
9 changed files with 35 additions and 15 deletions

View File

@@ -1,4 +1,6 @@
Button {
width:100%;
box-sizing: border-box;
margin: 1;
width: 100%;
}

View File

@@ -84,7 +84,7 @@ Tweet {
height:12;
width: 100%;
margin: 1 3;
background: $panel;
color: $text-panel;
layout: vertical;
@@ -198,7 +198,7 @@ Error {
color: $text-error;
border-top: wide $error-darken-1;
border-bottom: wide $error-darken-1;
margin: 1 3;
padding: 0;
text-style: bold;
align-horizontal: center;
@@ -211,7 +211,7 @@ Warning {
color: $text-warning-fade-1;
border-top: wide $warning-darken-1;
border-bottom: wide $warning-darken-1;
margin: 1 2;
text-style: bold;
align-horizontal: center;
}
@@ -222,7 +222,7 @@ Success {
height:auto;
box-sizing: border-box;
background: $success;
color: $text-success-fade-1;
color: $text-success;
border-top: hkey $success-darken-1;
border-bottom: hkey $success-darken-1;

View File

@@ -62,7 +62,7 @@ def get_box_model(
else:
# An explicit width
content_width = styles.width.resolve_dimension(
sizing_container, viewport, fraction_unit
sizing_container - styles.margin.totals, viewport, fraction_unit
)
if is_border_box:
content_width -= gutter.width

View File

@@ -43,6 +43,7 @@ VALID_STYLE_FLAGS: Final = {
"none",
"not",
"bold",
"blink",
"italic",
"underline",
"overline",
@@ -50,7 +51,9 @@ VALID_STYLE_FLAGS: Final = {
"b",
"i",
"u",
"uu",
"o",
"reverse",
}
NULL_SPACING: Final = Spacing.all(0)

View File

@@ -7,6 +7,7 @@ class Vertical(Widget):
CSS = """
Vertical {
layout: vertical;
overflow: auto;
}
"""
@@ -17,5 +18,6 @@ class Horizontal(Widget):
CSS = """
Horizontal {
layout: horizontal;
overflow: auto;
}
"""

View File

@@ -20,6 +20,7 @@ from rich.measure import Measurement
from rich.segment import Segment
from rich.style import Style
from rich.styled import Styled
from rich.text import Text
from . import errors, events, messages
from ._animator import BoundAnimator
@@ -887,11 +888,21 @@ class Widget(DOMNode):
"""
renderable = self.render()
styles = self.styles
if isinstance(renderable, str):
renderable = Text.from_markup(renderable)
rich_style = self.rich_style
if rich_style:
if isinstance(renderable, Text):
renderable.stylize(rich_style)
else:
renderable = Styled(renderable, rich_style)
content_align = (styles.content_align_horizontal, styles.content_align_vertical)
styles = self.styles
content_align = (
styles.content_align_horizontal,
styles.content_align_vertical,
)
if content_align != ("left", "top"):
horizontal, vertical = content_align
renderable = Align(renderable, horizontal, vertical=vertical)

View File

@@ -48,7 +48,7 @@ class Button(Widget, can_focus=True):
}
Button:focus {
text-style: bold underline;
text-style: bold underline;
}
Button:hover {

View File

@@ -88,7 +88,7 @@ def test_width():
box_model = get_box_model(
styles, Size(60, 20), Size(80, 24), one, get_auto_width, get_auto_height
)
assert box_model == BoxModel(Fraction(60), Fraction(16), Spacing(1, 2, 3, 4))
assert box_model == BoxModel(Fraction(54), Fraction(16), Spacing(1, 2, 3, 4))
styles.width = "100vw"
styles.max_width = "50%"

View File

@@ -1,6 +1,7 @@
from __future__ import annotations
from rich.segment import Segment
from rich.style import Style
from textual.color import Color
from textual.geometry import Region, Size
@@ -41,10 +42,11 @@ def test_no_styles():
content.__getitem__,
content_size=Size(3, 3),
)
style = Style.from_color(bgcolor=Color.parse("green").rich_color)
expected = [
[Segment("foo", styles.rich_style)],
[Segment("bar", styles.rich_style)],
[Segment("baz", styles.rich_style)],
[Segment("foo", style)],
[Segment("bar", style)],
[Segment("baz", style)],
]
assert lines == expected