pythonarcade / arcade

Easy to use Python library for creating 2D arcade games.
http://arcade.academy
Other
1.68k stars 319 forks source link

Texture Button cuts itself on resizing window #2349

Open Piedpiper5 opened 3 weeks ago

Piedpiper5 commented 3 weeks ago

So basically what is happening is that if the initial screen size is small (i don’t know how small) and u try to maximise it via the button on top right of the window the button cuts 3/4 off it self but if u manually maximise the window with ur cursor as much as u can and then click the top right button of the window it works fine (button doesn’t cut off).

Arcade 3.0.0.dev33

vendor: Intel renderer: Intel(R) HD Graphics 5500 version: (3, 3) python: 3.11.0 (main, Oct 24 2022, 18:26:48) [MSC v.1933 64 bit (AMD64)] platform: win32 pyglet version: 2.1.dev5 PIL version: 10.2.0

Actual behavior:

Button cuts off

Expected behavior:

Button doesn’t cut off

Steps to reproduce/example code:

Just run below code and click the maximise button of the opened window:

import arcade import arcade.gui print(arcade.get_display_size()[0], arcade.get_display_size()[1])

class StartingScreen(arcade.View): def init(self): super().init()

    self.ui_manager = arcade.gui.UIManager()
    self.ui_manager.enable()

    self.play_button_texture = arcade.load_texture(":resources:onscreen_controls/shaded_light/start.png")

    self.play_button = arcade.gui.UITextureButton(
        x=self.window.width / 4,
        y=self.window.height / 2.5,
        width=self.window.width / 2,
        height=self.window.height / 5,
        texture=self.play_button_texture
    )

    self.ui_manager.add(self.play_button)

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

def on_resize(self, width, height):
    starting_screen = StartingScreen()
    self.window.show_view(starting_screen)

if name == 'main': window = arcade.Window( resizable=True, width = 683, height = 384 ) window.show_view(StartingScreen()) window.run()

Enhancement request:

I don’t know

What should be added/changed?

I don’t know

(rest of the questions are not applicable/irrelevant)

eruvanos commented 3 weeks ago

I fixed the example code to be runnable:

import arcade
import arcade.gui

print(arcade.get_display_size()[0], arcade.get_display_size()[1])

class StartingScreen(arcade.View):
    def __init__(self):
        super().__init__()

        self.ui_manager = arcade.gui.UIManager()
        self.ui_manager.enable()

        self.play_button_texture = arcade.load_texture(
            ":resources:onscreen_controls/shaded_light/start.png"
        )

        self.play_button = arcade.gui.UITextureButton(
            x=self.window.width / 4,
            y=self.window.height / 2.5,
            width=self.window.width / 2,
            height=self.window.height / 5,
            texture=self.play_button_texture,
        )

        self.ui_manager.add(self.play_button)

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

    def on_resize(self, width, height):
        starting_screen = StartingScreen()
        self.window.show_view(starting_screen)

if __name__ == "__main__":
    window = arcade.Window(resizable=True, width=683, height=384)
    window.show_view(StartingScreen())
    window.run()
eruvanos commented 3 weeks ago

I will check, if I can somehow reproduce this.

@Piedpiper5 Can you check with this version:

import arcade
import arcade.gui

print(arcade.get_display_size()[0], arcade.get_display_size()[1])

PLAY_BUTTON_TEXTURE = arcade.load_texture(":resources:onscreen_controls/shaded_light/start.png")

class StartingScreen(arcade.View):
    def __init__(self):
        super().__init__()

        self.ui_manager = arcade.gui.UIManager()

        # self.play_button = arcade.gui.UITextureButton(
        #     x=self.window.width / 4,
        #     y=self.window.height / 2.5,
        #     width=self.window.width / 2,
        #     height=self.window.height / 5,
        #     texture=self.play_button_texture,
        # )
        # self.ui_manager.add(self.play_button)

        # using size_hint, and anchor layout
        self.play_button = arcade.gui.UITextureButton(
            texture=PLAY_BUTTON_TEXTURE,
            size_hint=(0.5, 0.2),
        )
        root = self.ui_manager.add(arcade.gui.UIAnchorLayout())
        root.add(self.play_button, anchor_x="center", anchor_y="center")

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

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

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

if __name__ == "__main__":
    window = arcade.Window(resizable=True, width=683, height=384)
    window.show_view(StartingScreen())
    window.run()