From 02dcad98bd0a975fed320f6e89146264bd57469f Mon Sep 17 00:00:00 2001 From: Peter Harris Date: Tue, 8 Apr 2025 22:35:23 +0100 Subject: [PATCH] Timeline: Clamp event min/max x coord to viewport Limit the event canvas-space coordinates to the size of the viewport to stop labels running off the right-hand side of the screen. --- lglpy/timeline/drawable/world_drawable.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lglpy/timeline/drawable/world_drawable.py b/lglpy/timeline/drawable/world_drawable.py index da4a5b9..77e9615 100644 --- a/lglpy/timeline/drawable/world_drawable.py +++ b/lglpy/timeline/drawable/world_drawable.py @@ -110,6 +110,10 @@ def draw(self, gc, vp): # Round based on final WS position not on WS width max_x, max_y = vp.transform_ws_to_cs(self.ws.max_x, self.ws.max_y, 2) + # Clamp extents to viewport size + x = max(x, vp.cs.min_x) + max_x = min(max_x, vp.cs.max_x) + # Calculate canvas-space width and height w = max_x - x + 1 h = max_y - y + 1