mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Add help text for offset-x and offset-y properies
This commit is contained in:
@@ -8,5 +8,4 @@
|
||||
.list-item {
|
||||
height: 8;
|
||||
background: dark_blue;
|
||||
offset: 12 1;
|
||||
}
|
||||
|
||||
@@ -80,7 +80,8 @@ class BasicApp(App):
|
||||
self.focused.display = not self.focused.display
|
||||
|
||||
def action_toggle_border(self):
|
||||
self.focused.styles.border = [("solid", "red"), ("dashed", "white")]
|
||||
# self.focused.styles.border = [("solid", "red"), ("dashed", "white")]
|
||||
self.focused.styles.offset = (12, "1x")
|
||||
|
||||
|
||||
BasicApp.run(css_file="uber.css", log="textual.log", log_verbosity=1)
|
||||
|
||||
@@ -610,3 +610,19 @@ def align_help_text() -> HelpText:
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
def offset_single_axis_help_text(property_name: str) -> HelpText:
|
||||
return HelpText(
|
||||
summary=f"Invalid value for [i]{property_name}[/]",
|
||||
bullets=[
|
||||
Bullet(
|
||||
markup=f"The [i]{property_name}[/] property can be set to a number or scalar value",
|
||||
examples=[
|
||||
Example(f"{property_name}: 10;"),
|
||||
Example(f"{property_name}: 50%;"),
|
||||
],
|
||||
),
|
||||
Bullet(f"Valid scalar units are {friendly_list(SYMBOL_UNIT)}"),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -18,6 +18,7 @@ from ._help_text import (
|
||||
border_property_help_text,
|
||||
layout_property_help_text,
|
||||
fractional_property_help_text,
|
||||
offset_property_help_text,
|
||||
)
|
||||
from ._help_text import (
|
||||
spacing_wrong_number_of_values,
|
||||
@@ -591,16 +592,23 @@ class OffsetProperty:
|
||||
obj.refresh(layout=True)
|
||||
else:
|
||||
x, y = offset
|
||||
scalar_x = (
|
||||
Scalar.parse(x, Unit.WIDTH)
|
||||
if isinstance(x, str)
|
||||
else Scalar(float(x), Unit.CELLS, Unit.WIDTH)
|
||||
)
|
||||
scalar_y = (
|
||||
Scalar.parse(y, Unit.HEIGHT)
|
||||
if isinstance(y, str)
|
||||
else Scalar(float(y), Unit.CELLS, Unit.HEIGHT)
|
||||
)
|
||||
|
||||
try:
|
||||
scalar_x = (
|
||||
Scalar.parse(x, Unit.WIDTH)
|
||||
if isinstance(x, str)
|
||||
else Scalar(float(x), Unit.CELLS, Unit.WIDTH)
|
||||
)
|
||||
scalar_y = (
|
||||
Scalar.parse(y, Unit.HEIGHT)
|
||||
if isinstance(y, str)
|
||||
else Scalar(float(y), Unit.CELLS, Unit.HEIGHT)
|
||||
)
|
||||
except ScalarParseError as error:
|
||||
raise StyleValueError(
|
||||
str(error), help_text=offset_property_help_text(context="inline")
|
||||
)
|
||||
|
||||
_offset = ScalarOffset(scalar_x, scalar_y)
|
||||
|
||||
if obj.set_rule(self.name, _offset):
|
||||
|
||||
@@ -19,6 +19,7 @@ from ._help_text import (
|
||||
fractional_property_help_text,
|
||||
align_help_text,
|
||||
offset_property_help_text,
|
||||
offset_single_axis_help_text,
|
||||
)
|
||||
from .constants import (
|
||||
VALID_ALIGN_HORIZONTAL,
|
||||
@@ -476,11 +477,11 @@ class StylesBuilder:
|
||||
if not tokens:
|
||||
return
|
||||
if len(tokens) != 1:
|
||||
self.error(name, tokens[0], f"expected a single number")
|
||||
self.error(name, tokens[0], offset_single_axis_help_text(name))
|
||||
else:
|
||||
token = tokens[0]
|
||||
if token.name not in ("scalar", "number"):
|
||||
self.error(name, token, f"expected a scalar; found {token.value!r}")
|
||||
self.error(name, token, offset_single_axis_help_text(name))
|
||||
x = Scalar.parse(token.value, Unit.WIDTH)
|
||||
y = self.styles.offset.y
|
||||
self.styles._rules["offset"] = ScalarOffset(x, y)
|
||||
@@ -489,11 +490,11 @@ class StylesBuilder:
|
||||
if not tokens:
|
||||
return
|
||||
if len(tokens) != 1:
|
||||
self.error(name, tokens[0], f"expected a single number")
|
||||
self.error(name, tokens[0], offset_single_axis_help_text(name))
|
||||
else:
|
||||
token = tokens[0]
|
||||
if token.name not in ("scalar", "number"):
|
||||
self.error(name, token, f"expected a scalar; found {token.value!r}")
|
||||
self.error(name, token, offset_single_axis_help_text(name))
|
||||
y = Scalar.parse(token.value, Unit.HEIGHT)
|
||||
x = self.styles.offset.x
|
||||
self.styles._rules["offset"] = ScalarOffset(x, y)
|
||||
|
||||
@@ -245,9 +245,6 @@ class GridLayout(Layout):
|
||||
col_align: GridAlign,
|
||||
row_align: GridAlign,
|
||||
) -> Region:
|
||||
offset_x = 0
|
||||
offset_y = 0
|
||||
|
||||
def align(size: int, container: int, align: GridAlign) -> int:
|
||||
offset = 0
|
||||
if align == "end":
|
||||
|
||||
Reference in New Issue
Block a user