From 302266b491c6eacc2f8be5e149ac35f0d1991963 Mon Sep 17 00:00:00 2001 From: Maic Siemering Date: Thu, 24 Jul 2025 00:30:55 +0200 Subject: [PATCH 1/2] gui: use incremental layout in UITextArea --- arcade/examples/gui/1_layouts.py | 3 ++- arcade/gui/experimental/scroll_area.py | 6 +++--- arcade/gui/widgets/text.py | 5 +++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/arcade/examples/gui/1_layouts.py b/arcade/examples/gui/1_layouts.py index 51afa9beab..f7d4bc8e29 100644 --- a/arcade/examples/gui/1_layouts.py +++ b/arcade/examples/gui/1_layouts.py @@ -14,6 +14,7 @@ from datetime import datetime import arcade +import arcade.gui from arcade.gui import UIAnchorLayout, UIImage, UITextArea arcade.resources.load_kenney_fonts() @@ -186,5 +187,5 @@ def main(): window.run() -if __name__ == '__main__': +if __name__ == "__main__": main() diff --git a/arcade/gui/experimental/scroll_area.py b/arcade/gui/experimental/scroll_area.py index 5b8ad10617..bd7db75412 100644 --- a/arcade/gui/experimental/scroll_area.py +++ b/arcade/gui/experimental/scroll_area.py @@ -46,9 +46,9 @@ def __init__(self, scroll_area: UIScrollArea, vertical: bool = True): bind(self, "_thumb_hover", UIScrollBar.trigger_render) bind(self, "_dragging", UIScrollBar.trigger_render) - bind(scroll_area, "scroll_x", UIScrollBar.trigger_full_render) - bind(scroll_area, "scroll_y", UIScrollBar.trigger_full_render) - bind(scroll_area, "rect", UIScrollBar.trigger_full_render) + bind(scroll_area, "scroll_x", self.trigger_full_render, weak=True) + bind(scroll_area, "scroll_y", self.trigger_full_render, weak=True) + bind(scroll_area, "rect", self.trigger_full_render, weak=True) def on_event(self, event: UIEvent) -> bool | None: # check if we are scrollable diff --git a/arcade/gui/widgets/text.py b/arcade/gui/widgets/text.py index a9b50cbee8..224de9a7b1 100644 --- a/arcade/gui/widgets/text.py +++ b/arcade/gui/widgets/text.py @@ -855,14 +855,14 @@ def __init__( ), ) - self.layout = pyglet.text.layout.ScrollableTextLayout( + self.layout = pyglet.text.layout.IncrementalTextLayout( self.doc, width=int(self.content_width), height=int(self.content_height), multiline=multiline, ) - bind(self, "rect", self._update_layout) + bind(self, "rect", UITextArea._update_layout) def fit_content(self): """Set the width and height of the text area to contain the whole text.""" @@ -894,6 +894,7 @@ def _update_layout(self): layout.begin_update() layout.width = content_width layout.height = content_height + layout.y = 0 # reset y position to 0 (Required by IncrementalTextLayout) layout.end_update() @override From 42a538c69c527a0ed885ec01d708d6ee140c98ec Mon Sep 17 00:00:00 2001 From: Maic Siemering Date: Tue, 29 Jul 2025 19:40:37 +0200 Subject: [PATCH 2/2] gui: add change log --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index eaa0ec647d..ba77e10b1a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ Arcade [PyPi Release History](https://pypi.org/project/arcade/#history) page. - GUI - Fix a bug, where the caret of UIInputText was misplaced after resizing the widget + - Use incremental layout for UIScrollArea to improve performance of changing text ## 3.3.2