|
4 | 4 |
|
5 | 5 | from m5ui.base import M5Base |
6 | 6 | import lvgl as lv |
| 7 | +import M5 |
7 | 8 |
|
8 | 9 |
|
9 | 10 | class M5Switch(lv.switch): |
@@ -85,19 +86,20 @@ def set_direction(self, direction): |
85 | 86 | self.set_size(min(cur_w, cur_h), max(cur_w, cur_h)) |
86 | 87 |
|
87 | 88 | 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") |
91 | 91 |
|
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() |
96 | 94 |
|
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 |
101 | 103 |
|
102 | 104 | def set_style_radius(self, radius: int, part: int) -> None: |
103 | 105 | if radius < 0: |
|
0 commit comments