pygame-widget-kit 0.0.2__tar.gz → 0.0.4__tar.gz

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.
Files changed (22) hide show
  1. {pygame_widget_kit-0.0.2 → pygame_widget_kit-0.0.4}/PKG-INFO +11 -3
  2. {pygame_widget_kit-0.0.2 → pygame_widget_kit-0.0.4}/README.md +10 -2
  3. {pygame_widget_kit-0.0.2 → pygame_widget_kit-0.0.4}/pyproject.toml +1 -1
  4. {pygame_widget_kit-0.0.2 → pygame_widget_kit-0.0.4}/src/main.py +18 -0
  5. {pygame_widget_kit-0.0.2 → pygame_widget_kit-0.0.4}/src/pygame_widget_kit/Button.py +64 -0
  6. {pygame_widget_kit-0.0.2 → pygame_widget_kit-0.0.4}/src/pygame_widget_kit/Select.py +5 -2
  7. pygame_widget_kit-0.0.4/src/pygame_widget_kit/Slider.py +164 -0
  8. pygame_widget_kit-0.0.4/src/pygame_widget_kit/TextArea.py +120 -0
  9. {pygame_widget_kit-0.0.2 → pygame_widget_kit-0.0.4}/src/pygame_widget_kit/TextInput.py +242 -0
  10. {pygame_widget_kit-0.0.2 → pygame_widget_kit-0.0.4}/src/pygame_widget_kit/UIComponent.py +5 -2
  11. {pygame_widget_kit-0.0.2 → pygame_widget_kit-0.0.4}/src/pygame_widget_kit/UIManager.py +1 -1
  12. {pygame_widget_kit-0.0.2 → pygame_widget_kit-0.0.4}/src/pygame_widget_kit/Widget.py +1 -1
  13. {pygame_widget_kit-0.0.2 → pygame_widget_kit-0.0.4}/src/pygame_widget_kit/__init__.py +3 -0
  14. {pygame_widget_kit-0.0.2 → pygame_widget_kit-0.0.4}/src/pygame_widget_kit.egg-info/PKG-INFO +11 -3
  15. {pygame_widget_kit-0.0.2 → pygame_widget_kit-0.0.4}/src/pygame_widget_kit.egg-info/SOURCES.txt +2 -0
  16. {pygame_widget_kit-0.0.2 → pygame_widget_kit-0.0.4}/LICENSE +0 -0
  17. {pygame_widget_kit-0.0.2 → pygame_widget_kit-0.0.4}/setup.cfg +0 -0
  18. {pygame_widget_kit-0.0.2 → pygame_widget_kit-0.0.4}/src/pygame_widget_kit/Radio.py +0 -0
  19. {pygame_widget_kit-0.0.2 → pygame_widget_kit-0.0.4}/src/pygame_widget_kit/Text.py +0 -0
  20. {pygame_widget_kit-0.0.2 → pygame_widget_kit-0.0.4}/src/pygame_widget_kit.egg-info/dependency_links.txt +0 -0
  21. {pygame_widget_kit-0.0.2 → pygame_widget_kit-0.0.4}/src/pygame_widget_kit.egg-info/requires.txt +0 -0
  22. {pygame_widget_kit-0.0.2 → pygame_widget_kit-0.0.4}/src/pygame_widget_kit.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pygame-widget-kit
3
- Version: 0.0.2
3
+ Version: 0.0.4
4
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
5
  Author-email: Sinan Orgu <sinanorguuu@gmail.com>
6
6
  License: MIT
@@ -33,9 +33,9 @@ PyPI: https://pypi.org/project/pygame-widget-kit/
33
33
  - Retained-mode component tree with nested children
34
34
  - Event routing with hover, focus, and active state handling
35
35
  - Modal/dropdown support via `UIManager`
36
- - Built-in widgets: `Button`, `Text`, `Select`, `Radio`, `TextInput`
36
+ - Built-in widgets: `Button`, `Text`, `Select`, `Radio`, `TextInput`, `Slider`,`TextArea`,`TextInput2D`
37
37
  - Text input filtering modes (text, number, hex, binary, octal)
38
- - Clipboard copy/paste in `TextInput` (requires `pygame.scrap`)
38
+
39
39
 
40
40
  ## Installation
41
41
 
@@ -135,6 +135,14 @@ def main():
135
135
  root.add_child(radio_value)
136
136
 
