Example #1
0
def test_ui_style_dispatches_event_on_change():
    style = UIStyle({})
    updated_style_classes = None

    @style.event()
    def on_style_change(style_classes: Set[str]):
        nonlocal updated_style_classes
        updated_style_classes = style_classes

    style.set_class_attrs('some-class', color=arcade.color.BLUE)

    assert {'some-class'} == updated_style_classes
Example #2
0
def main():
    defaults = dict(
        center_x=0,
        center_y=0,
    )
    window = Window()
    view = UIView()

    style = UIStyle.default_style()
    style.set_class_attrs(UILabel.__name__, )

    layout = ListLayout()
    layout.pack(UILabel(text="1. Red Sun", **defaults), space=15)
    layout.pack(UILabel(text="2. Green Gras", **defaults))
    layout.pack(UILabel(text="3. Blue Sky", **defaults), space=20)
    view.manager.add_layout(layout)

    layout = ListLayout(vertical=False)
    layout.pack(UILabel(text="4. Red Sun", **defaults), space=15)
    layout.pack(UILabel(text="5. Green Gras", **defaults))
    layout.pack(UILabel(text="6. Blue Sky", **defaults), space=20)
    view.manager.add_layout(layout)

    window.show_view(view)
    arcade.run()
Example #3
0
def test_style_returns_none_for_unknown_ui_element_class():
    style = UIStyle({
        'flatbutton': {
            'normal_color': arcade.color.RED
        },
    })
    button = UIGhostFlatButton('Love snakes.', 100, 100, 100, 30, style=style)

    assert button.style_attr('normal_color') is None
Example #4
0
def test_new_class_for_custom_overwrites():
    style = UIStyle({
        'flatbutton': {
            'normal_color': arcade.color.RED
        },
    })
    button = UIGhostFlatButton('Love snakes.', 100, 100, 100, 30, style=style)
    button.set_style_attrs(normal_color=arcade.color.BLUE)

    assert button.style_attr('normal_color') == arcade.color.BLUE
    assert len(style.data) == 2
 def setup(self):
     self.ui_manager.purge_ui_elements()
     #default style sheet
     UIStyle.default_style().set_class_attrs(
         'buttons',
         font_color=arcade.color.WHITE,
         font_color_hover=arcade.color.WHITE,
         font_color_press=arcade.color.WHITE,
         bg_color=(135, 21, 25),
         bg_color_hover=(135, 21, 25),
         bg_color_press=(122, 21, 24),
         border_color=(135, 21, 25),
         border_color_hover=arcade.color.WHITE,
         border_color_press=arcade.color.WHITE)
     #add buttons to UI manager
     self.ui_manager.add_ui_element(
         SinglePlayerButton(self.window.height // 2, self.window,
                            self.ui_manager))
     self.ui_manager.add_ui_element(
         MultiPlayerButton(self.window.height // 3, self.window,
                           self.ui_manager))
Example #6
0
    def on_show_view(self):
        arcade.set_background_color(arcade.color.BLACK)
        self.ui_manager.purge_ui_elements()

        flat = UIFlatButton('Hello world',
                            center_x=200,
                            center_y=self.window.height // 2,
                            width=200,
                            height=40)
        flat.set_style_attrs(font_color=arcade.color.WHITE,
                             font_color_hover=arcade.color.WHITE,
                             font_color_press=arcade.color.WHITE,
                             bg_color=(51, 139, 57),
                             bg_color_hover=(51, 139, 57),
                             bg_color_press=(28, 71, 32),
                             border_color=(51, 139, 57),
                             border_color_hover=arcade.color.WHITE,
                             border_color_press=arcade.color.WHITE)
        self.ui_manager.add_ui_element(flat)

        # creates a new class, which will match the id
        UIStyle.default_style().set_class_attrs(
            'right_button',
            font_color=arcade.color.WHITE,
            font_color_hover=arcade.color.WHITE,
            font_color_press=arcade.color.WHITE,
            bg_color=(135, 21, 25),
            bg_color_hover=(135, 21, 25),
            bg_color_press=(122, 21, 24),
            border_color=(135, 21, 25),
            border_color_hover=arcade.color.WHITE,
            border_color_press=arcade.color.WHITE)
        self.ui_manager.add_ui_element(
            UIGhostFlatButton('Hello world',
                              center_x=600,
                              center_y=self.window.height // 2,
                              width=200,
                              height=40,
                              id='right_button'))
