fix scrolling not working

This commit is contained in:
csd4ni3l
2025-07-16 14:41:48 +02:00
parent 4c245e3db8
commit e53d3d3da7

View File

@@ -208,17 +208,18 @@ class Renderer():
self.batch = pyglet.graphics.Batch() self.batch = pyglet.graphics.Batch()
def on_resize(self, width, height): def hide_out_of_bounds_labels(self):
for widget in self.text_labels: for widget in self.text_labels:
invisible = (widget.y + widget.content_height) > self.window.height * 0.95 invisible = (widget.y + widget.content_height) > self.window.height * 0.925
# Doing visible flag set manually since it takes a lot of time # Doing visible flag set manually since it takes a lot of time
if widget.visible: if widget.visible:
if invisible: if invisible:
widget.visible = False widget.visible = False
elif not widget.visible: else:
if not invisible: if not invisible:
widget.visible = True widget.visible = True
def on_resize(self, width, height):
self.http_client.needs_render = True self.http_client.needs_render = True
def on_mouse_scroll(self, x, y, scroll_x, scroll_y): def on_mouse_scroll(self, x, y, scroll_x, scroll_y):
@@ -226,20 +227,12 @@ class Renderer():
return return
old_y = self.scroll_y old_y = self.scroll_y
self.scroll_y = max(0, min(self.scroll_y - (scroll_y * self.scroll_y_speed), -self.smallest_y)) self.scroll_y = max(0, min(abs(self.scroll_y - (scroll_y * self.scroll_y_speed)), abs(self.smallest_y) - (self.window.height * 0.925) - 10)) # flip scroll direction
for widget in self.text_labels: for widget in self.text_labels:
widget.y += self.scroll_y - old_y widget.y += (self.scroll_y - old_y)
invisible = (widget.y + widget.content_height) > self.window.height * 0.95 self.hide_out_of_bounds_labels()
# Doing visible flag set manually since it takes a lot of time
if widget.visible:
if invisible:
widget.visible = False
elif not widget.visible:
if not invisible:
widget.visible = True
def add_text(self, x, y, text, font, multiline=False): def add_text(self, x, y, text, font, multiline=False):
self.text_labels.append( self.text_labels.append(
@@ -252,12 +245,12 @@ class Renderer():
multiline=multiline, multiline=multiline,
color=arcade.color.BLACK, color=arcade.color.BLACK,
x=x, x=x,
y=(self.window.height * 0.95) - y, y=(self.window.height * 0.925) - y,
batch=self.batch batch=self.batch
) )
) )
if y < self.smallest_y: if (self.window.height * 0.925) - y < self.smallest_y:
self.smallest_y = y self.smallest_y = y
def update(self): def update(self):
@@ -297,4 +290,6 @@ class Renderer():
paint_tree(self.document, self.display_list) paint_tree(self.document, self.display_list)
for x, y, text, font in self.display_list: for x, y, text, font in self.display_list:
self.add_text(x, y, text, font) self.add_text(x, y, text, font)
self.hide_out_of_bounds_labels()