From 39412c11a968a05c6adb2bf63b197c99b2fbdc51 Mon Sep 17 00:00:00 2001 From: Darren Burns Date: Tue, 26 Apr 2022 15:41:33 +0100 Subject: [PATCH] Ensure help text for align appears --- sandbox/uber.css | 5 ++- src/textual/css/_style_properties.py | 2 +- src/textual/css/_styles_builder.py | 50 +++++++++++++++++++--------- 3 files changed, 38 insertions(+), 19 deletions(-) diff --git a/sandbox/uber.css b/sandbox/uber.css index d943c33f0..aaa2a9e99 100644 --- a/sandbox/uber.css +++ b/sandbox/uber.css @@ -1,13 +1,12 @@ #uber1 { layout: vertical; background: dark_green; - overflow: auto auto; + overflow: hidden auto; border: heavy white; } .list-item { height: 8; - align: center middle; + align: centear middlex; background: dark_blue; - border: solid red; } diff --git a/src/textual/css/_style_properties.py b/src/textual/css/_style_properties.py index ddb46a993..4d3cd661b 100644 --- a/src/textual/css/_style_properties.py +++ b/src/textual/css/_style_properties.py @@ -515,7 +515,7 @@ class LayoutProperty: """ Args: obj (Styles): The Styles object. - layout (str | Layout): The layout to use. You can supply a the name of the layout + layout (str | Layout): The layout to use. You can supply the name of the layout or a ``Layout`` object. """ diff --git a/src/textual/css/_styles_builder.py b/src/textual/css/_styles_builder.py index f0275b63a..9abece2ef 100644 --- a/src/textual/css/_styles_builder.py +++ b/src/textual/css/_styles_builder.py @@ -29,7 +29,7 @@ from .constants import ( VALID_OVERFLOW, VALID_VISIBILITY, ) -from .errors import DeclarationError +from .errors import DeclarationError, StyleValueError from .model import Declaration from .scalar import Scalar, ScalarOffset, Unit, ScalarError, ScalarParseError from .styles import DockGroup, Styles @@ -657,30 +657,50 @@ class StylesBuilder: self.styles._rules["transitions"] = transitions def process_align(self, name: str, tokens: list[Token]) -> None: + def align_error(name, token): + self.error(name, token, align_help_text()) + if len(tokens) != 2: self.error(name, tokens[0], align_help_text()) + token_horizontal = tokens[0] token_vertical = tokens[1] + if token_horizontal.name != "token": - self.error( - name, - token_horizontal, - align_help_text(), - ) + align_error(name, token_horizontal) + elif token_horizontal.value not in VALID_ALIGN_HORIZONTAL: + align_error(name, token_horizontal) + if token_vertical.name != "token": - self.error( - name, - token_vertical, - align_help_text(), - ) + align_error(name, token_vertical) + elif token_horizontal.value not in VALID_ALIGN_VERTICAL: + align_error(name, token_horizontal) self.styles._rules["align_horizontal"] = token_horizontal.value self.styles._rules["align_vertical"] = token_vertical.value def process_align_horizontal(self, name: str, tokens: list[Token]) -> None: - value = self._process_enum(name, tokens, VALID_ALIGN_HORIZONTAL) - self.styles._rules["align_horizontal"] = value + try: + value = self._process_enum(name, tokens, VALID_ALIGN_HORIZONTAL) + self.styles._rules["align_horizontal"] = value + except StyleValueError: + self.error( + name, + tokens[0], + string_enum_help_text( + "align-horizontal", VALID_ALIGN_HORIZONTAL, context="css" + ), + ) def process_align_vertical(self, name: str, tokens: list[Token]) -> None: - value = self._process_enum(name, tokens, VALID_ALIGN_VERTICAL) - self.styles._rules["align_vertical"] = value + try: + value = self._process_enum(name, tokens, VALID_ALIGN_VERTICAL) + self.styles._rules["align_vertical"] = value + except StyleValueError: + self.error( + name, + tokens[0], + string_enum_help_text( + "align-vertical", VALID_ALIGN_VERTICAL, context="css" + ), + )