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 { Button {
box-sizing: border-box;
width:100%; margin: 1;
width: 100%;
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -88,7 +88,7 @@ def test_width():
box_model = get_box_model( box_model = get_box_model(
styles, Size(60, 20), Size(80, 24), one, get_auto_width, get_auto_height 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.width = "100vw"
styles.max_width = "50%" styles.max_width = "50%"

View File

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