diff --git a/examples/calculator.py b/examples/calculator.py index 9770228c1..8fc80f40a 100644 --- a/examples/calculator.py +++ b/examples/calculator.py @@ -208,7 +208,7 @@ class Calculator(GridView): class CalculatorApp(App): """The Calculator Application""" - async def on_mount(self, event: events.Mount) -> None: + async def on_mount(self) -> None: """Mount the calculator widget.""" await self.view.dock(Calculator()) diff --git a/src/textual/geometry.py b/src/textual/geometry.py index f057f998b..a10f52635 100644 --- a/src/textual/geometry.py +++ b/src/textual/geometry.py @@ -92,6 +92,16 @@ class Size(NamedTuple): width, height = self return Region(0, 0, width, height) + def __add__(self, other: tuple[int, int]) -> Size: + width, height = self + width2, height2 = other + return Size(width + width2, height + height2) + + def __sub__(self, other: tuple[int, int]) -> Size: + width, height = self + width2, height2 = other + return Size(width - width2, height - height2) + def contains(self, x: int, y: int) -> bool: """Check if a point is in the size. diff --git a/src/textual/layout.py b/src/textual/layout.py index 3b3b1de4f..dfba4b4e0 100644 --- a/src/textual/layout.py +++ b/src/textual/layout.py @@ -263,7 +263,7 @@ class Layout(ABC): lines = widget._get_lines() - if clip in region: + if region in clip: yield region, clip, lines elif clip.overlaps(region): new_region = region.intersection(clip) diff --git a/src/textual/layouts/vertical.py b/src/textual/layouts/vertical.py index c128d7e55..63eccc3ae 100644 --- a/src/textual/layouts/vertical.py +++ b/src/textual/layouts/vertical.py @@ -3,6 +3,7 @@ from __future__ import annotations from typing import Iterable from rich.console import Console +from rich.measure import Measurement from .. import log from ..geometry import Offset, Region, Size @@ -34,6 +35,9 @@ class VerticalLayout(Layout): width, height = size gutter_height, gutter_width = self.gutter render_width = width - gutter_width * 2 + + render_width = 1000 + gutter_width * 2 + x = gutter_width y = gutter_height map: LayoutMap = LayoutMap(size) diff --git a/src/textual/widgets/_scroll_view.py b/src/textual/widgets/_scroll_view.py index 4a187e127..74338d57e 100644 --- a/src/textual/widgets/_scroll_view.py +++ b/src/textual/widgets/_scroll_view.py @@ -126,7 +126,7 @@ class ScrollView(View): def scroll_to_center(self, line: int) -> None: self.target_y = line - self.size.height // 2 - if abs(self.target_y - self.y) > 2: + if abs(self.target_y - self.y) > 1: # Animate if its more than 1 self.animate("y", self.target_y, easing="out_cubic") else: @@ -190,18 +190,24 @@ class ScrollView(View): self.animate("x", self.target_x, speed=150, easing="out_cubic") self.animate("y", self.target_y, speed=150, easing="out_cubic") - async def handle_window_change(self, message: Message) -> None: - virtual_size = self.window.virtual_size + def handle_window_change(self) -> None: + virtual_width, virtual_height = self.virtual_size + width, height = self.size + + self.log(self.virtual_size, self.size) self.x = self.validate_x(self.x) self.y = self.validate_y(self.y) - self.vscroll.virtual_size = virtual_size.height - self.vscroll.window_size = self.size.height + + self.hscroll.virtual_size = virtual_width + self.hscroll.window_size = width + self.vscroll.virtual_size = virtual_height + self.vscroll.window_size = height assert isinstance(self.layout, GridLayout) - if self.layout.show_column("vscroll", virtual_size.height > self.size.height): + if self.layout.show_column("vscroll", virtual_height > height): self.refresh() - if self.layout.show_row("hscroll", virtual_size.width > self.size.width): + if self.layout.show_row("hscroll", virtual_width > width): self.refresh() def handle_cursor_move(self, message: CursorMove) -> None: