diff --git a/sandbox/buttons.css b/sandbox/buttons.css index 45fed5596..0d34ebf9e 100644 --- a/sandbox/buttons.css +++ b/sandbox/buttons.css @@ -1,4 +1,6 @@ + Button { - - width:100%; + box-sizing: border-box; + margin: 1; + width: 100%; } diff --git a/sandbox/will/basic.css b/sandbox/will/basic.css index c6de15b3a..1714e8f45 100644 --- a/sandbox/will/basic.css +++ b/sandbox/will/basic.css @@ -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; diff --git a/src/textual/box_model.py b/src/textual/box_model.py index 3f75e61f3..0acbfe134 100644 --- a/src/textual/box_model.py +++ b/src/textual/box_model.py @@ -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 diff --git a/src/textual/css/constants.py b/src/textual/css/constants.py index 102e7eb42..d8784c519 100644 --- a/src/textual/css/constants.py +++ b/src/textual/css/constants.py @@ -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) diff --git a/src/textual/layout.py b/src/textual/layout.py index 4c900a593..82db0e7da 100644 --- a/src/textual/layout.py +++ b/src/textual/layout.py @@ -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; } """ diff --git a/src/textual/widget.py b/src/textual/widget.py index 0abc35a2e..4ff2a8532 100644 --- a/src/textual/widget.py +++ b/src/textual/widget.py @@ -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) diff --git a/src/textual/widgets/_button.py b/src/textual/widgets/_button.py index 1c0a734ba..0246c9b0e 100644 --- a/src/textual/widgets/_button.py +++ b/src/textual/widgets/_button.py @@ -48,7 +48,7 @@ class Button(Widget, can_focus=True): } Button:focus { - text-style: bold underline; + text-style: bold underline; } Button:hover { diff --git a/tests/test_box_model.py b/tests/test_box_model.py index 63f20a3ce..87026ca3e 100644 --- a/tests/test_box_model.py +++ b/tests/test_box_model.py @@ -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%" diff --git a/tests/test_styles_cache.py b/tests/test_styles_cache.py index ea892f189..d30c1cebf 100644 --- a/tests/test_styles_cache.py +++ b/tests/test_styles_cache.py @@ -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