|
40 | 40 | if TYPE_CHECKING:
|
41 | 41 | from typing_extensions import TypeAlias
|
42 | 42 |
|
43 |
| - from textual.css.styles import RenderStyles |
44 | 43 | from textual.screen import Screen
|
45 | 44 | from textual.widget import Widget
|
46 | 45 |
|
@@ -522,38 +521,6 @@ def visible_widgets(self) -> dict[Widget, tuple[Region, Region]]:
|
522 | 521 | }
|
523 | 522 | return self._visible_widgets
|
524 | 523 |
|
525 |
| - def _constrain( |
526 |
| - self, styles: RenderStyles, region: Region, constrain_region: Region |
527 |
| - ) -> Region: |
528 |
| - """Applies constrain logic to a Region. |
529 |
| -
|
530 |
| - Args: |
531 |
| - styles: The widget's styles. |
532 |
| - region: The region to constrain. |
533 |
| - constrain_region: The outer region. |
534 |
| -
|
535 |
| - Returns: |
536 |
| - New region. |
537 |
| - """ |
538 |
| - constrain = styles.constrain |
539 |
| - if constrain == "inflect": |
540 |
| - inflect_margin = styles.margin |
541 |
| - margin_region = region.grow(inflect_margin) |
542 |
| - region = region.inflect( |
543 |
| - (-1 if margin_region.right > constrain_region.right else 0), |
544 |
| - (-1 if margin_region.bottom > constrain_region.bottom else 0), |
545 |
| - inflect_margin, |
546 |
| - ) |
547 |
| - region = region.translate_inside(constrain_region, True, True) |
548 |
| - elif constrain != "none": |
549 |
| - # Constrain to avoid clipping |
550 |
| - region = region.translate_inside( |
551 |
| - constrain_region, |
552 |
| - constrain in ("x", "both"), |
553 |
| - constrain in ("y", "both"), |
554 |
| - ) |
555 |
| - return region |
556 |
| - |
557 | 524 | def _arrange_root(
|
558 | 525 | self, root: Widget, size: Size, visible_only: bool = True
|
559 | 526 | ) -> tuple[CompositorMap, set[Widget]]:
|
@@ -688,10 +655,17 @@ def add_widget(
|
688 | 655 |
|
689 | 656 | widget_order = order + ((layer_index, z, layer_order),)
|
690 | 657 |
|
691 |
| - if overlay and sub_widget.styles.constrain != "none": |
692 |
| - widget_region = self._constrain( |
693 |
| - sub_widget.styles, widget_region, no_clip |
694 |
| - ) |
| 658 | + if overlay: |
| 659 | + styles = sub_widget.styles |
| 660 | + has_rule = styles.has_rule |
| 661 | + if has_rule("constrain_x") or has_rule("constrain_y"): |
| 662 | + widget_region = widget_region.constrain( |
| 663 | + styles.constrain_x, |
| 664 | + styles.constrain_y, |
| 665 | + styles.margin, |
| 666 | + no_clip, |
| 667 | + ) |
| 668 | + |
695 | 669 | if widget._cover_widget is None:
|
696 | 670 | add_widget(
|
697 | 671 | sub_widget,
|
@@ -739,13 +713,22 @@ def add_widget(
|
739 | 713 |
|
740 | 714 | widget_region = region + layout_offset
|
741 | 715 |
|
742 |
| - if widget._absolute_offset is not None: |
743 |
| - widget_region = widget_region.reset_offset.translate( |
744 |
| - widget._absolute_offset + widget.styles.margin.top_left |
| 716 | + if widget.absolute_offset is not None: |
| 717 | + margin = styles.margin |
| 718 | + widget_region = widget_region.at_offset( |
| 719 | + widget.absolute_offset + margin.top_left |
| 720 | + ) |
| 721 | + widget_region = widget_region.translate( |
| 722 | + styles.offset.resolve(widget_region.grow(margin).size, size) |
| 723 | + ) |
| 724 | + has_rule = styles.has_rule |
| 725 | + if has_rule("constrain_x") or has_rule("constrain_y"): |
| 726 | + widget_region = widget_region.constrain( |
| 727 | + styles.constrain_x, |
| 728 | + styles.constrain_y, |
| 729 | + styles.margin, |
| 730 | + size.region, |
745 | 731 | )
|
746 |
| - |
747 |
| - if styles.constrain != "none": |
748 |
| - widget_region = self._constrain(styles, widget_region, no_clip) |
749 | 732 |
|
750 | 733 | map[widget._render_widget] = _MapGeometry(
|
751 | 734 | widget_region,
|
|
0 commit comments