Skip to content

Commit 5f53538

Browse files
committed
absolute offset public
1 parent 55b03a6 commit 5f53538

File tree

7 files changed

+17
-17
lines changed

7 files changed

+17
-17
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1414
### Changed
1515

1616
- Digits are now thin by default, style with text-style: bold to get bold digits https://github.com/Textualize/textual/pull/5094
17+
- Made `Widget.absolute_offset` public https://github.com/Textualize/textual/pull/5097
1718

1819
## [0.82.0] - 2024-10-03
1920

src/textual/_compositor.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -557,8 +557,8 @@ def _constrain(
557557

558558
region = region.translate_inside(
559559
constrain_region.shrink(styles.margin),
560-
constrain_x == "inside",
561-
constrain_y == "inside",
560+
constrain_x != "none",
561+
constrain_y != "none",
562562
)
563563

564564
return region
@@ -697,13 +697,12 @@ def add_widget(
697697

698698
widget_order = order + ((layer_index, z, layer_order),)
699699

700-
if overlay and (
701-
sub_widget.styles.constrain_x != "none"
702-
or sub_widget.styles.constrain_y != "none"
703-
):
704-
widget_region = self._constrain(
705-
sub_widget.styles, widget_region, no_clip
706-
)
700+
if overlay:
701+
has_rule = sub_widget.styles.has_rule
702+
if has_rule("constrain_x") or has_rule("constrain_y"):
703+
widget_region = self._constrain(
704+
sub_widget.styles, widget_region, no_clip
705+
)
707706

708707
if widget._cover_widget is None:
709708
add_widget(
@@ -752,16 +751,16 @@ def add_widget(
752751

753752
widget_region = region + layout_offset
754753

755-
if widget._absolute_offset is not None:
754+
if widget.absolute_offset is not None:
756755
margin = styles.margin
757756
widget_region = widget_region.reset_offset.translate(
758-
widget._absolute_offset + margin.top_left
757+
widget.absolute_offset + margin.top_left
759758
)
760759
widget_region = widget_region.translate(
761760
styles.offset.resolve(widget_region.grow(margin).size, size)
762761
)
763-
764-
if styles.constrain_x != "none" or styles.constrain_y != "none":
762+
has_rule = styles.has_rule
763+
if has_rule("constrain_x") or has_rule("constrain_y"):
765764
widget_region = self._constrain(styles, widget_region, no_clip)
766765

767766
map[widget._render_widget] = _MapGeometry(

src/textual/css/_styles_builder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1066,7 +1066,7 @@ def process_constrain(self, name: str, tokens: list[Token]) -> None:
10661066
self.styles._rules["constrain_x"] = constrain_x # type: ignore
10671067
self.styles._rules["constrain_y"] = constrain_y # type: ignore
10681068
else:
1069-
self.error(name, tokens[0], "one or two values here")
1069+
self.error(name, tokens[0], "one or two values expected here")
10701070

10711071
def process_constrain_x(self, name: str, tokens: list[Token]) -> None:
10721072
try:

src/textual/screen.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1278,7 +1278,7 @@ def _handle_tooltip_timer(self, widget: Widget) -> None:
12781278
tooltip.display = False
12791279
else:
12801280
tooltip.display = True
1281-
tooltip._absolute_offset = self.app.mouse_position
1281+
tooltip.absolute_offset = self.app.mouse_position
12821282
tooltip.update(tooltip_content)
12831283

12841284
def _handle_mouse_move(self, event: events.MouseMove) -> None:

src/textual/widget.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ def __init__(
422422

423423
self._tooltip: RenderableType | None = None
424424
"""The tooltip content."""
425-
self._absolute_offset: Offset | None = None
425+
self.absolute_offset: Offset | None = None
426426
"""Force an absolute offset for the widget (used by tooltips)."""
427427

428428
self._scrollbar_changes: set[tuple[bool, bool]] = set()

src/textual/widgets/_tooltip.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ class Tooltip(Static, inherit_css=False):
88
Tooltip {
99
layer: _tooltips;
1010
margin: 1 2;
11-
1211
padding: 1 2;
1312
background: $background;
1413
width: auto;

tests/snapshot_tests/snapshot_apps/tooltips.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
class TooltipApp(App[None]):
66
TOOLTIP_DELAY = 0.4
7+
78
def compose(self) -> ComposeResult:
89
progress_bar = ProgressBar(100, show_eta=False)
910
progress_bar.advance(10)

0 commit comments

Comments
 (0)