Skip to content

Commit 22a5da8

Browse files
Tinyu-Zhaolbuque
authored andcommitted
lib/m5ui: Limit switch maximum size.
Signed-off-by: [email protected] <[email protected]>
1 parent 2e2340a commit 22a5da8

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

m5stack/libs/m5ui/switch.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from m5ui.base import M5Base
66
import lvgl as lv
7+
import M5
78

89

910
class M5Switch(lv.switch):
@@ -85,19 +86,20 @@ def set_direction(self, direction):
8586
self.set_size(min(cur_w, cur_h), max(cur_w, cur_h))
8687

8788
def set_size(self, w, h):
88-
super().set_size(w, h)
89-
self.width = w
90-
self.height = h
89+
if w < 0 or h < 0:
90+
raise ValueError("Width and height must be non-negative")
9191

92-
def set_style_radius(self, radius: int, part: int) -> None:
93-
if radius < 0:
94-
raise ValueError("Radius must be a non-negative integer.")
95-
super().set_style_radius(radius, part)
92+
_width = M5.Display.width()
93+
_height = M5.Display.height()
9694

97-
def set_style_radius(self, radius: int, part: int) -> None:
98-
if radius < 0:
99-
raise ValueError("Radius must be a non-negative integer.")
100-
super().set_style_radius(radius, part)
95+
if w < _width and h < _height:
96+
super().set_size(w, h)
97+
else:
98+
print("Warning: width or height exceed screen size, auto set to screen size")
99+
super().set_size(_width, _height)
100+
101+
self.width = w
102+
self.height = h
101103

102104
def set_style_radius(self, radius: int, part: int) -> None:
103105
if radius < 0:

0 commit comments

Comments
 (0)