Skip to content

Commit

Permalink
fix PriorityDrawer
Browse files Browse the repository at this point in the history
  • Loading branch information
gottadiveintopython committed Dec 22, 2023
1 parent d9d000d commit f2aeab6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/asyncpygame/_api_impl/priority_drawing.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,11 @@ def zorder(self, zorder):
req = self.__req
if req.zorder == zorder:
return
req.cancel()
self.__req = self.__add_request(req.draw, zorder)
if req.cancelled:
req.zorder = zorder
else:
req.cancel()
self.__req = self.__add_request(req.draw, zorder)

@property
def draw(self) -> DrawFunc:
Expand Down
21 changes: 21 additions & 0 deletions tests/_api_impl/test_priority_drawing.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,24 @@ def test_various_zorders():
req.draw = lambda v: value_list.append(v + v + v)
d.draw('E')
assert value_list == ['EEE', 'EE', 'E', ]


def test_change_zorder_while_inactive():
from asyncpygame._api_impl.priority_drawing import Drawer, DrawingRequest

d = Drawer()
value_list = []

req = DrawingRequest(d.add_request, value_list.append, zorder=0)
DrawingRequest(d.add_request, lambda v: value_list.append(v.lower()), zorder=1)
d.draw('A')
assert value_list == ['A', 'a']
req.active = False
d.draw('B')
assert value_list == ['A', 'a', 'b']
req.zorder = 2
d.draw('C')
assert value_list == ['A', 'a', 'b', 'c']
req.active = True
d.draw('D')
assert value_list == ['A', 'a', 'b', 'c', 'd', 'D']

0 comments on commit f2aeab6

Please sign in to comment.