mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
optimizations
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user