Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
eruvanos opened this issue Nov 1, 2024 · 0 comments
Assignees
Labels
enhancement gui Related to arcade GUI (sub module arcade.gui)

Comments

@eruvanos
Copy link
Member

eruvanos commented Nov 1, 2024

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()

@eruvanos eruvanos added enhancement gui Related to arcade GUI (sub module arcade.gui) labels Nov 1, 2024
@eruvanos eruvanos self-assigned this Nov 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement gui Related to arcade GUI (sub module arcade.gui)
Projects
None yet
Development

No branches or pull requests

1 participant