mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
snapshot
This commit is contained in:
@@ -371,7 +371,9 @@ class Compositor:
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Container region is minus border
|
# Container region is minus border
|
||||||
container_region = region.shrink(widget.styles.gutter)
|
container_region = region.shrink(widget.styles.gutter).translate(
|
||||||
|
layout_offset
|
||||||
|
)
|
||||||
container_size = container_region.size
|
container_size = container_region.size
|
||||||
|
|
||||||
# Widgets with scrollbars (containers or scroll view) require additional processing
|
# Widgets with scrollbars (containers or scroll view) require additional processing
|
||||||
@@ -393,7 +395,7 @@ class Compositor:
|
|||||||
widgets.update(arranged_widgets)
|
widgets.update(arranged_widgets)
|
||||||
|
|
||||||
# An offset added to all placements
|
# An offset added to all placements
|
||||||
placement_offset = container_region.offset + layout_offset
|
placement_offset = container_region.offset
|
||||||
placement_scroll_offset = placement_offset - widget.scroll_offset
|
placement_scroll_offset = placement_offset - widget.scroll_offset
|
||||||
|
|
||||||
_layers = widget.layers
|
_layers = widget.layers
|
||||||
|
|||||||
@@ -198,7 +198,7 @@ class StylesCache:
|
|||||||
if crop is None:
|
if crop is None:
|
||||||
crop = size.region
|
crop = size.region
|
||||||
|
|
||||||
width, height = size
|
width, _height = size
|
||||||
if width != self._width:
|
if width != self._width:
|
||||||
self.clear()
|
self.clear()
|
||||||
self._width = width
|
self._width = width
|
||||||
|
|||||||
@@ -635,6 +635,7 @@ class Region(NamedTuple):
|
|||||||
and (y2 >= oy2 >= y1)
|
and (y2 >= oy2 >= y1)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@lru_cache(maxsize=1024)
|
||||||
def translate(self, offset: tuple[int, int]) -> Region:
|
def translate(self, offset: tuple[int, int]) -> Region:
|
||||||
"""Move the offset of the Region.
|
"""Move the offset of the Region.
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
41
tests/snapshot_tests/snapshot_apps/offsets.py
Normal file
41
tests/snapshot_tests/snapshot_apps/offsets.py
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
from textual.app import App, ComposeResult
|
||||||
|
from textual.containers import Vertical
|
||||||
|
from textual.widgets import Label, Static
|
||||||
|
|
||||||
|
|
||||||
|
class Box(Static):
|
||||||
|
DEFAULT_CSS = """
|
||||||
|
Box {
|
||||||
|
border: solid white;
|
||||||
|
background: darkblue;
|
||||||
|
width: 16;
|
||||||
|
height: auto;
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
|
def compose(self) -> ComposeResult:
|
||||||
|
yield Label("FOO\nBAR\nBAZ")
|
||||||
|
|
||||||
|
|
||||||
|
class OffsetsApp(App):
|
||||||
|
|
||||||
|
CSS = """
|
||||||
|
|
||||||
|
#box1 {
|
||||||
|
offset: 5 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
#box2 {
|
||||||
|
offset: 15 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
def compose(self) -> ComposeResult:
|
||||||
|
yield Box(id="box1")
|
||||||
|
yield Box(id="box2")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
app = OffsetsApp()
|
||||||
|
app.run()
|
||||||
@@ -151,6 +151,11 @@ def test_columns_height(snap_compare):
|
|||||||
assert snap_compare("snapshot_apps/columns_height.py")
|
assert snap_compare("snapshot_apps/columns_height.py")
|
||||||
|
|
||||||
|
|
||||||
|
def test_offsets(snap_compare):
|
||||||
|
"""Test offsets of containers"""
|
||||||
|
assert snap_compare("snapshot_apps/offsets.py")
|
||||||
|
|
||||||
|
|
||||||
# --- Other ---
|
# --- Other ---
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user