Example #1
0
    def test_add_button(self, _init_pygame, default_ui_manager):
        panel = UIPanel(relative_rect=pygame.Rect(50, 50, 150, 400),
                        starting_layer_height=5,
                        manager=default_ui_manager,
                        margins={
                            'left': 10,
                            'right': 10,
                            'top': 5,
                            'bottom': 5
                        })

        assert panel.layer_thickness == 1

        button = UIButton(
            relative_rect=pygame.Rect(100, 100, 150, 30),
            text="Test Button",
            tool_tip_text=
            "This is a test of the button's tool tip functionality.",
            manager=default_ui_manager,
            container=panel)

        assert button.layer_thickness == 1
        assert panel.get_container(
        ).layer_thickness == 2  # happens 'cause elements added to container hover 1 layer up
        panel.update(0.05)
        assert panel.layer_thickness == 2
Example #2
0
    def test_kill(self, _init_pygame, default_ui_manager: IUIManagerInterface):
        panel = UIPanel(relative_rect=pygame.Rect(50, 50, 150, 400),
                        starting_layer_height=5,
                        manager=default_ui_manager,
                        margins={
                            'left': 10,
                            'right': 10,
                            'top': 5,
                            'bottom': 5
                        })

        button = UIButton(
            relative_rect=pygame.Rect(100, 100, 150, 30),
            text="Test Button",
            tool_tip_text=
            "This is a test of the button's tool tip functionality.",
            manager=default_ui_manager,
            container=panel)

        assert len(default_ui_manager.get_root_container().elements) == 2
        assert len(default_ui_manager.get_sprite_group().sprites()) == 4
        assert default_ui_manager.get_sprite_group().sprites() == [
            default_ui_manager.get_root_container(), panel,
            panel.get_container(), button
        ]
        panel.kill()
        assert len(default_ui_manager.get_root_container().elements) == 0
        assert len(default_ui_manager.get_sprite_group().sprites()) == 1
        assert default_ui_manager.get_sprite_group().sprites() == [
            default_ui_manager.get_root_container()
        ]
Example #3
0
    def test_update(self, _init_pygame, default_ui_manager):
        panel = UIPanel(relative_rect=pygame.Rect(50, 50, 150, 400),
                        starting_layer_height=5,
                        manager=default_ui_manager,
                        margins={
                            'left': 10,
                            'right': 10,
                            'top': 5,
                            'bottom': 5
                        })

        assert panel.layer_thickness == 1
        assert panel.get_container().layer_thickness == 0
        panel.get_container().layer_thickness = 4
        assert panel.layer_thickness == 1
        panel.update(0.05)
        assert panel.layer_thickness == 4