fix for scroll width issue

This commit is contained in:
Will McGugan
2022-08-30 10:14:16 +01:00
parent b5cb875c5f
commit b64b9eae2e
7 changed files with 18 additions and 24 deletions

View File

@@ -48,7 +48,7 @@ def arrange(
_WidgetPlacement = WidgetPlacement
top_z = TOP_Z
scroll_spacing = Spacing()
null_spacing = Spacing()
get_dock = attrgetter("styles.dock")
for widgets in dock_layers.values():
@@ -94,7 +94,9 @@ def arrange(
(widget_width, widget_height), size
)
dock_region = dock_region.shrink(margin).translate(align_offset)
add_placement(_WidgetPlacement(dock_region, dock_widget, top_z, True))
add_placement(
_WidgetPlacement(dock_region, null_spacing, dock_widget, top_z, True)
)
dock_spacing = Spacing(top, right, bottom, left)
region = size.region.shrink(dock_spacing)
@@ -109,9 +111,9 @@ def arrange(
if placement_offset:
layout_placements = [
_WidgetPlacement(
_region + placement_offset, layout_widget, order, fixed
_region + placement_offset, margin, layout_widget, order, fixed
)
for _region, layout_widget, order, fixed in layout_placements
for _region, margin, layout_widget, order, fixed in layout_placements
]
placements.extend(layout_placements)

View File

@@ -400,17 +400,16 @@ class Compositor:
get_layer_index = layers_to_index.get
# Add all the widgets
for sub_region, sub_widget, z, fixed in placements:
for sub_region, margin, sub_widget, z, fixed in placements:
# Combine regions with children to calculate the "virtual size"
if fixed:
widget_region = sub_region + placement_offset
else:
total_region = total_region.union(sub_region.grow(spacing))
total_region = total_region.union(
sub_region.grow(spacing + margin)
)
widget_region = sub_region + placement_scroll_offset
if sub_widget is None:
continue
widget_order = order + (get_layer_index(sub_widget.layer, 0), z)
add_widget(

View File

@@ -25,7 +25,8 @@ class WidgetPlacement(NamedTuple):
"""The position, size, and relative order of a widget within its parent."""
region: Region
widget: Widget | None = None # A widget of None means empty space
margin: Spacing
widget: Widget
order: int = 0
fixed: bool = False

View File

@@ -17,7 +17,6 @@ class CenterLayout(Layout):
) -> ArrangeResult:
placements: list[WidgetPlacement] = []
total_regions: list[Region] = []
parent_size = parent.outer_size
container_width, container_height = size
@@ -32,8 +31,6 @@ class CenterLayout(Layout):
x = margin.left + max(0, (container_width - margin_width) // 2)
y = margin.top + max(0, (container_height - margin_height) // 2)
region = Region(x, y, int(width), int(height))
total_regions.append(region.grow(margin))
placements.append(WidgetPlacement(region, widget, 0))
placements.append(WidgetPlacement(region, margin, widget, 0))
placements.append(WidgetPlacement(Region.from_union(total_regions), None, 0))
return placements, set(children)

View File

@@ -61,11 +61,8 @@ class HorizontalLayout(Layout):
max_height = max(
max_height, content_height + offset_y + box_model.margin.bottom
)
add_placement(WidgetPlacement(region, widget, 0))
add_placement(WidgetPlacement(region, box_model.margin, widget, 0))
x = next_x + margin
max_width = x
total_region = Region(0, 0, int(max_width), int(max_height))
add_placement(WidgetPlacement(total_region, None, 0))
return placements, set(displayed_children)

View File

@@ -6,7 +6,7 @@ from typing import TYPE_CHECKING, Iterable
from .._layout import ArrangeResult, Layout, WidgetPlacement
from .._resolve import resolve
from ..css.scalar import Scalar
from ..geometry import Region, Size
from ..geometry import Region, Size, Spacing
if TYPE_CHECKING:
from ..widget import Widget
@@ -132,6 +132,7 @@ class TableLayout(Layout):
add_widget = widgets.append
max_column = len(columns) - 1
max_row = len(rows) - 1
margin = Spacing()
for widget, (column, row, column_span, row_span) in cell_size_map.items():
x = columns[column][0]
if row > max_row:
@@ -150,7 +151,7 @@ class TableLayout(Layout):
.shrink(margin)
.clip_size(cell_size)
)
add_placement(WidgetPlacement(region, widget))
add_placement(WidgetPlacement(region, margin, widget))
add_widget(widget)
return (placements, set(widgets))

View File

@@ -54,10 +54,7 @@ class VerticalLayout(Layout):
)
next_y = y + content_height
region = Region(offset_x, int(y), int(content_width), int(next_y) - int(y))
add_placement(WidgetPlacement(region, widget, 0))
add_placement(WidgetPlacement(region, box_model.margin, widget, 0))
y = next_y + margin
total_region = Region(0, 0, size.width, int(y))
add_placement(WidgetPlacement(total_region, None, 0))
return placements, set(children)