-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathbool_btn.py
More file actions
36 lines (29 loc) · 936 Bytes
/
Copy pathbool_btn.py
File metadata and controls
36 lines (29 loc) · 936 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from typing import Callable
from pygame import Rect
from pacman.data_core import FontCfg
from .btn import Btn
from .utils import BtnColor
class BoolBtn(Btn):
def __init__(
self,
text: str,
rect: Rect,
state: bool,
color_true: BtnColor,
color_false: BtnColor,
function: Callable = None,
select_function: Callable = None,
text_size: int = 60,
font: str = FontCfg.DEFAULT,
):
self.__state = state
self.__color_true = color_true
self.__color_false = color_false
super().__init__(text, rect, function, select_function, color_true, text_size, font)
self.__update_color()
def __update_color(self):
self._set_color(self.__color_true if self.__state else self.__color_false)
def click(self) -> None:
super().click()
self.__state = not self.__state
self.__update_color()