Example #7
0
def test_style_returns_property_for_custom_ui_element():
    class MyButton(UIFlatButton):
        """Custom button, which should use style attributes of FlatButton"""
        pass

    style = UIStyle({
        'flatbutton': {
            'normal_color': arcade.color.RED
        },
    })

    flat = MyButton('Love snakes.', 100, 100, 100, 30, style=style)

    assert flat.style_attr('normal_color') == arcade.color.RED
Example #8
0
def test_style_returns_property_for_ui_elements():
    style = UIStyle({
        'flatbutton': {
            'normal_color': arcade.color.RED
        },
        'ghostflatbutton': {
            'normal_color': arcade.color.BLUE
        },
    })
    flat = UIFlatButton('Love snakes.', 100, 100, 100, 30, style=style)
    ghost = UIGhostFlatButton('Love snakes.', 100, 100, 100, 30, style=style)

    assert flat.style_attr('normal_color') == arcade.color.RED
    assert ghost.style_attr('normal_color') == arcade.color.BLUE
Example #9
0
    def __init__(self, text: str, center_x: int = 0, center_y: int = 0):
        super().__init__(text,
                         center_x,
                         center_y,
                         width=self.UNHOVER_WIDTH,
                         height=self.UNHOVER_HEIGHT,
                         style=UIStyle(border_width=0))

        self.set_style_attrs(
            font_color=arcade.color.WHITE,
            font_color_hover=arcade.color.WHITE,
            font_color_press=arcade.color.WHITE,
            font_name="assets/title-screen/LuckiestGuy-Regular.ttf",
            font_size=35)
Example #10
0
    def __init__(self,
                 center_x=0,
                 center_y=0,
                 id: Optional[str] = None,
                 style: UIStyle = None,
                 **kwargs):
        super().__init__()
        # ID for this element, to search in view by id or identify this element from an event
        self.__id = id
        self.mng: Optional['UIManager'] = None

        # unique id, to overwrite style for exactly this element, DONT CHANGE THIS LATER
        self.__style_id = str(uuid4())
        self.style_classes = ['globals']
        self._style: UIStyle = style if style else UIStyle.default_style()
        self._style.push_handlers(self.on_style_change)

        # what do we need to look like a proper arcade.Sprite
        # self.texture <- subclass
        # self.width/height <- subclass
        self.center_x = center_x
        self.center_y = center_y
Example #11
0
import arcade
from arcade.gui.ui_style import UIStyle

from src.menu import Menu
from src.globals import *

if __name__ == "__main__":
    # Sets a basic UIStyle for a label
    UIStyle.default_style().set_class_attrs(
        'label',
        font_color=arcade.color.WHITE,
        font_color_hover=arcade.color.WHITE,
        font_color_press=arcade.color.WHITE,
    )

    window = arcade.Window(title='Democracy defender',
                           height=HEIGHT,
                           width=WIDTH)
    window.show_view(Menu())
    arcade.run()
Example #12
0
def style() -> UIStyle:
    return UIStyle({
        'globals': {'font_color': arcade.color.BLACK},
        ELEMENT_STYLE_CLASS: {'normal_color': DEFAULT_COLOR}
    })
Example #13
0
def test_ui_element_uses_default_style():
    button = UIFlatButton('Love snakes.', 100, 100, 100, 30)

    assert button._style == UIStyle.default_style()
Example #14
0
def test_ui_style_has_on_change_event_type():
    style = UIStyle({})
    assert 'on_style_change' in style.event_types