Skip to content
Merged
Show file tree
Hide file tree
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
7 changes: 5 additions & 2 deletions arcade/gui/surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,11 @@ def activate(self) -> Generator[Self, None, None]:
# Restore blend function.
self.ctx.blend_func = prev_blend_func

def limit(self, rect: Rect):
"""Reduces the draw area to the given rect"""
def limit(self, rect: Rect | None = None):
"""Reduces the draw area to the given rect, or resets it to the full surface."""

if rect is None:
rect = LBWH(0, 0, *self.size)

l, b, w, h = rect.lbwh
w = max(w, 1)
Expand Down
13 changes: 12 additions & 1 deletion tests/unit/gui/test_surface.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from arcade import load_texture
from arcade import LBWH, load_texture
from arcade.gui import Surface, NinePatchTexture


Expand All @@ -25,3 +25,14 @@ def keywords_only(**kwargs):

with pytest.raises(NotImplementedError):
keywords_only(alpha=10, angle=30.0)


def test_limit_surface(window):
surface = Surface(size=(100, 100))
assert surface._cam.viewport == LBWH(0, 0, 100, 100)

surface.limit(LBWH(10, 10, 80, 80))
assert surface._cam.viewport == LBWH(10, 10, 80, 80)

surface.limit(None)
assert surface._cam.viewport == LBWH(0, 0, 100, 100)
Loading