137
137
  radio_last_value = radio.get_value()
138
+ slider = Slider((20,580),size=(500,20),min_value=50,max_value=2000)
139
+ slider_value = Text("Sider Value", pos=(20, 600), text_color=(0, 0, 0))
140
+ slider.change_bind(update_slider_label,slider,slider_value)
141
+
142
+ root.add_child(slider)
143
+ root.add_child(slider_value)
144
+
145
+
138
146
 
139
147
  running = True
140
148
  while running:
@@ -11,9 +11,9 @@ PyPI: https://pypi.org/project/pygame-widget-kit/
11
11
  - Retained-mode component tree with nested children
12
12
  - Event routing with hover, focus, and active state handling
13
13
  - Modal/dropdown support via `UIManager`
14
- - Built-in widgets: `Button`, `Text`, `Select`, `Radio`, `TextInput`
14
+ - Built-in widgets: `Button`, `Text`, `Select`, `Radio`, `TextInput`, `Slider`,`TextArea`,`TextInput2D`
15
15
  - Text input filtering modes (text, number, hex, binary, octal)
16
- - Clipboard copy/paste in `TextInput` (requires `pygame.scrap`)
16
+
17
17
 
18
18
  ## Installation
19
19
 
@@ -113,6 +113,14 @@ def main():
113
113
  root.add_child(radio_value)
114
114
 
115
115
  radio_last_value = radio.get_value()
116
+ slider = Slider((20,580),size=(500,20),min_value=50,max_value=2000)
117
+ slider_value = Text("Sider Value", pos=(20, 600), text_color=(0, 0, 0))
118
+ slider.change_bind(update_slider_label,slider,slider_value)
119
+
120
+ root.add_child(slider)
121
+ root.add_child(slider_value)
122
+
123
+
116
124
 
117
125
  running = True
118
126
  while running:
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "pygame-widget-kit"
7
- version = "0.0.2"
7
+ version = "0.0.4"
8
8
  authors = [
9
9
  { name="Sinan Orgu", email="sinanorguuu@gmail.com" },
10
10
  ]
@@ -13,6 +13,10 @@ def update_label_from_input(input_box: TextInput, label: Text):
13
13
  def update_select_label(select: Select, label: Text):
14
14
  label.set_text(f"Selected: {select.selected_value}")
15
15
 
16
+ def update_slider_label(slider:Slider,label:Text):
17
+ label.set_text(f"Slider Value: {round(slider.value,2)}")
18
+
19
+
16
20
 
17
21
  def main():
18
22
  pygame.init()
@@ -85,6 +89,20 @@ def main():
85
89
 
86
90
  radio_last_value = radio.get_value()
87
91
 
92
+ slider = Slider((20,580),size=(500,20),min_value=50,max_value=2000)
93
+ slider_value = Text("Sider Value", pos=(20, 600), text_color=(0, 0, 0))
94
+ slider.change_bind(update_slider_label,slider,slider_value)
95
+
96
+ root.add_child(slider)
97
+ root.add_child(slider_value)
98
+
99
+ text_area_str = "hello bu bir deneme yazisidir bakalaim bu bolme islemi duzgun bir sekilde yapilabilcek mi acaba??"
100
+ text_area = TextArea((20,650,300,200),text_area_str,text_color=(0,0,0),max_chars_per_line=20)
101
+ root.add_child(text_area)
102
+
103
+
104
+
105
+
88
106
  running = True
89
107
  while running:
90
108
  clock.tick(60)
@@ -2,6 +2,34 @@ import pygame
2
2
  from .Text import *
3
3
  from .UIComponent import *
4
4
  from functools import partial
5
+ import tkinter as tk
6
+ from tkinter import filedialog
7
+
8
+
9
+ import multiprocessing
10
+
11
+
12
+ def file_choser_process(queue):
13
+ try:
14
+ root = tk.Tk()
15
+ root.withdraw()
16
+
17
+ root.attributes('-topmost', True)
18
+
19
+ root.lift()
20
+ root.focus_force()
21
+
22
+ dosya_yolu = filedialog.askopenfilename(
23
+ title="Chose File",
24
+ filetypes=[("Tüm Dosyalar", "*.*")]
25
+ )
26
+
27
+ queue.put(dosya_yolu)
28
+
29
+ root.destroy()
30
+ except Exception as e:
31
+ queue.put(None)
32
+
5
33
 
