Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 18 additions & 17 deletions arcade/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ def __init__(
# self.invalid = False
set_window(self)

self.push_handlers(on_resize=self._on_resize)

self._ctx: ArcadeContext = ArcadeContext(self, gc_mode=gc_mode, gl_api=gl_api)
self._background_color: Color = TRANSPARENT_BLACK

Expand Down Expand Up @@ -601,31 +603,30 @@ def on_draw(self) -> Optional[bool]:
"""
return False

def on_resize(self, width: int, height: int) -> Optional[bool]:
def _on_resize(self, width: int, height: int):
"""
Override this function to add custom code to be called any time the window
is resized. The main responsibility of this method is updating
the projection and the viewport.

If you are not changing the default behavior when overriding, make sure
you call the parent's ``on_resize`` first::

def on_resize(self, width: int, height: int):
super().on_resize(width, height)
# Add extra resize logic here
Update the screen's viewport. If you need custom behaviour on resize there is another
method that can be overridden.

:param width: New width
:param height: New height
"""
# NOTE: When a second window is opened pyglet will
# dispatch on_resize during the window constructor.
# The arcade context is not created at that time
if hasattr(self, "_ctx"):
# Retain projection scrolling if applied
self.viewport = (0, 0, width, height)

# Retain viewport
self.viewport = (0, 0, width, height)

return False

def on_resize(self, width: int, height: int) -> Optional[bool]:
"""
Override this function to add custom code to be called any time the window
is resized.

:param width: New width
:param height: New height
"""
pass

def set_min_size(self, width: int, height: int) -> None:
"""Wrap the Pyglet window call to set minimum size

Expand Down