batframework 1.0.8a1__py3-none-any.whl → 1.0.8a3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- batFramework/action.py +30 -14
- batFramework/actionContainer.py +5 -3
- batFramework/audioManager.py +0 -1
- batFramework/camera.py +29 -24
- batFramework/cutscene.py +2 -4
- batFramework/entity.py +9 -2
- batFramework/enums.py +11 -2
- batFramework/fontManager.py +1 -1
- batFramework/gui/__init__.py +3 -1
- batFramework/gui/button.py +5 -2
- batFramework/gui/clickableWidget.py +42 -29
- batFramework/gui/constraints/constraints.py +269 -57
- batFramework/gui/container.py +39 -21
- batFramework/gui/debugger.py +18 -11
- batFramework/gui/dialogueBox.py +20 -17
- batFramework/gui/draggableWidget.py +7 -5
- batFramework/gui/image.py +27 -15
- batFramework/gui/indicator.py +1 -4
- batFramework/gui/interactiveWidget.py +91 -30
- batFramework/gui/label.py +44 -35
- batFramework/gui/layout.py +115 -43
- batFramework/gui/meter.py +3 -8
- batFramework/gui/radioButton.py +47 -25
- batFramework/gui/root.py +50 -25
- batFramework/gui/shape.py +14 -19
- batFramework/gui/slider.py +70 -44
- batFramework/gui/style.py +10 -0
- batFramework/gui/styleManager.py +48 -0
- batFramework/gui/textInput.py +25 -22
- batFramework/gui/toggle.py +42 -29
- batFramework/gui/widget.py +176 -115
- batFramework/object.py +9 -10
- batFramework/renderGroup.py +7 -2
- batFramework/scene.py +70 -49
- batFramework/sceneManager.py +15 -20
- batFramework/scrollingSprite.py +5 -3
- batFramework/sprite.py +20 -14
- batFramework/stateMachine.py +1 -2
- batFramework/tileset.py +5 -5
- batFramework/utils.py +12 -10
- {batframework-1.0.8a1.dist-info → batframework-1.0.8a3.dist-info}/METADATA +1 -1
- batframework-1.0.8a3.dist-info/RECORD +58 -0
- {batframework-1.0.8a1.dist-info → batframework-1.0.8a3.dist-info}/WHEEL +1 -1
- batframework-1.0.8a1.dist-info/RECORD +0 -56
- {batframework-1.0.8a1.dist-info → batframework-1.0.8a3.dist-info}/LICENCE +0 -0
- {batframework-1.0.8a1.dist-info → batframework-1.0.8a3.dist-info}/top_level.txt +0 -0
batFramework/gui/dialogueBox.py
CHANGED
@@ -14,11 +14,14 @@ class DialogueBox(Label):
|
|
14
14
|
self.set_alignment(bf.alignment.LEFT)
|
15
15
|
super().__init__("")
|
16
16
|
|
17
|
-
def
|
17
|
+
def __str__(self) -> str:
|
18
|
+
return "DialogueBox"
|
19
|
+
|
20
|
+
def pause(self) -> Self:
|
18
21
|
self.is_paused = True
|
19
22
|
return self
|
20
|
-
|
21
|
-
def resume(self)->Self:
|
23
|
+
|
24
|
+
def resume(self) -> Self:
|
22
25
|
self.is_paused = False
|
23
26
|
return self
|
24
27
|
|
@@ -28,40 +31,40 @@ class DialogueBox(Label):
|
|
28
31
|
|
29
32
|
def cut_text_to_width(self, text: str) -> list[str]:
|
30
33
|
w = self.get_padded_width()
|
31
|
-
if text == "" or not self.font_object or
|
34
|
+
if text == "" or not self.font_object or w < self.font_object.point_size:
|
32
35
|
return [text]
|
33
36
|
left = 0
|
34
37
|
for index in range(len(text)):
|
35
38
|
width = self.font_object.size(text[left:index])[0]
|
36
|
-
|
39
|
+
|
37
40
|
if width > w:
|
38
41
|
cut_point_start = index - 1
|
39
42
|
cut_point_end = index - 1
|
40
|
-
last_space = text.rfind(
|
41
|
-
last_nline = text.rfind(
|
43
|
+
last_space = text.rfind(" ", 0, cut_point_start)
|
44
|
+
last_nline = text.rfind("\n", 0, cut_point_start)
|
42
45
|
|
43
|
-
if last_space != -1 or last_nline!= -1: # space was found !:
|
44
|
-
cut_point_start = max(last_space,last_nline)
|
46
|
+
if last_space != -1 or last_nline != -1: # space was found !:
|
47
|
+
cut_point_start = max(last_space, last_nline)
|
45
48
|
cut_point_end = cut_point_start + 1
|
46
49
|
res = [text[:cut_point_start].strip()]
|
47
50
|
res.extend(self.cut_text_to_width(text[cut_point_end:].strip()))
|
48
51
|
return res
|
49
|
-
elif text[index] ==
|
52
|
+
elif text[index] == "\n":
|
50
53
|
left = index
|
51
54
|
return [text]
|
52
55
|
|
53
|
-
def paint(self)->None:
|
54
|
-
if self.font_object and self.message_queue
|
56
|
+
def paint(self) -> None:
|
57
|
+
if self.font_object and self.message_queue:
|
55
58
|
message = self.message_queue.pop(0)
|
56
59
|
message = "\n".join(self.cut_text_to_width(message))
|
57
|
-
self.message_queue.insert(0,message)
|
60
|
+
self.message_queue.insert(0, message)
|
58
61
|
super().paint()
|
59
|
-
|
60
|
-
def say(self, message: str) ->Self:
|
62
|
+
|
63
|
+
def say(self, message: str) -> Self:
|
61
64
|
self.message_queue.append(message)
|
62
65
|
self.is_over = False
|
63
66
|
return self
|
64
|
-
|
67
|
+
|
65
68
|
def is_queue_empty(self) -> bool:
|
66
69
|
return not self.message_queue
|
67
70
|
|
@@ -80,7 +83,7 @@ class DialogueBox(Label):
|
|
80
83
|
self.set_text("")
|
81
84
|
return self
|
82
85
|
|
83
|
-
def skip_current_message(self)->Self:
|
86
|
+
def skip_current_message(self) -> Self:
|
84
87
|
self.cursor_position = len(self.message_queue[0])
|
85
88
|
self.dirty_shape = True
|
86
89
|
|
@@ -17,19 +17,21 @@ class DraggableWidget(InteractiveWidget):
|
|
17
17
|
def do_reset_actions(self) -> None:
|
18
18
|
self.drag_action.reset()
|
19
19
|
|
20
|
-
def do_on_drag(
|
21
|
-
self
|
20
|
+
def do_on_drag(
|
21
|
+
self, drag_start: tuple[float, float], drag_end: tuple[float, float]
|
22
|
+
) -> None:
|
23
|
+
self.set_position(drag_end[0] - self.offset[0], drag_end[1] - self.offset[1])
|
22
24
|
|
23
25
|
def update(self, dt: float):
|
24
26
|
if self.drag_action.active and self.is_clicked_down:
|
25
27
|
r = self.get_root()
|
26
28
|
x, y = r.drawing_camera.screen_to_world(pygame.mouse.get_pos())
|
27
29
|
if self.drag_start == None and self.drag_action.active:
|
28
|
-
self.offset = x-self.rect.x,y-self.rect.y
|
29
|
-
self.drag_start = x,y
|
30
|
+
self.offset = x - self.rect.x, y - self.rect.y
|
31
|
+
self.drag_start = x, y
|
30
32
|
return
|
31
33
|
else:
|
32
|
-
self.do_on_drag(self.drag_start,(x,y))
|
34
|
+
self.do_on_drag(self.drag_start, (x, y))
|
33
35
|
return
|
34
36
|
else:
|
35
37
|
self.drag_start = None
|
batFramework/gui/image.py
CHANGED
@@ -1,47 +1,59 @@
|
|
1
1
|
import batFramework as bf
|
2
2
|
from .widget import Widget
|
3
|
+
from .shape import Shape
|
3
4
|
import pygame
|
4
5
|
from typing import Self
|
5
6
|
|
6
7
|
|
7
|
-
class Image(
|
8
|
+
class Image(Shape):
|
8
9
|
def __init__(
|
9
10
|
self,
|
10
11
|
path: str = None,
|
11
12
|
convert_alpha=True,
|
12
13
|
):
|
13
14
|
self.original_surface = None
|
14
|
-
super().__init__(convert_alpha
|
15
|
+
super().__init__(convert_alpha=convert_alpha)
|
15
16
|
if path is not None:
|
16
17
|
self.from_path(path)
|
17
18
|
|
19
|
+
def __str__(self) -> str:
|
20
|
+
return "Image"
|
21
|
+
|
18
22
|
def paint(self) -> None:
|
19
23
|
super().paint()
|
20
|
-
self.surface.fill((0,0,0,0 if self.convert_alpha else 255))
|
24
|
+
# self.surface.fill((0,0,0,0 if self.convert_alpha else 255))
|
25
|
+
if self.original_surface is None:
|
26
|
+
return
|
21
27
|
if self.rect.size != self.original_surface.get_size():
|
22
|
-
self.surface.blit(
|
28
|
+
self.surface.blit(
|
29
|
+
pygame.transform.scale(self.original_surface, self.rect.size), (0, 0)
|
30
|
+
)
|
23
31
|
else:
|
24
|
-
self.surface.blit(self.original_surface,(0,0))
|
25
|
-
|
32
|
+
self.surface.blit(self.original_surface, (0, 0))
|
26
33
|
|
27
|
-
def from_path(self,path:str)->Self:
|
28
|
-
tmp = bf.ResourceManager().get_image(path,self.convert_alpha)
|
34
|
+
def from_path(self, path: str) -> Self:
|
35
|
+
tmp = bf.ResourceManager().get_image(path, self.convert_alpha)
|
29
36
|
if tmp is None:
|
30
37
|
return self
|
31
38
|
self.original_surface = tmp
|
32
39
|
size = self.original_surface.get_size()
|
33
|
-
if not self.autoresize_h
|
34
|
-
|
40
|
+
if not self.autoresize_h:
|
41
|
+
size[0] = None
|
42
|
+
if not self.autoresize_h:
|
43
|
+
size[1] = None
|
35
44
|
self.set_size(size)
|
36
45
|
self.dirty_surface = True
|
37
46
|
return self
|
38
47
|
|
39
|
-
def from_surface(self,surface: pygame.Surface)->Self:
|
40
|
-
if surface is None
|
48
|
+
def from_surface(self, surface: pygame.Surface) -> Self:
|
49
|
+
if surface is None:
|
50
|
+
return self
|
41
51
|
self.original_surface = surface
|
42
52
|
size = self.original_surface.get_size()
|
43
|
-
if not self.autoresize_h
|
44
|
-
|
53
|
+
if not self.autoresize_h:
|
54
|
+
size[0] = None
|
55
|
+
if not self.autoresize_h:
|
56
|
+
size[1] = None
|
45
57
|
self.set_size(size)
|
46
58
|
self.dirty_surface = True
|
47
|
-
return self
|
59
|
+
return self
|
batFramework/gui/indicator.py
CHANGED
@@ -23,7 +23,6 @@ class Indicator(Shape):
|
|
23
23
|
def get_value(self) -> Any:
|
24
24
|
pass
|
25
25
|
|
26
|
-
|
27
26
|
def top_at(self, x, y):
|
28
27
|
return None
|
29
28
|
|
@@ -31,7 +30,7 @@ class Indicator(Shape):
|
|
31
30
|
class ToggleIndicator(Indicator):
|
32
31
|
def __init__(self, default_value: bool) -> None:
|
33
32
|
self.value: bool = default_value
|
34
|
-
self.callback = lambda val
|
33
|
+
self.callback = lambda val: self.set_color("green" if val else "red")
|
35
34
|
super().__init__((20, 20))
|
36
35
|
self.set_value(default_value)
|
37
36
|
|
@@ -56,5 +55,3 @@ class ToggleIndicator(Indicator):
|
|
56
55
|
if r is self:
|
57
56
|
return None
|
58
57
|
return r
|
59
|
-
|
60
|
-
|
@@ -23,7 +23,7 @@ class InteractiveWidget(Widget):
|
|
23
23
|
return self
|
24
24
|
|
25
25
|
def allow_focus_to_self(self) -> bool:
|
26
|
-
return
|
26
|
+
return self.visible
|
27
27
|
|
28
28
|
def get_focus(self) -> bool:
|
29
29
|
if self.focusable and ((r := self.get_root()) is not None):
|
@@ -47,22 +47,90 @@ class InteractiveWidget(Widget):
|
|
47
47
|
self.is_focused = False
|
48
48
|
self.do_on_lose_focus()
|
49
49
|
|
50
|
-
def
|
50
|
+
def focus_next_tab(self, previous_widget):
|
51
|
+
|
52
|
+
if previous_widget != self and self.visible:
|
53
|
+
if (
|
54
|
+
isinstance(self, InteractiveWidget)
|
55
|
+
and not isinstance(self, bf.Container)
|
56
|
+
and self.allow_focus_to_self()
|
57
|
+
):
|
58
|
+
self.focus_next_sibling()
|
59
|
+
return
|
60
|
+
i_children = [
|
61
|
+
c
|
62
|
+
for c in self.children
|
63
|
+
if isinstance(c, InteractiveWidget) and c.visible
|
64
|
+
]
|
65
|
+
if i_children:
|
66
|
+
index = i_children.index(previous_widget)
|
67
|
+
if index < len(i_children) - 1:
|
68
|
+
|
69
|
+
i_children[index + 1].get_focus()
|
70
|
+
return
|
71
|
+
|
72
|
+
if self.parent:
|
73
|
+
self.parent.focus_next_tab(self)
|
74
|
+
|
75
|
+
def focus_prev_tab(self, previous_widget):
|
76
|
+
if previous_widget != self and self.visible:
|
77
|
+
if (
|
78
|
+
isinstance(self, InteractiveWidget)
|
79
|
+
and not isinstance(self, bf.Container)
|
80
|
+
and self.allow_focus_to_self()
|
81
|
+
):
|
82
|
+
self.get_focus()
|
83
|
+
return
|
84
|
+
i_children = [
|
85
|
+
c
|
86
|
+
for c in self.children
|
87
|
+
if isinstance(c, InteractiveWidget) and c.visible
|
88
|
+
]
|
89
|
+
|
90
|
+
if i_children:
|
91
|
+
index = i_children.index(previous_widget)
|
92
|
+
if index > 0:
|
93
|
+
i_children[index - 1].get_focus()
|
94
|
+
return
|
95
|
+
|
96
|
+
if self.parent:
|
97
|
+
self.parent.focus_prev_tab(self)
|
98
|
+
|
99
|
+
def focus_next_sibling(self) -> None:
|
100
|
+
if isinstance(self.parent, bf.Container):
|
101
|
+
self.parent.focus_next_child()
|
102
|
+
|
103
|
+
def focus_prev_sibling(self) -> None:
|
104
|
+
if isinstance(self.parent, bf.Container):
|
105
|
+
self.parent.focus_prev_child()
|
106
|
+
|
107
|
+
def on_key_down(self, key) -> bool:
|
51
108
|
if key == pygame.K_DOWN:
|
52
109
|
self.focus_next_sibling()
|
53
110
|
elif key == pygame.K_UP:
|
54
111
|
self.focus_prev_sibling()
|
112
|
+
elif key == pygame.K_TAB and self.parent:
|
113
|
+
keys = pygame.key.get_pressed()
|
114
|
+
if keys[pygame.K_LSHIFT] or keys[pygame.K_RSHIFT]:
|
115
|
+
|
116
|
+
self.focus_prev_tab(self)
|
117
|
+
else:
|
118
|
+
self.focus_next_tab(self)
|
119
|
+
|
55
120
|
else:
|
56
|
-
self.do_on_key_down(key)
|
57
121
|
|
58
|
-
|
59
|
-
self.do_on_key_up(key)
|
122
|
+
return self.do_on_key_down(key)
|
60
123
|
|
61
|
-
|
62
|
-
pass
|
124
|
+
return False
|
63
125
|
|
64
|
-
def
|
65
|
-
|
126
|
+
def on_key_up(self, key) -> bool:
|
127
|
+
return self.do_on_key_up(key)
|
128
|
+
|
129
|
+
def do_on_key_down(self, key) -> bool:
|
130
|
+
return False
|
131
|
+
|
132
|
+
def do_on_key_up(self, key) -> bool:
|
133
|
+
return False
|
66
134
|
|
67
135
|
def do_on_get_focus(self) -> None:
|
68
136
|
pass
|
@@ -70,27 +138,19 @@ class InteractiveWidget(Widget):
|
|
70
138
|
def do_on_lose_focus(self) -> None:
|
71
139
|
pass
|
72
140
|
|
73
|
-
def
|
74
|
-
if isinstance(self.parent, bf.Container):
|
75
|
-
self.parent.focus_next_child()
|
76
|
-
|
77
|
-
def focus_prev_sibling(self) -> None:
|
78
|
-
if isinstance(self.parent, bf.Container):
|
79
|
-
self.parent.focus_prev_child()
|
80
|
-
|
81
|
-
def on_click_down(self, button: int) -> None:
|
141
|
+
def on_click_down(self, button: int) -> bool:
|
82
142
|
self.is_clicked_down = True
|
83
|
-
self.do_on_click_down(button)
|
143
|
+
return self.do_on_click_down(button)
|
84
144
|
|
85
|
-
def on_click_up(self, button: int) ->
|
145
|
+
def on_click_up(self, button: int) -> bool:
|
86
146
|
self.is_clicked_down = False
|
87
|
-
self.do_on_click_up(button)
|
147
|
+
return self.do_on_click_up(button)
|
88
148
|
|
89
|
-
def do_on_click_down(self, button: int) ->
|
90
|
-
|
149
|
+
def do_on_click_down(self, button: int) -> bool:
|
150
|
+
return False
|
91
151
|
|
92
|
-
def do_on_click_up(self, button: int) ->
|
93
|
-
|
152
|
+
def do_on_click_up(self, button: int) -> bool:
|
153
|
+
return False
|
94
154
|
|
95
155
|
def on_enter(self) -> None:
|
96
156
|
self.is_hovered = True
|
@@ -108,18 +168,19 @@ class InteractiveWidget(Widget):
|
|
108
168
|
pass
|
109
169
|
|
110
170
|
def on_mouse_motion(self, x, y) -> None:
|
111
|
-
self.do_on_mouse_motion(x,y)
|
171
|
+
self.do_on_mouse_motion(x, y)
|
112
172
|
|
113
|
-
def do_on_mouse_motion(self,x,y)->None:
|
173
|
+
def do_on_mouse_motion(self, x, y) -> None:
|
114
174
|
pass
|
115
175
|
|
116
176
|
def set_focused_child(self, child: "InteractiveWidget"):
|
117
177
|
pass
|
118
178
|
|
119
|
-
def draw_focused(self, camera: bf.Camera) -> None:
|
120
|
-
delta = 4 + ((2*cos(pygame.time.get_ticks()/100)) //2) * 2
|
179
|
+
def draw_focused(self, camera: bf.Camera) -> None:
|
180
|
+
delta = 4 + ((2 * cos(pygame.time.get_ticks() / 100)) // 2) * 2
|
121
181
|
pygame.draw.rect(
|
122
182
|
camera.surface,
|
123
183
|
"white",
|
124
|
-
self.rect.move(-camera.rect.x
|
184
|
+
self.rect.move(-camera.rect.x, -camera.rect.y).inflate(delta, delta),
|
185
|
+
1,
|
125
186
|
)
|
batFramework/gui/label.py
CHANGED
@@ -7,8 +7,8 @@ from typing import Self
|
|
7
7
|
class Label(Shape):
|
8
8
|
_text_cache = {}
|
9
9
|
|
10
|
-
def __init__(self, text: str) -> None:
|
11
|
-
self.text =
|
10
|
+
def __init__(self, text: str = "") -> None:
|
11
|
+
self.text = text
|
12
12
|
|
13
13
|
self.resized_flag: bool = False
|
14
14
|
|
@@ -34,7 +34,7 @@ class Label(Shape):
|
|
34
34
|
# reference to the font object
|
35
35
|
self.font_object = None
|
36
36
|
# Rect containing the text of the label
|
37
|
-
self.text_rect = pygame.FRect(0,0,0,0)
|
37
|
+
self.text_rect = pygame.FRect(0, 0, 0, 0)
|
38
38
|
# text surface (result of font.render)
|
39
39
|
self.text_surface: pygame.Surface = pygame.Surface((0, 0))
|
40
40
|
self.do_caching: bool = False
|
@@ -53,12 +53,14 @@ class Label(Shape):
|
|
53
53
|
self.set_color("gray50")
|
54
54
|
self.set_autoresize(True)
|
55
55
|
self.set_font(force=True)
|
56
|
-
self.set_text(text)
|
57
56
|
|
58
57
|
@staticmethod
|
59
58
|
def clear_cache():
|
60
59
|
Label._text_cache = {}
|
61
60
|
|
61
|
+
def __str__(self) -> str:
|
62
|
+
return f"Label({self.text})"
|
63
|
+
|
62
64
|
def enable_caching(self) -> Self:
|
63
65
|
self.do_caching = True
|
64
66
|
return self
|
@@ -76,7 +78,7 @@ class Label(Shape):
|
|
76
78
|
if value == self.is_italic:
|
77
79
|
return self
|
78
80
|
self.is_italic = value
|
79
|
-
if self.autoresize_h or self.autoresize_w:
|
81
|
+
if self.autoresize_h or self.autoresize_w:
|
80
82
|
self.dirty_shape = True
|
81
83
|
else:
|
82
84
|
self.dirty_surface = True
|
@@ -86,7 +88,7 @@ class Label(Shape):
|
|
86
88
|
if value == self.is_bold:
|
87
89
|
return self
|
88
90
|
self.is_bold = value
|
89
|
-
if self.autoresize_h or self.autoresize_w:
|
91
|
+
if self.autoresize_h or self.autoresize_w:
|
90
92
|
self.dirty_shape = True
|
91
93
|
else:
|
92
94
|
self.dirty_surface = True
|
@@ -123,9 +125,6 @@ class Label(Shape):
|
|
123
125
|
self.dirty_surface = True
|
124
126
|
return self
|
125
127
|
|
126
|
-
def __str__(self) -> str:
|
127
|
-
return f"Label({self.text})"
|
128
|
-
|
129
128
|
def set_alignment(self, alignment: bf.alignment) -> "Label":
|
130
129
|
self.alignment = alignment
|
131
130
|
self.dirty_surface = True
|
@@ -133,22 +132,23 @@ class Label(Shape):
|
|
133
132
|
|
134
133
|
def set_auto_wraplength(self, val: bool) -> "Label":
|
135
134
|
self.auto_wraplength = val
|
136
|
-
if self.autoresize_h or self.autoresize_w:
|
135
|
+
if self.autoresize_h or self.autoresize_w:
|
137
136
|
self.dirty_shape = True
|
138
137
|
else:
|
139
138
|
self.dirty_surface = True
|
140
139
|
return self
|
141
140
|
|
142
141
|
def get_debug_outlines(self):
|
142
|
+
if self.visible:
|
143
|
+
yield (self.text_rect.move(*self.rect.topleft), "purple")
|
143
144
|
yield from super().get_debug_outlines()
|
144
|
-
|
145
|
-
|
145
|
+
|
146
146
|
def set_font(self, font_name: str = None, force: bool = False) -> Self:
|
147
147
|
if font_name == self.font_name and not force:
|
148
148
|
return self
|
149
149
|
self.font_name = font_name
|
150
150
|
self.font_object = bf.FontManager().get_font(self.font_name, self.text_size)
|
151
|
-
if self.autoresize_h or self.autoresize_w:
|
151
|
+
if self.autoresize_h or self.autoresize_w:
|
152
152
|
self.dirty_shape = True
|
153
153
|
else:
|
154
154
|
self.dirty_surface = True
|
@@ -160,7 +160,7 @@ class Label(Shape):
|
|
160
160
|
return self
|
161
161
|
self.text_size = text_size
|
162
162
|
self.font_object = bf.FontManager().get_font(self.font_name, self.text_size)
|
163
|
-
if self.autoresize_h or self.autoresize_w:
|
163
|
+
if self.autoresize_h or self.autoresize_w:
|
164
164
|
self.dirty_shape = True
|
165
165
|
return self
|
166
166
|
|
@@ -182,8 +182,8 @@ class Label(Shape):
|
|
182
182
|
self.dirty_shape = True
|
183
183
|
return self
|
184
184
|
|
185
|
-
def get_min_required_size(self)->tuple[float,float]:
|
186
|
-
if not (self.autoresize_w or
|
185
|
+
def get_min_required_size(self) -> tuple[float, float]:
|
186
|
+
if not (self.autoresize_w or self.autoresize_h):
|
187
187
|
return self.rect.size
|
188
188
|
if not self.text_rect:
|
189
189
|
params = {
|
@@ -192,13 +192,17 @@ class Label(Shape):
|
|
192
192
|
"antialias": False,
|
193
193
|
"color": "white",
|
194
194
|
"bgcolor": "black", # if (self.has_alpha_color() or self.draw_mode == bf.drawMode.TEXTURED) else self.color,
|
195
|
-
"wraplength":
|
195
|
+
"wraplength": (
|
196
|
+
int(self.get_padded_width()) if self.auto_wraplength else 0
|
197
|
+
),
|
196
198
|
}
|
197
199
|
|
198
200
|
self.text_rect.size = self._render_font(params).get_size()
|
199
|
-
res = self.inflate_rect_by_padding((0,0
|
201
|
+
res = self.inflate_rect_by_padding((0, 0, *self.text_rect.size)).size
|
200
202
|
# return res
|
201
|
-
return res[0] if self.autoresize_w else self.rect.w,
|
203
|
+
return res[0] if self.autoresize_w else self.rect.w, (
|
204
|
+
res[1] if self.autoresize_h else self.rect.h
|
205
|
+
)
|
202
206
|
|
203
207
|
def get_text(self) -> str:
|
204
208
|
return self.text
|
@@ -212,19 +216,19 @@ class Label(Shape):
|
|
212
216
|
if cached_value is None:
|
213
217
|
params.pop("font_name")
|
214
218
|
|
215
|
-
#save old settings
|
219
|
+
# save old settings
|
216
220
|
old_italic = self.font_object.get_italic()
|
217
221
|
old_bold = self.font_object.get_bold()
|
218
222
|
old_underline = self.font_object.get_underline()
|
219
223
|
|
220
|
-
#setup font
|
224
|
+
# setup font
|
221
225
|
self.font_object.set_italic(self.is_italic)
|
222
226
|
self.font_object.set_bold(self.is_bold)
|
223
227
|
self.font_object.set_underline(self.is_underlined)
|
224
|
-
|
228
|
+
|
225
229
|
surf = self.font_object.render(**params)
|
226
230
|
|
227
|
-
# reset font
|
231
|
+
# reset font
|
228
232
|
self.font_object.set_italic(old_italic)
|
229
233
|
self.font_object.set_bold(old_bold)
|
230
234
|
self.font_object.set_underline(old_underline)
|
@@ -251,16 +255,18 @@ class Label(Shape):
|
|
251
255
|
}
|
252
256
|
|
253
257
|
self.text_rect.size = self._render_font(params).get_size()
|
254
|
-
if self.autoresize_h or self.autoresize_w:
|
255
|
-
target_rect = self.inflate_rect_by_padding((0,0
|
256
|
-
if not self.autoresize_w
|
257
|
-
|
258
|
+
if self.autoresize_h or self.autoresize_w:
|
259
|
+
target_rect = self.inflate_rect_by_padding((0, 0, *self.text_rect.size))
|
260
|
+
if not self.autoresize_w:
|
261
|
+
target_rect.w = self.rect.w
|
262
|
+
if not self.autoresize_h:
|
263
|
+
target_rect.h = self.rect.h
|
258
264
|
if self.rect.size != target_rect.size:
|
259
265
|
self.set_size(target_rect.size)
|
260
266
|
self.build()
|
261
267
|
return
|
262
|
-
padded = self.get_padded_rect().move(-self.rect.x
|
263
|
-
self.align_text(self.text_rect,padded,self.alignment)
|
268
|
+
padded = self.get_padded_rect().move(-self.rect.x, -self.rect.y)
|
269
|
+
self.align_text(self.text_rect, padded, self.alignment)
|
264
270
|
|
265
271
|
def _paint_text(self) -> None:
|
266
272
|
if self.font_object is None:
|
@@ -284,7 +290,6 @@ class Label(Shape):
|
|
284
290
|
.to_surface(setcolor=self.text_outline_color, unsetcolor=(0, 0, 0, 0))
|
285
291
|
)
|
286
292
|
|
287
|
-
|
288
293
|
l = []
|
289
294
|
if self.show_text_outline:
|
290
295
|
l.append(
|
@@ -298,18 +303,22 @@ class Label(Shape):
|
|
298
303
|
)
|
299
304
|
self.surface.fblits(l)
|
300
305
|
|
301
|
-
def align_text(
|
302
|
-
|
303
|
-
|
306
|
+
def align_text(
|
307
|
+
self, text_rect: pygame.FRect, area: pygame.FRect, alignment: bf.alignment
|
308
|
+
):
|
309
|
+
if alignment == bf.alignment.LEFT:
|
310
|
+
alignment = bf.alignment.MIDLEFT
|
311
|
+
elif alignment == bf.alignment.MIDRIGHT:
|
312
|
+
alignment = bf.alignment.MIDRIGHT
|
304
313
|
|
305
314
|
pos = area.__getattribute__(alignment.value)
|
306
|
-
text_rect.__setattr__(alignment.value,pos)
|
315
|
+
text_rect.__setattr__(alignment.value, pos)
|
307
316
|
|
308
317
|
def build(self) -> None:
|
309
318
|
super().build()
|
310
319
|
self._build_layout()
|
311
320
|
|
312
|
-
def paint(self)->None:
|
321
|
+
def paint(self) -> None:
|
313
322
|
super().paint()
|
314
323
|
if self.font_object:
|
315
324
|
self._paint_text()
|