mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
virtual size and docks
This commit is contained in:
@@ -94,7 +94,9 @@ def arrange(
|
||||
)
|
||||
dock_region = dock_region.shrink(margin).translate(align_offset)
|
||||
add_placement(
|
||||
_WidgetPlacement(dock_region, null_spacing, dock_widget, top_z, True)
|
||||
_WidgetPlacement(
|
||||
dock_region, null_spacing, dock_widget, top_z, True, False
|
||||
)
|
||||
)
|
||||
|
||||
dock_spacing = Spacing(top, right, bottom, left)
|
||||
|
||||
@@ -592,6 +592,7 @@ class Compositor:
|
||||
get_layer_index = layers_to_index.get
|
||||
|
||||
scroll_spacing = arrange_result.scroll_spacing
|
||||
total_region = total_region.shrink(scroll_spacing)
|
||||
|
||||
# Add all the widgets
|
||||
for sub_region, margin, sub_widget, z, fixed, overlay in reversed(
|
||||
@@ -621,13 +622,21 @@ class Compositor:
|
||||
constrain in ("y", "both"),
|
||||
)
|
||||
|
||||
if overlay:
|
||||
clip_region = no_clip
|
||||
else:
|
||||
if fixed:
|
||||
clip_region = sub_clip
|
||||
else:
|
||||
clip_region = sub_clip.shrink(scroll_spacing)
|
||||
|
||||
add_widget(
|
||||
sub_widget,
|
||||
sub_region,
|
||||
widget_region,
|
||||
((1, 0, 0),) if overlay else widget_order,
|
||||
layer_order,
|
||||
no_clip if overlay else sub_clip,
|
||||
clip_region,
|
||||
visible,
|
||||
)
|
||||
|
||||
|
||||
@@ -72,9 +72,9 @@ class WidgetPlacement(NamedTuple):
|
||||
region: Region
|
||||
margin: Spacing
|
||||
widget: Widget
|
||||
order: int = 0
|
||||
fixed: bool = False
|
||||
overlay: bool = False
|
||||
order: int
|
||||
fixed: bool
|
||||
overlay: bool
|
||||
|
||||
|
||||
class Layout(ABC):
|
||||
|
||||
@@ -21,8 +21,9 @@ def partition(
|
||||
"""
|
||||
|
||||
result: tuple[list[T], list[T]] = ([], [])
|
||||
appends = (result[0].append, result[1].append)
|
||||
append0 = result[0].append
|
||||
append1 = result[1].append
|
||||
|
||||
for value in iterable:
|
||||
appends[1 if pred(value) else 0](value)
|
||||
(append1 if pred(value) else append0)(value)
|
||||
return result
|
||||
|
||||
@@ -153,7 +153,7 @@ class GridLayout(Layout):
|
||||
.shrink(margin)
|
||||
.clip_size(cell_size)
|
||||
)
|
||||
add_placement(WidgetPlacement(region, margin, widget))
|
||||
add_placement(WidgetPlacement(region, margin, widget, 0, False, False))
|
||||
add_widget(widget)
|
||||
|
||||
return (placements, set(widgets))
|
||||
|
||||
@@ -580,7 +580,10 @@ class Screen(Generic[ScreenResultType], Widget):
|
||||
) in layers:
|
||||
if widget in exposed_widgets:
|
||||
if widget._size_updated(
|
||||
region.size, virtual_size, container_size, layout=False
|
||||
region.size,
|
||||
virtual_size,
|
||||
container_size,
|
||||
layout=False,
|
||||
):
|
||||
widget.post_message(
|
||||
ResizeEvent(
|
||||
|
||||
@@ -24,10 +24,8 @@ def test_arrange_dock_top():
|
||||
result = arrange(container, [child, header], Size(80, 24), Size(80, 24))
|
||||
|
||||
assert result.placements == [
|
||||
WidgetPlacement(
|
||||
Region(0, 0, 80, 1), Spacing(), header, order=TOP_Z, fixed=True
|
||||
),
|
||||
WidgetPlacement(Region(0, 1, 80, 23), Spacing(), child, order=0, fixed=False),
|
||||
WidgetPlacement(Region(0, 0, 80, 1), Spacing(), header, TOP_Z, True, False),
|
||||
WidgetPlacement(Region(0, 1, 80, 23), Spacing(), child, 0, False, False),
|
||||
]
|
||||
assert result.widgets == {child, header}
|
||||
|
||||
@@ -41,10 +39,8 @@ def test_arrange_dock_left():
|
||||
|
||||
result = arrange(container, [child, header], Size(80, 24), Size(80, 24))
|
||||
assert result.placements == [
|
||||
WidgetPlacement(
|
||||
Region(0, 0, 10, 24), Spacing(), header, order=TOP_Z, fixed=True
|
||||
),
|
||||
WidgetPlacement(Region(10, 0, 70, 24), Spacing(), child, order=0, fixed=False),
|
||||
WidgetPlacement(Region(0, 0, 10, 24), Spacing(), header, TOP_Z, True, False),
|
||||
WidgetPlacement(Region(10, 0, 70, 24), Spacing(), child, 0, False, False),
|
||||
]
|
||||
assert result.widgets == {child, header}
|
||||
|
||||
@@ -58,10 +54,8 @@ def test_arrange_dock_right():
|
||||
|
||||
result = arrange(container, [child, header], Size(80, 24), Size(80, 24))
|
||||
assert result.placements == [
|
||||
WidgetPlacement(
|
||||
Region(70, 0, 10, 24), Spacing(), header, order=TOP_Z, fixed=True
|
||||
),
|
||||
WidgetPlacement(Region(0, 0, 70, 24), Spacing(), child, order=0, fixed=False),
|
||||
WidgetPlacement(Region(70, 0, 10, 24), Spacing(), header, TOP_Z, True, False),
|
||||
WidgetPlacement(Region(0, 0, 70, 24), Spacing(), child, 0, False, False),
|
||||
]
|
||||
assert result.widgets == {child, header}
|
||||
|
||||
@@ -75,10 +69,8 @@ def test_arrange_dock_bottom():
|
||||
|
||||
result = arrange(container, [child, header], Size(80, 24), Size(80, 24))
|
||||
assert result.placements == [
|
||||
WidgetPlacement(
|
||||
Region(0, 23, 80, 1), Spacing(), header, order=TOP_Z, fixed=True
|
||||
),
|
||||
WidgetPlacement(Region(0, 0, 80, 23), Spacing(), child, order=0, fixed=False),
|
||||
WidgetPlacement(Region(0, 23, 80, 1), Spacing(), header, TOP_Z, True, False),
|
||||
WidgetPlacement(Region(0, 0, 80, 23), Spacing(), child, 0, False, False),
|
||||
]
|
||||
assert result.widgets == {child, header}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user