GUI Scrollable Text

For an introduction the GUI system, see GUI Concepts.

Screen shot gui_scrollable_text in action
gui_scrollable_text.py
 1"""
 2If Python and Arcade are installed, this example can be run from the command line with:
 3python -m arcade.examples.gui_scrollable_text
 4"""
 5import arcade
 6from arcade import load_texture
 7from arcade.gui import UIManager, UIInputText, UITextArea
 8from arcade.gui.nine_patch import NinePatchTexture
 9
10LOREM_IPSUM = (
11    "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent eget pellentesque velit. "
12    "Nam eu rhoncus nulla. Fusce ornare libero eget ex vulputate, vitae mattis orci eleifend. "
13    "Donec quis volutpat arcu. Proin lacinia velit id imperdiet ultrices. Fusce porta magna leo, "
14    "non maximus justo facilisis vel. Duis pretium sem ut eros scelerisque, a dignissim ante "
15    "pellentesque. Cras rutrum aliquam fermentum. Donec id mollis mi.\n"
16    "\n"
17    "Nullam vitae nunc aliquet, lobortis purus eget, porttitor purus. Curabitur feugiat purus sit "
18    "amet finibus accumsan. Proin varius, enim in pretium pulvinar, augue erat pellentesque ipsum, "
19    "sit amet varius leo risus quis tellus. Donec posuere ligula risus, et scelerisque nibh cursus "
20    "ac. Mauris feugiat tortor turpis, vitae imperdiet mi euismod aliquam. Fusce vel ligula volutpat, "
21    "finibus sapien in, lacinia lorem. Proin tincidunt gravida nisl in pellentesque. Aenean sed "
22    "arcu ipsum. Vivamus quam arcu, elementum nec auctor non, convallis non elit. Maecenas id "
23    "scelerisque lectus. Vivamus eget sem tristique, dictum lorem eget, maximus leo. Mauris lorem "
24    "tellus, molestie eu orci ut, porta aliquam est. Nullam lobortis tempor magna, egestas lacinia lectus.\n"
25)
26
27
28class MyView(arcade.View):
29    def __init__(self):
30        super().__init__()
31        self.ui = UIManager()
32
33        bg_tex = NinePatchTexture(
34            left=5,
35            right=5,
36            top=5,
37            bottom=5,
38            texture=load_texture(":resources:gui_basic_assets/window/grey_panel.png"))
39        text_area = UITextArea(
40            x=100,
41            y=200,
42            width=200,
43            height=300,
44            text=LOREM_IPSUM,
45            text_color=(0, 0, 0, 255),
46        )
47
48        self.ui.add(text_area.with_padding(all=15).with_background(texture=bg_tex))
49
50        self.ui.add(
51            UIInputText(x=340, y=200, width=200, height=50, text="Hello")
52            .with_background(texture=bg_tex)
53            .with_padding(all=10)
54        )
55
56        self.ui.add(
57            UIInputText(x=340, y=110, width=200, height=50, text="").with_border(),
58        )
59
60    def on_show_view(self):
61        self.window.background_color = arcade.color.DARK_BLUE_GRAY
62        # Enable UIManager when view is shown to catch window events
63        self.ui.enable()
64
65    def on_hide_view(self):
66        # Disable UIManager when view gets inactive
67        self.ui.disable()
68
69    def on_draw(self):
70        self.clear()
71        self.ui.draw()
72
73
74if __name__ == '__main__':
75    window = arcade.Window(800, 600, "UIExample", resizable=True)
76    window.show_view(MyView())
77    window.run()