6
34
 
7
35
  class Button(UIComponent):
@@ -63,4 +91,40 @@ class Button(UIComponent):
63
91
  self.click_function()
64
92
  else:
65
93
  print("Button clicked")
94
+
95
+
96
+
97
+
98
+ class ChooseFileButton(Button):
99
+ def __init__(self, text_str="Button", pos=(0, 0), size=(200, 40), style=None, z_index=0, color=(175, 175, 175), border_color=(100, 100, 100), hover_color=(150, 150, 150), text_color=(0, 0, 0), padding=(20, 10)):
100
+ super().__init__(text_str, pos, size, style, z_index, color, border_color, hover_color, text_color, padding)
101
+
102
+ self.chosen_file_path = None
103
+
104
+ def on_click(self, event):
105
+ print("Dosya seçici ayrı işlemde başlatılıyor...")
106
+
107
+ q = multiprocessing.Queue()
108
+
109
+ p = multiprocessing.Process(target=file_choser_process, args=(q,))
110
+
111
+ p.start()
112
+ p.join()
113
+ if not q.empty():
114
+ sonuc = q.get()
115
+ if sonuc:
116
+ secilen_dosya = sonuc
117
+ print(f"Gelen dosya: {secilen_dosya}")
118
+ self.chosen_file_path = secilen_dosya
119
+ self.text.set_text(secilen_dosya)
120
+ if self.click_function is not None:
121
+ self.click_function()
122
+ else:
123
+ print("islem iptal")
124
+ else:
125
+ print("İşlem iptal edildi veya hata oluştu.")
126
+
127
+
128
+
129
+
66
130
 
@@ -5,6 +5,7 @@ from .Button import *
5
5
  from functools import partial
6
6
 
7
7
 
8
+
8
9
  class SelectOption(Button):
9
10
  def __init__(self,value:str, rect, parent_select:"Select", color=(200,200,200),border_color = (127,127,127)):
10
11
  super().__init__(text_str=value,pos=(rect[0],rect[1]),size=(rect[2],rect[3]), color=color,padding=(5,5),text_color=(0,0,0),border_color=border_color)
@@ -116,10 +117,12 @@ class Select(UIComponent):
116
117
  self.on_option_change()
117
118
 
118
119
  def on_click(self, event):
119
- self.toggle()
120
+ if self.enabled:
121
+ self.toggle()
120
122
 
121
123
  def draw(self, surface: pygame.Surface):
122
-
124
+ if self.visible == False:
125
+ return
123
126
  super().draw(surface)
124
127
 
125
128
  cx = self.absolute_rect[0] + self.absolute_rect[2] - 15
