crystalwindow 3.8.5__py3-none-any.whl → 3.8.6__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.
- crystalwindow/gui_ext.py +34 -16
- {crystalwindow-3.8.5.dist-info → crystalwindow-3.8.6.dist-info}/METADATA +1 -1
- {crystalwindow-3.8.5.dist-info → crystalwindow-3.8.6.dist-info}/RECORD +6 -6
- {crystalwindow-3.8.5.dist-info → crystalwindow-3.8.6.dist-info}/WHEEL +0 -0
- {crystalwindow-3.8.5.dist-info → crystalwindow-3.8.6.dist-info}/licenses/LICENSE +0 -0
- {crystalwindow-3.8.5.dist-info → crystalwindow-3.8.6.dist-info}/top_level.txt +0 -0
crystalwindow/gui_ext.py
CHANGED
|
@@ -3,35 +3,48 @@ from .window import Window
|
|
|
3
3
|
from .assets import load_image
|
|
4
4
|
from .sprites import Sprite
|
|
5
5
|
from .gui import Button
|
|
6
|
+
from .color_handler import Colors, Color
|
|
7
|
+
|
|
8
|
+
def parse_color(c):
|
|
9
|
+
if isinstance(c, tuple):
|
|
10
|
+
return c
|
|
11
|
+
if isinstance(c, Color):
|
|
12
|
+
return c.to_tuple()
|
|
13
|
+
if isinstance(c, str):
|
|
14
|
+
if hasattr(Colors, c):
|
|
15
|
+
return getattr(Colors, c).to_tuple()
|
|
16
|
+
return (255,255,255)
|
|
17
|
+
return (255,255,255)
|
|
6
18
|
|
|
7
19
|
class Toggle:
|
|
8
|
-
def __init__(self, rect, value=False, color=
|
|
9
|
-
# rect = (x, y, w, h)
|
|
20
|
+
def __init__(self, rect, value=False, color="gray", hover_color="white", cooldown=0.1):
|
|
10
21
|
self.rect = rect
|
|
11
22
|
self.value = value
|
|
12
|
-
|
|
13
|
-
self.
|
|
23
|
+
|
|
24
|
+
self.color = parse_color(color)
|
|
25
|
+
self.hover_color = parse_color(hover_color)
|
|
26
|
+
|
|
14
27
|
self.hovered = False
|
|
15
28
|
self.cooldown = cooldown
|
|
16
|
-
self._last_toggle = 0
|
|
29
|
+
self._last_toggle = 0
|
|
17
30
|
|
|
18
31
|
def update(self, win: Window):
|
|
19
32
|
mx, my = win.mouse_pos
|
|
20
33
|
x, y, w, h = self.rect
|
|
21
34
|
self.hovered = x <= mx <= x + w and y <= my <= y + h
|
|
22
35
|
|
|
23
|
-
# check cooldown timer
|
|
24
36
|
now = time.time()
|
|
25
37
|
can_toggle = now - self._last_toggle >= self.cooldown
|
|
26
38
|
|
|
27
39
|
if self.hovered and win.mouse_pressed(1) and can_toggle:
|
|
28
40
|
self.value = not self.value
|
|
29
|
-
self._last_toggle = now
|
|
41
|
+
self._last_toggle = now
|
|
30
42
|
|
|
31
43
|
def draw(self, win: Window):
|
|
32
44
|
draw_color = self.hover_color if self.hovered else self.color
|
|
33
45
|
win.draw_rect(draw_color, self.rect)
|
|
34
|
-
|
|
46
|
+
|
|
47
|
+
# ON glow
|
|
35
48
|
if self.value:
|
|
36
49
|
inner = (
|
|
37
50
|
self.rect[0] + 4,
|
|
@@ -43,13 +56,15 @@ class Toggle:
|
|
|
43
56
|
|
|
44
57
|
|
|
45
58
|
class Slider:
|
|
46
|
-
def __init__(self, rect, min_val=0, max_val=100, value=50, color=
|
|
47
|
-
# rect = (x, y, w, h)
|
|
59
|
+
def __init__(self, rect, min_val=0, max_val=100, value=50, color="lightgray", handle_color="red", handle_radius=10):
|
|
48
60
|
self.rect = rect
|
|
49
61
|
self.min_val = min_val
|
|
50
62
|
self.max_val = max_val
|
|
51
63
|
self.value = value
|
|
52
|
-
|
|
64
|
+
|
|
65
|
+
self.color = parse_color(color)
|
|
66
|
+
self.handle_color = parse_color(handle_color)
|
|
67
|
+
|
|
53
68
|
self.handle_radius = handle_radius
|
|
54
69
|
self.dragging = False
|
|
55
70
|
|
|
@@ -60,21 +75,24 @@ class Slider:
|
|
|
60
75
|
handle_x = x + ((self.value - self.min_val) / (self.max_val - self.min_val)) * w
|
|
61
76
|
handle_y = y + h // 2
|
|
62
77
|
|
|
63
|
-
# start drag if mouse clicks inside slider bar area
|
|
64
78
|
if win.mouse_pressed(1):
|
|
65
79
|
if not self.dragging and (x <= mx <= x+w and y <= my <= y+h):
|
|
66
80
|
self.dragging = True
|
|
67
81
|
else:
|
|
68
|
-
self.dragging = False
|
|
82
|
+
self.dragging = False
|
|
69
83
|
|
|
70
|
-
# update value while dragging
|
|
71
84
|
if self.dragging:
|
|
72
|
-
rel_x = max(0, min(mx - x, w))
|
|
85
|
+
rel_x = max(0, min(mx - x, w))
|
|
73
86
|
self.value = self.min_val + (rel_x / w) * (self.max_val - self.min_val)
|
|
74
87
|
|
|
75
88
|
def draw(self, win: Window):
|
|
76
89
|
x, y, w, h = self.rect
|
|
90
|
+
|
|
91
|
+
# bar
|
|
77
92
|
win.draw_rect(self.color, (x, y + h//2 - 2, w, 4))
|
|
93
|
+
|
|
94
|
+
# handle
|
|
78
95
|
handle_x = x + ((self.value - self.min_val) / (self.max_val - self.min_val)) * w
|
|
79
96
|
handle_y = y + h // 2
|
|
80
|
-
|
|
97
|
+
|
|
98
|
+
win.draw_circle(self.handle_color, (int(handle_x), int(handle_y)), self.handle_radius)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: crystalwindow
|
|
3
|
-
Version: 3.8.
|
|
3
|
+
Version: 3.8.6
|
|
4
4
|
Summary: A Tkinter powered window + GUI toolkit made by Crystal (MEEEEEE)! Easier apps, smoother UI and all-in-one helpers!
|
|
5
5
|
Home-page: https://pypi.org/project/crystalwindow/
|
|
6
6
|
Author: CrystalBallyHereXD
|
|
@@ -14,7 +14,7 @@ crystalwindow/draw_tool.py,sha256=1YYEqjmgt4HpV3S15sTjCSmcqgHup4fD8gskTkxU0t4,16
|
|
|
14
14
|
crystalwindow/fun_helpers.py,sha256=fo5yTwGENltdtVIVwgITtUkvzpsImujOcqTxe8XPzR8,760
|
|
15
15
|
crystalwindow/gravity.py,sha256=pZJykZzO-mKVBPsZRP55nnlvUoYQfR29wPgJcI4IbBs,2904
|
|
16
16
|
crystalwindow/gui.py,sha256=vqI2Qpus0RHEwEsef0gojXb54yOFo6p-9TnDF4bEnSg,3538
|
|
17
|
-
crystalwindow/gui_ext.py,sha256=
|
|
17
|
+
crystalwindow/gui_ext.py,sha256=aOZ5Fa0VoBJd3SiEW2zgH2Sw1NwnK2mW1YtGdJijDVg,3045
|
|
18
18
|
crystalwindow/math.py,sha256=slOY3KQZ99VDMUMxsSJabMyRtJcwVzEyxR2RoXspHho,963
|
|
19
19
|
crystalwindow/player.py,sha256=4wpIdUZLTlRXV8fDRQ11yVJRbx_cv8Ekpn2y7pQGgAQ,3442
|
|
20
20
|
crystalwindow/sprites.py,sha256=2kYW4QfSnyUwRLedZCkb99wUSxn2a0JdWOHcfkxcG0U,3411
|
|
@@ -32,8 +32,8 @@ crystalwindow/gametests/guitesting.py,sha256=SrOssY5peCQEV6TQ1AiOWtjb9phVGdRzW-Q
|
|
|
32
32
|
crystalwindow/gametests/sandbox.py,sha256=Oo2tU2N0y3BPVa6T5vs_h9N6islhQrjSrr_78XLut5I,1007
|
|
33
33
|
crystalwindow/gametests/squaremove.py,sha256=poP2Zjl2oc2HVvIAgIK34H2jVj6otL4jEdvAOR6L9sI,572
|
|
34
34
|
crystalwindow/gametests/windowtesting.py,sha256=_9X6wnV1-_X_PtNS-0zu-k209NtFIwAc4vpxLPp7V2o,97
|
|
35
|
-
crystalwindow-3.8.
|
|
36
|
-
crystalwindow-3.8.
|
|
37
|
-
crystalwindow-3.8.
|
|
38
|
-
crystalwindow-3.8.
|
|
39
|
-
crystalwindow-3.8.
|
|
35
|
+
crystalwindow-3.8.6.dist-info/licenses/LICENSE,sha256=Gt5cJRchdNt0guxyQMHKsATN5PM5mjuDhdO6Gzs9qQc,1096
|
|
36
|
+
crystalwindow-3.8.6.dist-info/METADATA,sha256=VooxfUadE7ciIboTfZUUwY0N8FVaaLX5pm7pg3kivlo,7340
|
|
37
|
+
crystalwindow-3.8.6.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
38
|
+
crystalwindow-3.8.6.dist-info/top_level.txt,sha256=PeQSld4b19XWT-zvbYkvE2Xg8sakIMbDzSzSdOSRN8o,14
|
|
39
|
+
crystalwindow-3.8.6.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|