Skip to content

UITextArea supports attributed or html text mode, but overwrites style in initial text #2441

Open
@eruvanos

Description

@eruvanos

Request

UITextArea supports attributed or html text mode, but overwrites style in initial text.
We need a way to disable this behaviour.

System Info

arcade: dev

Code

import arcade
from arcade import View, open_window
from arcade.gui import UIAnchorLayout, UIManager, UITextArea


class MyView(View):
    def __init__(self):
        super().__init__()

        self.background_color = arcade.color.WHITE
        self.ui = UIManager()  # Setup UIManager
        root = self.ui.add(UIAnchorLayout())
        # UIAnchorLayout is especially useful for positioning UI elements within the center of the screen

        # add a text area with our start text
        ta = root.add(
            UITextArea(
                text="Initial text, using the UITextArea style properties. {color (255, 0, 0, 255)}This should be red{color (0, 0, 0, 255)}!",
                size_hint=(0.5, 0.5),
                document_mode="ATTRIBUTED",
                text_color=arcade.color.BLACK,
            )
        )
        # append some text to the text area, with different styles
        ta.doc.append_text("\n")
        ta.doc.append_text("This text will be added to the text area. \n")
        ta.doc.append_text(
            "Here it is easy to add some style attributes.\n", dict(color=arcade.color.RED)
        )
        ta.doc.append_text(
            "Here it is easy to add some style attributes.\n",
            dict(color=arcade.color.GREEN, underline=arcade.color.BLACK),
        )
        # Style attributes from: https://pyglet.readthedocs.io/en/latest/modules/text/document.html#style-attributes

    def on_show_view(self) -> None:
        self.ui.enable()

    def on_hide_view(self) -> None:
        self.ui.disable()

    def on_draw(self):
        self.clear()
        self.ui.draw()


if __name__ == "__main__":
    open_window(window_title="Minimal example", width=1280, height=720, resizable=True).show_view(
        MyView()
    )
    arcade.run()

Metadata

Metadata

Assignees

Labels

enhancementguiRelated to arcade GUI (sub module arcade.gui)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions