size properties

This commit is contained in:
Will McGugan
2022-07-04 21:15:24 +01:00
parent d7f463f3eb
commit 0ba3ffb171
10 changed files with 23 additions and 23 deletions

View File

@@ -14,8 +14,8 @@ class EasingApp(App):
def watch_side(self, side: bool) -> None:
"""Animate when the side changes (False for left, True for right)."""
width = self.easing_view.size.width
animate_x = (width - self.placeholder.size.width) if side else 0
width = self.easing_view.outer_size.width
animate_x = (width - self.placeholder.outer_size.width) if side else 0
self.placeholder.animate(
"layout_offset_x", animate_x, easing=self.easing, duration=1
)

View File

@@ -36,7 +36,7 @@ class ScalarAnimation(Animation):
self.final_value = value
self.easing = easing
size = widget.size
size = widget.outer_size
viewport = widget.app.size
self.start: Offset = getattr(styles, attribute).resolve(size, viewport)

View File

@@ -22,7 +22,7 @@ class HorizontalLayout(Layout):
add_placement = placements.append
x = max_width = max_height = Fraction(0)
parent_size = parent.size
parent_size = parent.outer_size
children = list(parent.children)
styles = [child.styles for child in children if child.styles.width is not None]

View File

@@ -20,7 +20,7 @@ class VerticalLayout(Layout):
placements: list[WidgetPlacement] = []
add_placement = placements.append
parent_size = parent.size
parent_size = parent.outer_size
children = list(parent.children)
styles = [child.styles for child in children if child.styles.height is not None]

View File

@@ -131,7 +131,7 @@ class Screen(Widget):
def _refresh_layout(self, size: Size | None = None, full: bool = False) -> None:
"""Refresh the layout (can change size and positions of widgets)."""
size = self.size if size is None else size
size = self.outer_size if size is None else size
if not size:
return

View File

@@ -434,15 +434,18 @@ class Widget(DOMNode):
return self.styles.gutter + self.scrollbar_gutter
@property
def content_size(self) -> Size:
def size(self) -> Size:
"""The size of the content area."""
return self.content_region.size
@property
def size(self) -> Size:
def outer_size(self) -> Size:
"""The size of the widget (including padding and border)."""
return self._size
@property
def container_size(self) -> Size:
"""The size of the container (parent widget)."""
return self._container_size
@property
@@ -535,17 +538,14 @@ class Widget(DOMNode):
"""
if regions:
widget_regions = [
region.translate(self.content_offset) for region in regions
]
content_offset = self.content_offset
widget_regions = [region.translate(content_offset) for region in regions]
self._dirty_regions.update(widget_regions)
self._styles_cache.set_dirty(*widget_regions)
else:
self._dirty_regions.clear()
self._styles_cache.clear()
# TODO: Does this need to be content region?
# self._dirty_regions.append(self.size.region)
self._dirty_regions.add(self.size.region)
self._dirty_regions.add(self.outer_size.region)
def get_dirty_regions(self) -> Collection[Region]:
"""Get regions which require a repaint.
@@ -976,13 +976,13 @@ class Widget(DOMNode):
def _render_content(self) -> None:
"""Render all lines."""
width, height = self.content_size
width, height = self.size
renderable = self.render_styled()
options = self.console.options.update_dimensions(width, height).update(
highlight=False
)
lines = self.console.render_lines(renderable, options, style=self.rich_style)
self._render_cache = RenderCache(self.content_size, lines)
self._render_cache = RenderCache(self.size, lines)
self._dirty_regions.clear()
def render_line(self, y: int) -> list[Segment]:

View File

@@ -462,7 +462,7 @@ class DataTable(ScrollView, Generic[CellType]):
list[Segment]: List of segments for rendering.
"""
width = self.content_size.width
width = self.size.width
try:
row_index, line_no = self._get_offsets(y)
@@ -507,7 +507,7 @@ class DataTable(ScrollView, Generic[CellType]):
Returns:
list[Segment]: A rendered line.
"""
width, height = self.content_size
width, height = self.size
scroll_x, scroll_y = self.scroll_offset
fixed_top_row_count = sum(
self.get_row_height(row_index) for row_index in range(self.fixed_rows)

View File

@@ -277,5 +277,5 @@ async def test_scrollbar_gutter(
app = MyTestApp(test_name="scrollbar_gutter", size=Size(80, 10))
await app.boot_and_shutdown()
assert text_widget.size.width == expected_text_widget_width
assert text_widget.outer_size.width == expected_text_widget_width
assert container.scrollbars_enabled[0] is expects_vertical_scrollbar

View File

@@ -144,7 +144,7 @@ async def test_composition_of_vertical_container_with_children(
async with app.in_running_state():
# root widget checks:
root_widget = cast(Widget, app.get_child("root"))
assert root_widget.size == expected_screen_size
assert root_widget.outer_size == expected_screen_size
root_widget_region = app.screen.find_widget(root_widget).region
assert root_widget_region == (
0,
@@ -158,7 +158,7 @@ async def test_composition_of_vertical_container_with_children(
# placeholder widgets checks:
for placeholder in app_placeholders:
assert placeholder.size == expected_placeholders_size
assert placeholder.outer_size == expected_placeholders_size
assert placeholder.styles.offset.x.value == 0.0
assert app.screen.get_offset(placeholder).x == expected_placeholders_offset_x
@@ -224,7 +224,7 @@ async def test_border_edge_types_impact_on_widget_size(
)
assert box_inner_size == expected_box_inner_size
assert border_target.size == expected_box_size
assert border_target.outer_size == expected_box_size
top_left_edge_style = app.screen.get_style_at(0, 0)
top_left_edge_color = top_left_edge_style.color.name

View File

@@ -159,7 +159,7 @@ class AppTest(App):
# We artificially tell the Compositor that the whole area should be refreshed
screen._compositor._dirty_regions = {
Region(0, 0, screen.size.width, screen.size.height),
Region(0, 0, screen.outer_size.width, screen.outer_size.height),
}
screen.refresh(repaint=repaint, layout=layout)
# We also have to make sure we have at least one dirty widget, or `screen._on_update()` will early return: