1919]
2020
2121from itertools import product
22- from typing import Any , Optional , Union
22+ from typing import Any
2323
2424import pygame
2525
4646
4747def get_scrollbars_from_position (
4848 position : str
49- ) -> Union [ str , tuple [str , str ], tuple [str , str , str , str ] ]:
49+ ) -> str | tuple [str , str ] | tuple [str , str , str , str ]:
5050 """
5151 Return the scrollbars from the given position.
5252
@@ -125,41 +125,41 @@ class ScrollArea(Base):
125125 :param shadow_position: Position of the scrollbar shadow. See :py:mod:`pygame_menu.locals`
126126 :param world: Surface to draw and scroll
127127 """
128- _area_color : Optional [ Union [ ColorInputType , pygame_menu .BaseImage ]]
129- _border_color : Optional [ Union [ ColorInputType , pygame_menu .BaseImage ]]
128+ _area_color : ColorInputType | pygame_menu .BaseImage | None
129+ _border_color : ColorInputType | pygame_menu .BaseImage | None
130130 _border_tiles : list [pygame .Surface ]
131131 _border_tiles_size : Tuple2IntType
132132 _border_width : int
133- _bg_surface : Optional [ pygame .Surface ]
133+ _bg_surface : pygame .Surface | None
134134 _decorator : Decorator
135135 _extend_x : int
136136 _extend_y : int
137- _menu : Optional [ pygame_menu .Menu ]
137+ _menu : pygame_menu .Menu | None
138138 _menubar : pygame_menu .widgets .MenuBar
139139 _parent_scrollarea : ScrollArea
140140 _rect : pygame .Rect
141- _scrollbar_positions : Union [ str , tuple [str , ...] ]
141+ _scrollbar_positions : str | tuple [str , ...]
142142 _scrollbars : list [ScrollBar ]
143143 _scrollbars_props : tuple [Any , ...]
144144 _translate : Tuple2IntType
145145 _view_rect : pygame .Rect
146- _world : Optional [ pygame .Surface ]
146+ _world : pygame .Surface | None
147147
148148 def __init__ (
149149 self ,
150150 area_width : int ,
151151 area_height : int ,
152- area_color : Optional [ Union [ ColorInputType , pygame_menu .BaseImage ]] = None ,
153- border_color : Optional [ Union [ ColorInputType , pygame_menu .BaseImage ]] = None ,
152+ area_color : ColorInputType | pygame_menu .BaseImage | None = None ,
153+ border_color : ColorInputType | pygame_menu .BaseImage | None = None ,
154154 border_width : int = 0 ,
155155 controls_joystick : bool = True ,
156156 controls_keyboard : bool = True ,
157157 controls_mouse : bool = True ,
158158 controls_touchscreen : bool = True ,
159159 extend_x : int = 0 ,
160160 extend_y : int = 0 ,
161- menubar : Optional [ pygame_menu .widgets .MenuBar ] = None ,
162- parent_scrollarea : Optional [ ScrollArea ] = None ,
161+ menubar : pygame_menu .widgets .MenuBar | None = None ,
162+ parent_scrollarea : ScrollArea | None = None ,
163163 scrollarea_id : str = '' ,
164164 scrollbar_color : ColorInputType = (235 , 235 , 235 ),
165165 scrollbar_cursor : CursorInputType = None , # type: ignore
@@ -172,7 +172,7 @@ def __init__(
172172 shadow_color : ColorInputType = (0 , 0 , 0 ),
173173 shadow_offset : int = 2 ,
174174 shadow_position : str = POSITION_SOUTHEAST ,
175- world : Optional [ pygame .Surface ] = None
175+ world : pygame .Surface | None = None
176176 ) -> None :
177177 super ().__init__ (object_id = scrollarea_id )
178178
@@ -344,7 +344,7 @@ def _make_background_surface(self) -> None:
344344
345345 def update_area_color (
346346 self ,
347- color : Optional [ Union [ ColorInputType , pygame_menu .BaseImage ]]
347+ color : ColorInputType | pygame_menu .BaseImage | None
348348 ) -> ScrollArea :
349349 """
350350 Updates area color (background).
@@ -357,7 +357,7 @@ def update_area_color(
357357 self ._make_background_surface ()
358358 return self
359359
360- def set_parent_scrollarea (self , parent : Optional [ ScrollArea ] ) -> ScrollArea :
360+ def set_parent_scrollarea (self , parent : ScrollArea | None ) -> ScrollArea :
361361 """
362362 Set parent ScrollArea.
363363
@@ -368,7 +368,7 @@ def set_parent_scrollarea(self, parent: Optional[ScrollArea]) -> ScrollArea:
368368 self ._parent_scrollarea = parent
369369 return self
370370
371- def get_parent (self ) -> Optional [ ScrollArea ] :
371+ def get_parent (self ) -> ScrollArea | None :
372372 """
373373 Return the parent ScrollArea.
374374
@@ -547,7 +547,7 @@ def draw(self, surface: pygame.Surface) -> ScrollArea:
547547 top -= th
548548
549549 # draw top and bottom tiles
550- area : Optional [ tuple [int , int , int , int ]]
550+ area : tuple [int , int , int , int ] | None
551551
552552 for x in range (border_rect .left , border_rect .right , tw ):
553553 if x + tw >= border_rect .right :
@@ -1072,7 +1072,7 @@ def set_world(self, surface: pygame.Surface) -> ScrollArea:
10721072 self ._apply_size_changes ()
10731073 return self
10741074
1075- def get_world (self ) -> Optional [ pygame .Surface ] :
1075+ def get_world (self ) -> pygame .Surface | None :
10761076 """
10771077 Return the world surface area.
10781078
@@ -1140,9 +1140,9 @@ def get_absolute_view_rect(self) -> pygame.Rect:
11401140
11411141 def to_real_position (
11421142 self ,
1143- virtual : Union [ pygame .Rect , Tuple2NumberType ] ,
1143+ virtual : pygame .Rect | Tuple2NumberType ,
11441144 visible : bool = False
1145- ) -> Union [ pygame .Rect , Tuple2IntType ] :
1145+ ) -> pygame .Rect | Tuple2IntType :
11461146 """
11471147 Return the real position/Rect according to the ScrollArea origin of a
11481148 position/Rect in the world surface reference.
@@ -1174,8 +1174,8 @@ def to_real_position(
11741174
11751175 def to_world_position (
11761176 self ,
1177- real : Union [ pygame .Rect , Tuple2NumberType ]
1178- ) -> Union [ pygame .Rect , Tuple2IntType ] :
1177+ real : pygame .Rect | Tuple2NumberType
1178+ ) -> pygame .Rect | Tuple2IntType :
11791179 """
11801180 Return the position/Rect in the world surface reference of a real
11811181 position/Rect according to the ScrollArea origin.
@@ -1242,7 +1242,7 @@ def set_menu(self, menu: pygame_menu.Menu) -> ScrollArea:
12421242 sbar .set_menu (menu )
12431243 return self
12441244
1245- def get_menu (self ) -> Optional [ pygame_menu .Menu ] :
1245+ def get_menu (self ) -> pygame_menu .Menu | None :
12461246 """
12471247 Return the Menu reference (if exists).
12481248
@@ -1252,7 +1252,7 @@ def get_menu(self) -> Optional[pygame_menu.Menu]:
12521252
12531253 def collide (
12541254 self ,
1255- widget : Union [ pygame_menu .widgets .Widget , pygame .Rect ] ,
1255+ widget : pygame_menu .widgets .Widget | pygame .Rect ,
12561256 event : EventType
12571257 ) -> bool :
12581258 """
@@ -1269,7 +1269,7 @@ def collide(
12691269 widget_rect = widget
12701270 return bool (widget_rect .collidepoint (* get_finger_pos (self ._menu , event )))
12711271
1272- def get_scrollbar (self , position : str ) -> Optional [ ScrollBar ] :
1272+ def get_scrollbar (self , position : str ) -> ScrollBar | None :
12731273 """
12741274 Returns the scrollbar at the given position, or None if not present.
12751275 :param position: The position of the scrollbar (e.g., POSITION_NORTH, POSITION_EAST).
0 commit comments