@@ -0,0 +1,164 @@
1
+ import pygame
2
+ from .UIComponent import *
3
+ from functools import partial
4
+
5
+
6
+ class Slider(UIComponent):
7
+ def __init__(
8
+ self,
9
+ pos=(0, 0),
10
+ size=(200, 20),
11
+ min_value=0,
12
+ max_value=100,
13
+ value=None,
14
+ style=None,
15
+ z_index=0,
16
+ color=(200, 200, 200),
17
+ border_color=(120, 120, 120),
18
+ hover_color=(220, 220, 220),
19
+ handle_color=(80, 80, 80),
20
+ handle_hover_color=None,
21
+ handle_border_color=None,
22
+ ):
23
+ self.min_value = min_value
24
+ self.max_value = max_value
25
+ self.value = min_value if value is None else value
26
+
27
+ self.size = size
28
+
29
+ self.handle_color = handle_color
30
+ self.handle_hover_color = (
31
+ handle_hover_color
32
+ if handle_hover_color is not None
33
+ else tuple(min(c + 30, 255) for c in handle_color)
34
+ )
35
+ self.handle_active_color = tuple(max(c - 40, 0) for c in handle_color)
36
+ self.handle_border_color = handle_border_color
37
+
38
+ self.dragging = False
39
+ self.drag_offset = 0
40
+ self.change_function = None
41
+
42
+ rect = (pos[0], pos[1], self.size[0], self.size[1])
43
+ super().__init__(rect, style, z_index, color, border_color, hover_color)
44
+
45
+ self.handle_width = min(self.rect[2], self.rect[3])
46
+ self.handle_height = self.rect[3]
47
+
48
+ self.set_value(self.value)
49
+
50
+ def change_bind(self, func, *args):
51
+ self.change_function = partial(func, *args)
52
+
53
+ def on_change(self):
54
+ if self.change_function is not None:
55
+ self.change_function()
56
+
57
+ def set_value(self, value):
58
+ if self.max_value == self.min_value:
59
+ if self.value != self.min_value:
60
+ self.value = self.min_value
61
+ self.on_change()
62
+ return
63
+
64
+ old_value = self.value
65
+ if value < self.min_value:
66
+ value = self.min_value
67
+ elif value > self.max_value:
68
+ value = self.max_value
69
+
70
+ self.value = value
71
+ if self.value != old_value:
72
+ self.on_change()
73
+
74
+ def get_value(self):
75
+ return self.value
76
+
77
+ def _get_track_range(self):
78
+ x = self.absolute_rect[0]
79
+ w = self.rect[2]
80
+ handle_w = self.handle_width
81
+ min_center = x + handle_w / 2
82
+ max_center = x + w - handle_w / 2
83
+ return min_center, max_center
84
+
85
+ def _value_to_center(self):
86
+ min_center, max_center = self._get_track_range()
87
+ if max_center <= min_center or self.max_value == self.min_value:
88
+ return min_center
89
+
90
+ ratio = (self.value - self.min_value) / (self.max_value - self.min_value)
91
+ ratio = max(0, min(1, ratio))
92
+ return min_center + ratio * (max_center - min_center)
93
+
94
+ def _get_handle_rect(self):
95
+ center_x = self._value_to_center()
96
+ handle_x = int(center_x - self.handle_width / 2)
97
+ handle_y = int(self.absolute_rect[1] + (self.rect[3] - self.handle_height) / 2)
98
+ return pygame.Rect(handle_x, handle_y, self.handle_width, self.handle_height)
99
+
100
+ def _set_value_from_mouse(self, mouse_x, use_offset):
101
+ min_center, max_center = self._get_track_range()
102
+ if max_center <= min_center or self.max_value == self.min_value:
103
+ self.set_value(self.min_value)
104
+ return
105
+
106
+ center_x = mouse_x - (self.drag_offset if use_offset else 0)
107
+ if center_x < min_center:
108
+ center_x = min_center
109
+ elif center_x > max_center:
110
+ center_x = max_center
111
+
112
+ ratio = (center_x - min_center) / (max_center - min_center)
113
+ self.set_value(self.min_value + ratio * (self.max_value - self.min_value))
114
+
115
+ def _begin_drag(self):
116
+ mouse_x, mouse_y = pygame.mouse.get_pos()
117
+ handle_rect = self._get_handle_rect()
118
+
119
+ if handle_rect.collidepoint(mouse_x, mouse_y):
120
+ self.drag_offset = mouse_x - handle_rect.centerx
121
+ else:
122
+ self.drag_offset = 0
123
+ self._set_value_from_mouse(mouse_x, use_offset=False)
124
+
125
+ self.dragging = True
126
+
127
+ def on_click(self, event):
128
+ if not self.visible or not self.enabled:
129
+ return
130
+
131
+ if not self.dragging:
132
+ self._set_value_from_mouse(event.pos[0], use_offset=False)
133
+
134
+ self.dragging = False
135
+ self.drag_offset = 0
136
+
137
+
138
+ def draw(self, surface: pygame.Surface):
139
+ if not self.visible:
140
+ return
141
+
142
+ if self.active and self.enabled:
143
+ if not self.dragging:
144
+ self._begin_drag()
145
+ mouse_x, _ = pygame.mouse.get_pos()
146
+ self._set_value_from_mouse(mouse_x, use_offset=True)
147
+ else:
148
+ self.dragging = False
149
+ self.drag_offset = 0
150
+
151
+ super().draw(surface)
152
+
153
+ handle_color = self.handle_color
154
+ if not self.enabled:
155
+ handle_color = tuple(c // 2 for c in handle_color)
156
+ elif self.active:
157
+ handle_color = self.handle_active_color
158
+ elif self.hovered:
159
+ handle_color = self.handle_hover_color
160
+
161
+ handle_rect = self._get_handle_rect()
162
+ pygame.draw.rect(surface, handle_color, handle_rect, 0)
163
+ if self.handle_border_color:
164
+ pygame.draw.rect(surface, self.handle_border_color, handle_rect, 2)
@@ -0,0 +1,120 @@
1
+ import pygame
2
+ from .UIComponent import *
3
+
4
+
5
+ class TextArea(UIComponent):
6
+ def __init__(
7
+ self,
8
+ rect,
9
+ text_str="",
10
+ font_size=25,
11
+ font_type="Veranda",
12
+ text_color: tuple[int, int, int] = (127, 127, 127),
13
+ bg_color=None,
14
+ hover_color=None,
15
+ padding=6,
16
+ line_spacing=0,
17
+ max_chars_per_line=None,
18
+ style=None,
19
+ z_index=0,
20
+ border_color=None,
21
+ ):
22
+ self.font_size = font_size
23
+ self.font_type = font_type
24
+ self.font = pygame.font.SysFont(self.font_type, self.font_size)
25
+
26
+ self.text_str = text_str
27
+ self.text_color = text_color
28
+ self.padding = padding
29
+ self.line_spacing = line_spacing
30
+ self.max_chars_per_line = max_chars_per_line
31
+
32
+ super().__init__(rect, style, z_index, bg_color, border_color, hover_color)
33
+
34
+ self._rebuild_lines()
35
+
36
+ def _wrap_line(self, line):
37
+ if self.max_chars_per_line is None or self.max_chars_per_line <= 0:
38
+ return [line]
39
+
40
+ words = line.split(" ")
41
+ if not words:
42
+ return [line]
43
+
44
+ wrapped = []
45
+ current = ""
46
+
47
+ for word in words:
48
+ if current == "":
49
+ if len(word) > self.max_chars_per_line:
50
+ wrapped.append(word)
51
+ else:
52
+ current = word
53
+ continue
54
+
55
+ candidate_len = len(current) + 1 + len(word)
56
+ if candidate_len <= self.max_chars_per_line:
57
+ current = f"{current} {word}"
58
+ else:
59
+ wrapped.append(current)
60
+ if len(word) > self.max_chars_per_line:
61
+ wrapped.append(word)
62
+ current = ""
63
+ else:
64
+ current = word
65
+
66
+ if current != "":
67
+ wrapped.append(current)
68
+
69
+ return wrapped
70
+
71
+ def _rebuild_lines(self):
72
+ raw_lines = self.text_str.split("\n")
73
+ self.lines = []
74
+ for raw_line in raw_lines:
75
+ if raw_line == "":
76
+ self.lines.append("")
77
+ continue
78
+ self.lines.extend(self._wrap_line(raw_line))
79
+ self.line_height = self.font.get_linesize()
80
+ self.line_renders = [
81
+ self.font.render(line, True, self.text_color, None) for line in self.lines
82
+ ]
83
+
84
+ def set_text(self, new_text_str):
85
+ self.text_str = new_text_str
86
+ self._rebuild_lines()
87
+
88
+ def update_font_size(self, new_size):
89
+ self.font_size = new_size
90
+ self.font = pygame.font.SysFont(self.font_type, self.font_size)
91
+ self._rebuild_lines()
92
+
93
+ def update_font_type(self, new_type):
94
+ self.font_type = new_type
95
+ self.font = pygame.font.SysFont(self.font_type, self.font_size)
96
+ self._rebuild_lines()
97
+
98
+ def draw(self, surface):
99
+ if not self.visible:
100
+ return
101
+
102
+ super().draw(surface)
103
+
104
+ if not self.lines:
105
+ return
106
+
107
+ color = self.text_color
108
+ if not self.enabled:
109
+ color = tuple(c // 2 for c in color)
110
+
111
+ x = self.absolute_rect[0] + self.padding
112
+ y = self.absolute_rect[1] + self.padding
113
+ step = self.line_height + self.line_spacing
114
+
115
+ for i, line in enumerate(self.lines):
116
+ if color == self.text_color:
117
+ render = self.line_renders[i]
118
+ else:
119
+ render = self.font.render(line, True, color, None)
120
+ surface.blit(render, (x, y + i * step))
@@ -343,3 +343,245 @@ class TextInput(UIComponent):
343
343
  self.caret_color,
344
344
  (cx, cy, 2, self.text.render.get_height())
345
345
  )
346
+
347
+
348
+
349
+ class TextInput2D(UIComponent):
350
+ def __init__(
351
+ self,
352
+ rect,
353
+ initial_text="",
354
+ text_color=(0, 0, 0),
355
+ bg_color=(220, 220, 220),
356
+ hover_color=(240, 240, 240),
357
+ selection_color=(100, 150, 255),
358
+ caret_color=(0, 0, 0),
359
+ padding=6,
360
+ font_size=25,
361
+ font_type='Veranda',
362
+ z_index=0
363
+ ):
364
+ super().__init__(
365
+ rect=rect,
366
+ z_index=z_index,
367
+ color=bg_color,
368
+ hover_color=hover_color
369
+ )
370
+
371
+ self.text_color = text_color
372
+ self.selection_color = selection_color
373
+ self.caret_color = caret_color
374
+ self.padding = padding
375
+ self.font_size = font_size
376
+ self.font_type = font_type
377
+ self.font = pygame.font.SysFont(self.font_type, self.font_size)
378
+
379
+ self.lines = initial_text.split('\n') if initial_text else ['']
380
+ self.cursor_line = 0
381
+ self.cursor_col = 0
382
+
383
+ self.selection_start = None
384
+ self.selection_end = None
385
+ self.dragging = False
386
+
387
+ # caret blink
388
+ self.caret_visible = True
389
+ self._caret_timer = 0
390
+ self._caret_interval = 0.5
391
+ self.last_blinked_at = time.time()
392
+
393
+ def get_text(self):
394
+ return '\n'.join(self.lines)
395
+
396
+ def set_text(self, text):
397
+ self.lines = text.split('\n') if text else ['']
398
+ self.cursor_line = min(self.cursor_line, len(self.lines) - 1)
399
+ self.cursor_col = min(self.cursor_col, len(self.lines[self.cursor_line]))
400
+
401
+ def _get_line_height(self):
402
+ return self.font.get_height()
403
+
404
+ def _get_text_width(self, text):
405
+ return self.font.size(text)[0]
406
+
407
+ def _mouse_to_pos(self, mouse_x, mouse_y):
408
+ local_x = mouse_x - self.absolute_rect[0] - self.padding
409
+ local_y = mouse_y - self.absolute_rect[1] - self.padding
410
+
411
+ line_height = self._get_line_height()
412
+ line = int(local_y // line_height)
413
+ line = max(0, min(line, len(self.lines) - 1))
414
+
415
+ line_text = self.lines[line]
416
+ col = 0
417
+ for i in range(len(line_text) + 1):
418
+ if self._get_text_width(line_text[:i]) > local_x:
419
+ col = i - 1
420
+ break
421
+ else:
422
+ col = len(line_text)
423
+
424
+ return line, col
425
+
426
+ def on_click(self, event):
427
+ self.dragging = True
428
+ self.cursor_line, self.cursor_col = self._mouse_to_pos(event.pos[0], event.pos[1])
429
+ self.selection_start = (self.cursor_line, self.cursor_col)
430
+ self.selection_end = None
431
+
432
+ def handle_event(self, event: pygame.Event):
433
+ if not self.focused or not self.enabled:
434
+ return
435
+
436
+ # MOUSE DRAG SELECTION
437
+ if event.type == pygame.MOUSEMOTION and self.dragging:
438
+ line, col = self._mouse_to_pos(event.pos[0], event.pos[1])
439
+ self.selection_end = (line, col)
440
+ self.cursor_line, self.cursor_col = line, col
441
+
442
+ if event.type == pygame.MOUSEBUTTONUP:
443
+ self.dragging = False
444
+ if self.selection_start == self.selection_end:
445
+ self.selection_start = self.selection_end = None
446
+
447
+ if event.type == pygame.KEYDOWN:
448
+ # BACKSPACE
449
+ if event.key == pygame.K_BACKSPACE:
450
+ if self.has_selection():
451
+ self.delete_selection()
452
+ elif self.cursor_col > 0:
453
+ self.lines[self.cursor_line] = (
454
+ self.lines[self.cursor_line][:self.cursor_col - 1]
455
+ + self.lines[self.cursor_line][self.cursor_col:]
456
+ )
457
+ self.cursor_col -= 1
458
+ elif self.cursor_line > 0:
459
+ # Join with previous line
460
+ prev_line = self.lines[self.cursor_line - 1]
461
+ self.cursor_col = len(prev_line)
462
+ self.lines[self.cursor_line - 1] += self.lines[self.cursor_line]
463
+ del self.lines[self.cursor_line]
464
+ self.cursor_line -= 1
465
+
466
+ # ENTER
467
+ elif event.key == pygame.K_RETURN:
468
+ if self.has_selection():
469
+ self.delete_selection()
470
+ line = self.lines[self.cursor_line]
471
+ self.lines[self.cursor_line] = line[:self.cursor_col]
472
+ self.lines.insert(self.cursor_line + 1, line[self.cursor_col:])
473
+ self.cursor_line += 1
474
+ self.cursor_col = 0
475
+
476
+ # ARROW KEYS
477
+ elif event.key == pygame.K_LEFT:
478
+ if self.cursor_col > 0:
479
+ self.cursor_col -= 1
480
+ elif self.cursor_line > 0:
481
+ self.cursor_line -= 1
482
+ self.cursor_col = len(self.lines[self.cursor_line])
483
+ elif event.key == pygame.K_RIGHT:
484
+ if self.cursor_col < len(self.lines[self.cursor_line]):
485
+ self.cursor_col += 1
486
+ elif self.cursor_line < len(self.lines) - 1:
487
+ self.cursor_line += 1
488
+ self.cursor_col = 0
489
+ elif event.key == pygame.K_UP:
490
+ if self.cursor_line > 0:
491
+ self.cursor_line -= 1
492
+ self.cursor_col = min(self.cursor_col, len(self.lines[self.cursor_line]))
493
+ elif event.key == pygame.K_DOWN:
494
+ if self.cursor_line < len(self.lines) - 1:
495
+ self.cursor_line += 1
496
+ self.cursor_col = min(self.cursor_col, len(self.lines[self.cursor_line]))
497
+
498
+ # TYPING
499
+ elif event.unicode and event.unicode.isprintable():
500
+ if self.has_selection():
501
+ self.delete_selection()
502
+ line = self.lines[self.cursor_line]
503
+ self.lines[self.cursor_line] = line[:self.cursor_col] + event.unicode + line[self.cursor_col:]
504
+ self.cursor_col += 1
505
+
506
+ def has_selection(self):
507
+ return (
508
+ self.selection_start is not None
509
+ and self.selection_end is not None
510
+ and self.selection_start != self.selection_end
511
+ )
512
+
513
+ def get_selection_range(self):
514
+ # For simplicity, assume single line selection or handle multi-line later
515
+ # This is complex, for now assume same line
516
+ if not self.has_selection():
517
+ return None
518
+ start_line, start_col = self.selection_start
519
+ end_line, end_col = self.selection_end
520
+ if start_line != end_line:
521
+ # Multi-line selection, for now just clear
522
+ return None
523
+ return sorted((start_col, end_col))
524
+
525
+ def delete_selection(self):
526
+ if not self.has_selection():
527
+ return
528
+ start_line, start_col = self.selection_start
529
+ end_line, end_col = self.selection_end
530
+ if start_line == end_line:
531
+ line = self.lines[start_line]
532
+ a, b = sorted((start_col, end_col))
533
+ self.lines[start_line] = line[:a] + line[b:]
534
+ self.cursor_line = start_line
535
+ self.cursor_col = a
536
+ # Multi-line delete not implemented yet
537
+ self.selection_start = self.selection_end = None
538
+
539
+ def update(self):
540
+ if not self.focused:
541
+ self.caret_visible = False
542
+ return
543
+
544
+ if time.time() - self.last_blinked_at >= self._caret_interval:
545
+ self.last_blinked_at = time.time()
546
+ self.caret_visible = not self.caret_visible
547
+
548
+ def draw(self, surface):
549
+ super().draw(surface)
550
+ self.update()
551
+
552
+ line_height = self._get_line_height()
553
+ y = self.absolute_rect[1] + self.padding
554
+
555
+ for i, line in enumerate(self.lines):
556
+ render = self.font.render(line, True, self.text_color)
557
+ surface.blit(render, (self.absolute_rect[0] + self.padding, y))
558
+ y += line_height
559
+
560
+ # CARET
561
+ if self.focused and self.caret_visible:
562
+ caret_x = self.absolute_rect[0] + self.padding + self._get_text_width(self.lines[self.cursor_line][:self.cursor_col])
563
+ caret_y = self.absolute_rect[1] + self.padding + self.cursor_line * line_height
564
+
565
+ pygame.draw.rect(
566
+ surface,
567
+ self.caret_color,
568
+ (caret_x, caret_y, 2, line_height)
569
+ )
570
+
571
+ # SELECTION - simplified, only same line
572
+ if self.has_selection():
573
+ sel_range = self.get_selection_range()
574
+ if sel_range:
575
+ a, b = sel_range
576
+ line = self.lines[self.cursor_line]
577
+ x1 = self.absolute_rect[0] + self.padding + self._get_text_width(line[:a])
578
+ x2 = self.absolute_rect[0] + self.padding + self._get_text_width(line[:b])
579
+ y = self.absolute_rect[1] + self.padding + self.cursor_line * line_height
580
+
581
+ pygame.draw.rect(
582
+ surface,
583
+ self.selection_color,
584
+ (x1, y, x2 - x1, line_height)
585
+ )
586
+
587
+
@@ -115,12 +115,15 @@ class UIComponent:
115
115
  pygame.draw.rect(surface, fill_color, self.absolute_rect, 0)
116
116
 
117
117
  if self.show_border:
118
+
118
119
  border_color = self.color
119
120
 
120
121
 
121
122
  if self.focused:
122
- border_color =self.border_color
123
- pygame.draw.rect(surface, border_color, self.absolute_rect, 2)
123
+ border_color = self.border_color
124
+
125
+ if border_color:
126
+ pygame.draw.rect(surface, border_color, self.absolute_rect, 2)
124
127
 
125
128
  self.draw_child(surface)
126
129
 
@@ -32,7 +32,7 @@ class UIManager:
32
32
  if hit:
33
33
  return hit
34
34
  else:
35
- if child.is_in_rect(pos):
35
+ if child.is_in_rect(pos) and child.visible:
36
36
  return child
37
37
 
38
38
  if component.is_in_rect(pos):
@@ -8,7 +8,7 @@ class Widget(UIComponent):
8
8
  hover_color = color
9
9
  super().__init__(rect, style, z_index, color, border_color, hover_color)
10
10
 
11
- def draw(self, surface,parent_pos = None):
11
+ def draw(self, surface):
12
12
 
13
13
  return super().draw(surface)
14
14
 
@@ -6,3 +6,6 @@ from .UIManager import*
6
6
  from .Select import*
7
7
  from .TextInput import*
8
8
  from .Radio import*
9
+ from .Slider import*
10
+ from .TextArea import*
11
+ from .TextArea import*
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pygame-widget-kit
3
- Version: 0.0.2
3
+ Version: 0.0.4
4
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
5
  Author-email: Sinan Orgu <sinanorguuu@gmail.com>
6
6
  License: MIT
@@ -33,9 +33,9 @@ PyPI: https://pypi.org/project/pygame-widget-kit/
33
33
  - Retained-mode component tree with nested children
34
34
  - Event routing with hover, focus, and active state handling
35
35
  - Modal/dropdown support via `UIManager`
36
- - Built-in widgets: `Button`, `Text`, `Select`, `Radio`, `TextInput`
36
+ - Built-in widgets: `Button`, `Text`, `Select`, `Radio`, `TextInput`, `Slider`,`TextArea`,`TextInput2D`
37
37
  - Text input filtering modes (text, number, hex, binary, octal)
38
- - Clipboard copy/paste in `TextInput` (requires `pygame.scrap`)
38
+
39
39
 
40
40
  ## Installation
41
41
 
@@ -135,6 +135,14 @@ def main():
135
135
  root.add_child(radio_value)
136
136
 
137
137
  radio_last_value = radio.get_value()
138
+ slider = Slider((20,580),size=(500,20),min_value=50,max_value=2000)
139
+ slider_value = Text("Sider Value", pos=(20, 600), text_color=(0, 0, 0))
140
+ slider.change_bind(update_slider_label,slider,slider_value)
141
+
142
+ root.add_child(slider)
143
+ root.add_child(slider_value)
144
+
145
+
138
146
 
139
147
  running = True
140
148
  while running:
@@ -5,7 +5,9 @@ src/main.py
5
5
  src/pygame_widget_kit/Button.py
6
6
  src/pygame_widget_kit/Radio.py
7
7
  src/pygame_widget_kit/Select.py
8
+ src/pygame_widget_kit/Slider.py
8
9
  src/pygame_widget_kit/Text.py
10
+ src/pygame_widget_kit/TextArea.py
9
11
  src/pygame_widget_kit/TextInput.py
10
12
  src/pygame_widget_kit/UIComponent.py
11
13
  src/pygame_widget_kit/UIManager.py