Skip to content

Commit

Permalink
fix for horizontal scrolling
Browse files Browse the repository at this point in the history
  • Loading branch information
willmcgugan committed Aug 27, 2021
1 parent 07fc8e6 commit 0696468
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 9 deletions.
2 changes: 1 addition & 1 deletion examples/calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def do_math() -> None:
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())

Expand Down
10 changes: 10 additions & 0 deletions src/textual/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,16 @@ def region(self) -> Region:
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.
Expand Down
2 changes: 1 addition & 1 deletion src/textual/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def _get_renders(self, console: Console) -> Iterable[tuple[Region, Region, Lines

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)
Expand Down
4 changes: 4 additions & 0 deletions src/textual/layouts/vertical.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import Iterable

from rich.console import Console
from rich.measure import Measurement

from .. import log
from ..geometry import Offset, Region, Size
Expand Down Expand Up @@ -34,6 +35,9 @@ def generate_map(
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)
Expand Down
20 changes: 13 additions & 7 deletions src/textual/widgets/_scroll_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def scroll_in_to_view(self, line: int) -> None:

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:
Expand Down Expand Up @@ -190,18 +190,24 @@ async def handle_scroll_to(self, message: ScrollTo) -> None:
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:
Expand Down

0 comments on commit 0696468

Please sign in to comment.