optimizations

This commit is contained in:
Will McGugan
2022-08-29 21:39:08 +01:00
parent 51173e7a5d
commit f4eb053a26
3 changed files with 28 additions and 8 deletions

View File

@@ -1,3 +1,7 @@
Screen {
overflow: auto;
}
#calculator {
layout: table;
table-size: 4;
@@ -6,6 +10,7 @@
table-rows: 1fr;
margin: 1 2;
min-height:23;
min-width: 40;
}
Button {

View File

@@ -551,6 +551,19 @@ class Region(NamedTuple):
height + expand_height * 2,
)
def clip_size(self, size: tuple[int, int]) -> Region:
"""Clip the size to fit within minimum values.
Args:
size (tuple[int, int]): Maximum width and height.
Returns:
Region: No region, not bigger than size.
"""
x, y, width, height = self
max_width, max_height = size
return Region(x, y, min(width, max_width), min(height, max_height))
@lru_cache(maxsize=1024)
def overlaps(self, other: Region) -> bool:
"""Check if another region overlaps this region.

View File

@@ -139,16 +139,18 @@ class TableLayout(Layout):
y = rows[row][0]
x2, cell_width = columns[min(max_column, column + column_span)]
y2, cell_height = rows[min(max_row, row + row_span)]
cell_size = Size(cell_width + x2 - x, cell_height + y2 - y)
width, height, margin = widget._get_box_model(
Size(
x2 - x + cell_width,
y2 - y + cell_height,
),
cell_size,
viewport,
fraction_unit,
)
region = Region(x, y, int(width), int(height)).shrink(margin)
region = (
Region(x, y, int(width), int(height))
.shrink(margin)
.clip_size(cell_size)
)
add_placement(WidgetPlacement(region, widget))
add_widget(widget)
return placements, {*widgets}
return (placements, set(widgets))