pygame-widget-kit 0.0.1__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.
@@ -0,0 +1,48 @@
1
+ import pygame
2
+ from .Text import *
3
+ from .UIComponent import *
4
+
5
+ class Button(UIComponent):
6
+ def __init__(self, text_str = "Button",
7
+ pos = (0,0),
8
+ size = (200,40),
9
+ style=None,
10
+ z_index=0,
11
+ color=(255,175,175),
12
+ border_color = None,
13
+ hover_color=(150,150,150),
14
+ text_color = (0,0,0)):
15
+ self.text_str = text_str
16
+ self.size = size
17
+ self.text_color =text_color
18
+ self.text = Text(self.text_str,pos = (20,20),text_color=text_color,bg_color=None)
19
+
20
+ rect = (pos[0],pos[1],self.size[0],self.size[1])
21
+ self.cc = 0
22
+ super().__init__(rect, style, z_index, color, border_color, hover_color)
23
+ self.add_child(self.text)
24
+
25
+ def draw(self, surface):
26
+ if self.visible == False:
27
+ return
28
+
29
+ color = self.color
30
+ if self.hovered:
31
+ color=self.hover_color
32
+
33
+ if color is not None:
34
+ pygame.draw.rect(surface,color,self.absolute_rect,0)
35
+
36
+ self.text.draw(surface)
37
+
38
+
39
+ def handle_event(self, event):
40
+ if event.type == pygame.MOUSEBUTTONDOWN:
41
+ self.active = True
42
+
43
+ elif event.type == pygame.MOUSEBUTTONUP:
44
+ self.active = False
45
+
46
+ def on_click(self, event):
47
+ print("Button clicked",self.cc)
48
+ self.cc +=1
@@ -0,0 +1,138 @@
1
+ import pygame
2
+ from .UIComponent import UIComponent
3
+ from .Text import Text
4
+
5
+
6
+ class SelectOption(UIComponent):
7
+ def __init__(self, text, value, rect, parent_select, color=(200,200,200)):
8
+ super().__init__(rect, color=color)
9
+ self.value = value
10
+ self.parent_select = parent_select
11
+
12
+ self.label = Text(
13
+ text_str=text,
14
+ pos=(5, 5),
15
+ text_color=(0,0,0)
16
+ )
17
+ self.add_child(self.label)
18
+
19
+ def handle_event(self, event):
20
+ if not self.enabled or not self.visible:
21
+ return
22
+
23
+ if event.type == pygame.MOUSEBUTTONUP:
24
+ if self.is_in_rect(event.pos):
25
+ self.on_click(event)
26
+
27
+ def on_click(self, event):
28
+ self.parent_select.set_value(self.value)
29
+ self.parent_select.close()
30
+
31
+
32
+
33
+ class Select(UIComponent):
34
+ def __init__(
35
+ self,
36
+ rect,
37
+ options:list[tuple[str, any]],
38
+ default_index=0,
39
+ color=(180,180,180),
40
+ hover_color=(200,200,200)
41
+ ):
42
+ super().__init__(rect, color=color, hover_color=hover_color)
43
+
44
+ self.options = options
45
+ self.is_open = False
46
+ self.selected_index = default_index
47
+
48
+ # Görünen text
49
+ self.text = Text(
50
+ text_str=self.options[self.selected_index][0],
51
+ pos=(8, 8),
52
+ text_color=(0,0,0)
53
+ )
54
+ self.add_child(self.text)
55
+
56
+ # Dropdown option container
57
+ self.option_height = rect[3]
58
+ self.option_components:list[SelectOption] = []
59
+
60
+ def toggle(self):
61
+ if self.is_open:
62
+ self.close()
63
+ else:
64
+ self.open()
65
+
66
+ def open(self):
67
+ if self.is_open:
68
+ return
69
+
70
+ self.is_open = True
71
+ self.option_components.clear()
72
+
73
+ base_x, base_y, w, h = self.rect
74
+
75
+ for i, (label, value) in enumerate(self.options):
76
+ opt_rect = (
77
+ 0,
78
+ h * (i + 1),
79
+ w,
80
+ h
81
+ )
82
+
83
+ opt = SelectOption(
84
+ label,
85
+ value,
86
+ opt_rect,
87
+ parent_select=self,
88
+ color=(220,220,220)
89
+ )
90
+ opt.z_index = self.z_index + 1
91
+ self.add_child(opt)
92
+ self.option_components.append(opt)
93
+
94
+ self.ui_manager.modal = self
95
+
96
+
97
+ def close(self):
98
+ self.is_open = False
99
+
100
+ for opt in self.option_components:
101
+ self.children.remove(opt)
102
+
103
+ self.option_components.clear()
104
+ self.ui_manager.modal = None
105
+
106
+ def set_value(self, value):
107
+ for i, (_, v) in enumerate(self.options):
108
+ if v == value:
109
+ self.selected_index = i
110
+ self.text.update_text(self.options[i][0])
111
+ break
112
+
113
+ def on_click(self, event):
114
+ self.toggle()
115
+
116
+ def draw(self, surface: pygame.Surface):
117
+
118
+ super().draw(surface)
119
+
120
+ cx = self.absolute_rect[0] + self.absolute_rect[2] - 15
121
+ cy = self.absolute_rect[1] + self.absolute_rect[3] // 2
122
+
123
+ if self.is_open:
124
+ # ▲ yukarı bakan caret
125
+ points = [
126
+ (cx - 5, cy + 3),
127
+ (cx + 5, cy + 3),
128
+ (cx, cy - 3),
129
+ ]
130
+ else:
131
+ # ▼ aşağı bakan caret
132
+ points = [
133
+ (cx - 5, cy - 3),
134
+ (cx + 5, cy - 3),
135
+ (cx, cy + 3),
136
+ ]
137
+
138
+ pygame.draw.polygon(surface, (0, 0, 0), points)
@@ -0,0 +1,83 @@
1
+ import pygame
2
+ from .UIComponent import *
3
+
4
+ class Text(UIComponent):
5
+ def __init__(self, text_str="",font_size=25,
6
+ font_type='Veranda',pos=(0,0),
7
+ text_color:tuple[int,int,int] = (0,0,0),
8
+ bg_color:tuple[int,int,int] = (0,0,0),
9
+ style=None,
10
+ z_index=0,
11
+ color=None,
12
+ border_color=...):
13
+
14
+ self.font_size=font_size
15
+ self.font_type=font_type
16
+ self.font = pygame.font.SysFont(self.font_type, self.font_size)
17
+ self.text_str = text_str
18
+ self.text_color = text_color
19
+ self.render = self.font.render(text_str, True,self.text_color , None)
20
+ self.size = self.render.get_size()
21
+ rect = (pos[0],pos[1],self.size[0],self.size[1])
22
+
23
+ super().__init__(rect, style, z_index, color, border_color)
24
+
25
+ def update_text(self,new_text_str):
26
+ self.text_str = new_text_str
27
+ self.render = self.font.render(self.text_str, True,self.text_color , None)
28
+ self.size = self.render.get_size()
29
+
30
+
31
+ def update_font_size(self,new_size):
32
+ self.font_size = new_size
33
+ self.font = pygame.font.SysFont(self.font_type, self.font_size)
34
+ self.render = self.font.render(self.text_str, True,(255,255,255) , None)
35
+ self.size = self.render.get_size()
36
+ def update_font_type(self,new_type):
37
+ self.font_type = new_type
38
+ self.font = pygame.font.SysFont(self.font_type, self.font_size)
39
+ self.render = self.font.render(self.text_str, True,(255,255,255) , None)
40
+ self.size = self.render.get_size()
41
+
42
+
43
+ def draw(self, surface):
44
+ surface.blit(self.render,self.absolute_rect)
45
+
46
+
47
+
48
+
49
+ """
50
+
51
+ class text():
52
+ def __init__(self,text_str="",font_size=25,font_type='Veranda',pos=(0,0),text_color:tuple[int,int,int] = (0,0,0)):
53
+ self.font_size=font_size
54
+ self.font_type=font_type
55
+ self.font = pygame.font.SysFont(self.font_type, self.font_size)
56
+ self.text_str = text_str
57
+ self.text_color = text_color
58
+ self.render = self.font.render(text_str, True,self.text_color , None)
59
+ self.size = self.render.get_size()
60
+ self.pos = pos
61
+
62
+ def draw(self,pencere:pygame.Surface):
63
+ pencere.blit(self.render,self.pos)
64
+
65
+ def update_text(self,new_text_str):
66
+ self.text_str = new_text_str
67
+ self.render = self.font.render(self.text_str, True,self.text_color , None)
68
+ self.size = self.render.get_size()
69
+
70
+ def update_pos(self,new_pos):
71
+ self.pos = new_pos
72
+ def update_font_size(self,new_size):
73
+ self.font_size = new_size
74
+ self.font = pygame.font.SysFont(self.font_type, self.font_size)
75
+ self.render = self.font.render(self.text_str, True,(255,255,255) , None)
76
+ self.size = self.render.get_size()
77
+ def update_font_type(self,new_type):
78
+ self.font_type = new_type
79
+ self.font = pygame.font.SysFont(self.font_type, self.font_size)
80
+ self.render = self.font.render(self.text_str, True,(255,255,255) , None)
81
+ self.size = self.render.get_size()
82
+
83
+ """
@@ -0,0 +1,301 @@
1
+ import pygame
2
+ from .UIComponent import UIComponent
3
+ from .Text import Text
4
+
5
+ class TextInput2(UIComponent):
6
+ def __init__(
7
+ self,
8
+ rect,
9
+ initial_text="",
10
+ text_color=(0, 0, 0),
11
+ bg_color=(220, 220, 220),
12
+ hover_color=(240, 240, 240),
13
+ caret_color=(0, 0, 0),
14
+ padding=6,
15
+ z_index=0
16
+ ):
17
+ super().__init__(
18
+ rect=rect,
19
+ z_index=z_index,
20
+ color=bg_color,
21
+ hover_color=hover_color
22
+ )
23
+
24
+ self.text_value = initial_text
25
+ self.text_color = text_color
26
+ self.caret_color = caret_color
27
+ self.padding = padding
28
+
29
+ # Text child
30
+ self.text = Text(
31
+ text_str=self.text_value,
32
+ pos=(self.padding, self.padding),
33
+ text_color=self.text_color
34
+ )
35
+ self.add_child(self.text)
36
+
37
+ # caret
38
+ self.caret_visible = True
39
+ self._caret_timer = 0
40
+ self._caret_interval = 500 # ms
41
+ def handle_event(self, event):
42
+ if not self.enabled or not self.visible:
43
+ return
44
+
45
+ if event.type == pygame.KEYDOWN and self.focused:
46
+
47
+ # ESC → blur
48
+ if event.key == pygame.K_ESCAPE:
49
+ if self.ui_manager:
50
+ self.ui_manager.focused = None
51
+ self.on_blur()
52
+ return
53
+
54
+ # ENTER → blur (submit gibi düşünebilirsin)
55
+ if event.key == pygame.K_RETURN:
56
+ if self.ui_manager:
57
+ self.ui_manager.focused = None
58
+ self.on_blur()
59
+ return
60
+
61
+ # BACKSPACE
62
+ if event.key == pygame.K_BACKSPACE:
63
+ self.text_value = self.text_value[:-1]
64
+
65
+ # Printable characters
66
+ else:
67
+ if event.unicode and event.unicode.isprintable():
68
+ self.text_value += event.unicode
69
+
70
+ self.text.update_text(self.text_value)
71
+ def on_click(self, event):
72
+ # sadece focus almak yeterli
73
+ pass
74
+ def update(self, dt):
75
+ if not self.focused:
76
+ self.caret_visible = False
77
+ return
78
+
79
+ self._caret_timer += dt
80
+ if self._caret_timer >= self._caret_interval:
81
+ self._caret_timer = 0
82
+ self.caret_visible = not self.caret_visible
83
+ def draw(self, surface: pygame.Surface):
84
+ super().draw(surface)
85
+
86
+ # caret sadece focused iken
87
+ if self.focused and self.caret_visible:
88
+ text_w, text_h = self.text.render.get_size()
89
+
90
+ caret_x = (
91
+ self.absolute_rect[0]
92
+ + self.padding
93
+ + text_w
94
+ )
95
+ caret_y = (
96
+ self.absolute_rect[1]
97
+ + self.padding
98
+ )
99
+
100
+ caret_rect = pygame.Rect(
101
+ caret_x,
102
+ caret_y,
103
+ 2,
104
+ text_h
105
+ )
106
+
107
+ pygame.draw.rect(surface, self.caret_color, caret_rect)
108
+ def get_value(self):
109
+ return self.text_value
110
+
111
+ def set_value(self, value: str):
112
+ self.text_value = value
113
+ self.text.update_text(value)
114
+
115
+ def clear(self):
116
+ self.set_value("")
117
+
118
+
119
+ class TextInput(UIComponent):
120
+ def __init__(
121
+ self,
122
+ rect,
123
+ initial_text="",
124
+ text_color=(0, 0, 0),
125
+ bg_color=(220, 220, 220),
126
+ hover_color=(240, 240, 240),
127
+ selection_color=(100, 150, 255),
128
+ caret_color=(0, 0, 0),
129
+ padding=6,
130
+ z_index=0
131
+ ):
132
+ super().__init__(
133
+ rect=rect,
134
+ z_index=z_index,
135
+ color=bg_color,
136
+ hover_color=hover_color
137
+ )
138
+
139
+ self.text_value = initial_text
140
+ self.text_color = text_color
141
+ self.selection_color = selection_color
142
+ self.caret_color = caret_color
143
+ self.padding = padding
144
+
145
+ # text render
146
+ self.text = Text(
147
+ text_str=self.text_value,
148
+ pos=(self.padding, self.padding),
149
+ text_color=self.text_color
150
+ )
151
+ self.add_child(self.text)
152
+
153
+ # caret & selection
154
+ self.cursor_index = len(self.text_value)
155
+ self.selection_start = None
156
+ self.selection_end = None
157
+ self.dragging = False
158
+
159
+ # caret blink
160
+ self.caret_visible = True
161
+ self._caret_timer = 0
162
+ self._caret_interval = 500
163
+
164
+ pygame.scrap.init()
165
+ def _mouse_to_index(self, mouse_x):
166
+ local_x = mouse_x - self.absolute_rect[0] - self.padding
167
+ if local_x <= 0:
168
+ return 0
169
+
170
+ for i in range(len(self.text_value) + 1):
171
+ w = self.text.font.size(self.text_value[:i])[0]
172
+ if local_x < w:
173
+ return i
174
+
175
+ return len(self.text_value)
176
+ def on_click(self, event):
177
+ self.dragging = True
178
+ self.cursor_index = self._mouse_to_index(event.pos[0])
179
+ self.selection_start = self.cursor_index
180
+ self.selection_end = None
181
+ def handle_event(self, event):
182
+ if not self.focused or not self.enabled:
183
+ return
184
+
185
+ # MOUSE DRAG SELECTION
186
+ if event.type == pygame.MOUSEMOTION and self.dragging:
187
+ idx = self._mouse_to_index(event.pos[0])
188
+ self.selection_end = idx
189
+ self.cursor_index = idx
190
+
191
+ if event.type == pygame.MOUSEBUTTONUP:
192
+ self.dragging = False
193
+ if self.selection_start == self.selection_end:
194
+ self.selection_start = self.selection_end = None
195
+ if event.type == pygame.KEYDOWN:
196
+
197
+ ctrl = event.mod & pygame.KMOD_CTRL
198
+
199
+ # COPY
200
+ if ctrl and event.key == pygame.K_c and self.has_selection():
201
+ pygame.scrap.put(
202
+ pygame.SCRAP_TEXT,
203
+ self.get_selected_text().encode()
204
+ )
205
+ return
206
+
207
+ # PASTE
208
+ if ctrl and event.key == pygame.K_v:
209
+ clip = pygame.scrap.get(pygame.SCRAP_TEXT)
210
+ if clip:
211
+ self.insert_text(clip.decode())
212
+ return
213
+
214
+ # BACKSPACE
215
+ if event.key == pygame.K_BACKSPACE:
216
+ if self.has_selection():
217
+ self.delete_selection()
218
+ elif self.cursor_index > 0:
219
+ self.text_value = (
220
+ self.text_value[:self.cursor_index - 1]
221
+ + self.text_value[self.cursor_index:]
222
+ )
223
+ self.cursor_index -= 1
224
+
225
+ # NORMAL CHARACTER
226
+ elif event.unicode and event.unicode.isprintable():
227
+ self.insert_text(event.unicode)
228
+
229
+ self.text.update_text(self.text_value)
230
+ def has_selection(self):
231
+ return (
232
+ self.selection_start is not None
233
+ and self.selection_end is not None
234
+ and self.selection_start != self.selection_end
235
+ )
236
+
237
+ def get_selection_range(self):
238
+ return sorted((self.selection_start, self.selection_end))
239
+
240
+ def get_selected_text(self):
241
+ a, b = self.get_selection_range()
242
+ return self.text_value[a:b]
243
+
244
+ def delete_selection(self):
245
+ a, b = self.get_selection_range()
246
+ self.text_value = self.text_value[:a] + self.text_value[b:]
247
+ self.cursor_index = a
248
+ self.selection_start = self.selection_end = None
249
+
250
+ def insert_text(self, s):
251
+ if self.has_selection():
252
+ self.delete_selection()
253
+
254
+ self.text_value = (
255
+ self.text_value[:self.cursor_index]
256
+ + s
257
+ + self.text_value[self.cursor_index:]
258
+ )
259
+ self.cursor_index += len(s)
260
+ def update(self, dt):
261
+ if not self.focused:
262
+ self.caret_visible = False
263
+ return
264
+
265
+ self._caret_timer += dt
266
+ if self._caret_timer >= self._caret_interval:
267
+ self._caret_timer = 0
268
+ self.caret_visible = not self.caret_visible
269
+ def draw(self, surface):
270
+ super().draw(surface)
271
+
272
+ # SELECTION
273
+ if self.has_selection():
274
+ a, b = self.get_selection_range()
275
+ x1 = self.absolute_rect[0] + self.padding + self.text.font.size(self.text_value[:a])[0]
276
+ x2 = self.absolute_rect[0] + self.padding + self.text.font.size(self.text_value[:b])[0]
277
+
278
+ h = self.text.render.get_height()
279
+ y = self.absolute_rect[1] + self.padding
280
+
281
+ pygame.draw.rect(
282
+ surface,
283
+ self.selection_color,
284
+ (x1, y, x2 - x1, h)
285
+ )
286
+
287
+ # redraw text over selection
288
+ self.text.draw(surface)
289
+
290
+ # CARET
291
+ if self.focused and self.caret_visible:
292
+ cx = self.absolute_rect[0] + self.padding + self.text.font.size(
293
+ self.text_value[:self.cursor_index]
294
+ )[0]
295
+ cy = self.absolute_rect[1] + self.padding
296
+
297
+ pygame.draw.rect(
298
+ surface,
299
+ self.caret_color,
300
+ (cx, cy, 2, self.text.render.get_height())
301
+ )
@@ -0,0 +1,130 @@
1
+ import pygame
2
+
3
+ class UIComponent:
4
+ def __init__(self, rect, style=None,z_index = 0, color = None, border_color:tuple[int,int,int] = (0,255,0),hover_color = None):
5
+ self.rect = rect
6
+ self.absolute_rect = rect
7
+ #self.style = style or {}
8
+
9
+ self.parent:UIComponent = None
10
+ self.children:list[UIComponent] = []
11
+ self.ui_manager = None
12
+
13
+ self.visible = True
14
+ self.enabled = True
15
+
16
+ self.hovered = False
17
+ self.active = False
18
+ self.focused = False
19
+ self.z_index = z_index
20
+
21
+ self.border_color = border_color
22
+ self.show_border = True if border_color is not None else False
23
+
24
+
25
+ self.color = color
26
+
27
+ self.hover_color = hover_color or (tuple(min(c + 30, 255) for c in color) if color is not None else None)
28
+
29
+
30
+
31
+ def add_child(self, component:"UIComponent"):
32
+ component.parent = self
33
+ component.ui_manager = self.ui_manager
34
+ self.children.append(component)
35
+ component.update_absolute_rect()
36
+
37
+ def update_absolute_rect(self):
38
+ if self.parent is not None:
39
+ self.absolute_rect = (self.rect[0]+self.parent.absolute_rect[0],
40
+ self.rect[1]+self.parent.absolute_rect[1],
41
+ self.rect[2],
42
+ self.rect[3])
43
+ else:
44
+ self.absolute_rect = self.rect
45
+
46
+ for child in self.children:
47
+ child.update_absolute_rect()
48
+
49
+ def set_pos(self,pos_x,pos_y):
50
+ self.rect = (pos_x,pos_y,self.rect[2],self.rect[3])
51
+ self.update_absolute_rect()
52
+
53
+
54
+
55
+ def handle_event(self, event):
56
+ pass
57
+
58
+ def on_hover(self, is_hover):
59
+ self.hovered = is_hover
60
+
61
+ def on_click(self, event):
62
+ pass
63
+
64
+ def on_focus(self):
65
+ self.focused = True
66
+
67
+ def on_blur(self):
68
+ self.focused = False
69
+
70
+ def draw_child(self, surface: pygame.Surface):
71
+ for child in sorted(self.children, key=lambda c: c.z_index):
72
+ child.draw(surface)
73
+
74
+ def is_in_rect(self,pos):
75
+ if self.absolute_rect[0]<pos[0] < self.absolute_rect[0]+self.absolute_rect[2] and \
76
+ self.absolute_rect[1]<pos[1] < self.absolute_rect[1]+self.absolute_rect[3]:
77
+ return True
78
+ return False
79
+
80
+
81
+ def set_hover(self,is_hover):
82
+ if self.visible == False or self.enabled==False:
83
+ return
84
+
85
+ self.hovered = is_hover
86
+ if is_hover == False:
87
+ for child in self.children:
88
+ child.set_hover(False)
89
+
90
+
91
+
92
+
93
+
94
+
95
+
96
+ def draw(self, surface: pygame.Surface):
97
+ if not self.visible:
98
+ return
99
+
100
+ fill_color = self.color
101
+
102
+ if not self.enabled:
103
+ if fill_color is not None:
104
+ fill_color = tuple(c // 2 for c in fill_color)
105
+
106
+ elif self.active:
107
+ if fill_color is not None:
108
+ fill_color = tuple(max(c - 40, 0) for c in fill_color)
109
+
110
+ elif self.hovered:
111
+ if fill_color is not None:
112
+ fill_color = tuple(min(c + 30, 255) for c in fill_color)
113
+
114
+ if fill_color is not None:
115
+ pygame.draw.rect(surface, fill_color, self.absolute_rect, 0)
116
+
117
+ if self.show_border:
118
+ border_color = (255, 201, 0)
119
+
120
+
121
+ if self.focused:
122
+ border_color = (255, 201, 0)
123
+ pygame.draw.rect(surface, border_color, self.absolute_rect, 2)
124
+
125
+ self.draw_child(surface)
126
+
127
+
128
+
129
+
130
+
@@ -0,0 +1,125 @@
1
+ import pygame
2
+ from .Widget import*
3
+
4
+ class UIManager:
5
+ def __init__(self, root):
6
+ self.root = root
7
+ self.focused = None
8
+ self.active = None
9
+ self.modal = None # dropdown / modal
10
+ self._bind_manager(root)
11
+
12
+ def _bind_manager(self, component):
13
+ component.ui_manager = self
14
+ for child in component.children:
15
+ self._bind_manager(child)
16
+
17
+ def hit_test(self, component:UIComponent, pos):
18
+ if not component.visible or not component.enabled:
19
+ return None
20
+
21
+ # modal varsa SADECE onun içi
22
+ children = component.children
23
+ if self.modal:
24
+ children = self.modal.children
25
+
26
+ children = sorted(children, key=lambda c: c.z_index)
27
+ children.reverse()
28
+
29
+ for child in children:
30
+ if isinstance(child,Widget):
31
+ hit = self.hit_test(child, pos)
32
+ if hit:
33
+ return hit
34
+ else:
35
+ if child.is_in_rect(pos):
36
+ return child
37
+
38
+ if component.is_in_rect(pos):
39
+ return component
40
+
41
+ return None
42
+
43
+
44
+ def handle_event(self, event: pygame.event.Event):
45
+
46
+ # 🔹 Event'in başlayacağı root
47
+ root = self.modal if self.modal else self.root
48
+
49
+ # -------------------------
50
+ # MOUSE BUTTON DOWN
51
+ # -------------------------
52
+ if event.type == pygame.MOUSEBUTTONDOWN:
53
+
54
+ target = self.hit_test(root, event.pos)
55
+
56
+ # 👉 Modal açık ama DIŞINA tıklandıysa
57
+ if self.modal and not target:
58
+ # modal kapatılır
59
+ if hasattr(self.modal, "close"):
60
+ self.modal.close()
61
+ self.modal = None
62
+ return
63
+
64
+ if target:
65
+ self.active = target
66
+ target.active = True
67
+
68
+ # focus yönetimi
69
+ if self.focused and self.focused != target:
70
+ self.focused.on_blur()
71
+
72
+ target.on_focus()
73
+ self.focused = target
74
+
75
+ # -------------------------
76
+ # MOUSE BUTTON UP
77
+ # -------------------------
78
+ elif event.type == pygame.MOUSEBUTTONUP:
79
+
80
+ if self.active:
81
+ self.active.active = False
82
+
83
+ # click sayılır mı?
84
+ if self.active.is_in_rect(event.pos):
85
+ self.active.on_click(event)
86
+
87
+ self.active = None
88
+
89
+ # -------------------------
90
+ # MOUSE MOVE (HOVER)
91
+ # -------------------------
92
+ elif event.type == pygame.MOUSEMOTION:
93
+
94
+ target = self.hit_test(root, event.pos)
95
+
96
+ # hover değiştiyse güncelle
97
+ def clear_hover(widget):
98
+ widget.hovered = False
99
+ for c in widget.children:
100
+ clear_hover(c)
101
+
102
+ clear_hover(self.root)
103
+
104
+ if target:
105
+ target.hovered = True
106
+
107
+ # -------------------------
108
+ # KEYBOARD
109
+ # -------------------------
110
+ elif event.type == pygame.KEYDOWN:
111
+ if self.focused:
112
+ self.focused.handle_event(event)
113
+
114
+ def _handle_hover(self, pos):
115
+ target = self.hit_test(self.modal or self.root, pos)
116
+
117
+ def clear_hover(widget):
118
+ widget.hovered = False
119
+ for c in widget.children:
120
+ clear_hover(c)
121
+
122
+ clear_hover(self.root)
123
+
124
+ if target:
125
+ target.hovered = True
@@ -0,0 +1,13 @@
1
+ import pygame
2
+ from .UIComponent import *
3
+
4
+
5
+ class Widget(UIComponent):
6
+ def __init__(self, rect, style=None, z_index=0, color=None, border_color = None , hover_color=None):
7
+ super().__init__(rect, style, z_index, color, border_color, hover_color)
8
+
9
+ def draw(self, surface,parent_pos = None):
10
+
11
+ return super().draw(surface)
12
+
13
+
@@ -0,0 +1,7 @@
1
+ from .UIComponent import *
2
+ from .Widget import *
3
+ from .Text import *
4
+ from .Button import *
5
+ from .UIManager import*
6
+ from .Select import*
7
+ from .TextInput import*
@@ -0,0 +1,24 @@
1
+ Metadata-Version: 2.4
2
+ Name: pygame-widget-kit
3
+ Version: 0.0.1
4
+ Summary: A GUI framework built on Pygame. Designed as a retained-mode UI system with a component tree, extensible widgets, and focus management.
5
+ Author-email: Sinan Orgu <sinanorguuu@gmail.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/sinanorgu/pygame-widget-kit
8
+ Project-URL: Repository, https://github.com/sinanorgu/pygame-widget-kit
9
+ Project-URL: Issues, https://github.com/sinanorgu/pygame-widget-kit/issues
10
+ Keywords: pygame,ui,gui,toolkit,widgets,interface,game-development,inputbox,buttons
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Topic :: Software Development :: Libraries :: pygame
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Operating System :: OS Independent
17
+ Requires-Python: >=3.7
18
+ Description-Content-Type: text/markdown
19
+ License-File: LICENSE
20
+ Requires-Dist: pygame>=2.0.0
21
+ Dynamic: license-file
22
+
23
+ # pygame-widget-kit
24
+ A GUI framework built on Pygame. Designed as a retained-mode UI system with a component tree, event routing, focus and modal management, and extensible widgets such as Select/Dropdown and TextInput with mouse-based text selection and clipboard support.
@@ -0,0 +1,13 @@
1
+ pygame_widget_kit/Button.py,sha256=v7rwfVl1K-n2fDfqUPqMsm4UsH_mxxIyjkRg6kZIN5c,1397
2
+ pygame_widget_kit/Select.py,sha256=bJarYdtXWxM3BtS6F5S-j1LKAyDh6WssL7yENwC3PrA,3497
3
+ pygame_widget_kit/Text.py,sha256=SEfhoAc20ddZU0W370CUeT27L5f8kvFZWcBi3o9_0aY,3182
4
+ pygame_widget_kit/TextInput.py,sha256=i9M9w2IoRQfsHdJXMwf64pi0vwycl4p8k2UQf2N8jtU,9068
5
+ pygame_widget_kit/UIComponent.py,sha256=N1uQLCpy2JlWv2oGd72yX642ANBL-5-2zTRaOxdvwOI,3529
6
+ pygame_widget_kit/UIManager.py,sha256=m6MOleX-hv7XqRN2_MUA60uCR-irs9O2vkhawnIHoTs,3513
7
+ pygame_widget_kit/Widget.py,sha256=0OwXP4OFA1WnQDSGbG_nBUJfkl8-WKEcy7EBLACww1k,355
8
+ pygame_widget_kit/__init__.py,sha256=I-vtw5zbDuS3xuvwwL6_pgD_hpH4sbiAZAFY9xZRmDY,159
9
+ pygame_widget_kit-0.0.1.dist-info/licenses/LICENSE,sha256=1V6RqYoCrQE5UW4Gc5180fbMYRGJHb7r5uXKo10CQNo,1066
10
+ pygame_widget_kit-0.0.1.dist-info/METADATA,sha256=ytHJBAyJzbXvQ8hdSGxNd8pS9OyWWntJXP4OOvg3sRc,1278
11
+ pygame_widget_kit-0.0.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
12
+ pygame_widget_kit-0.0.1.dist-info/top_level.txt,sha256=xdeycCQO03FZ-xmrxKlCN0QUPvoZ1jHs91QE94tszZs,18
13
+ pygame_widget_kit-0.0.1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.9.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 sinanorgu
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ pygame_widget_kit