fix for horizontal scrolling

This commit is contained in:
Will McGugan
2021-08-27 21:48:43 +01:00
parent 07fc8e65f1
commit 0696468a1c
5 changed files with 29 additions and 9 deletions

View File

@@ -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())

View File

@@ -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.

View File

@@ -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)

View File

@@ -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)

View File

@@ -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: