Skip to content

Commit 0c9a253

Browse files
Tinyu-Zhaolbuque
authored andcommitted
lib/m5ui: M5Base add API for setting line color and opa.
Signed-off-by: tinyu <tinyu@m5stack.com>
1 parent f56c8d5 commit 0c9a253

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

m5stack/libs/m5ui/base.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,22 @@ def set_text_color(self, color: int, opa: int, part: int) -> None:
7373
time.sleep(0.01)
7474
self.set_style_text_opa(opa, part)
7575

76+
@staticmethod
77+
def set_line_color(self, color: int, opa: int, part: int) -> None:
78+
"""Set the line color and opacity for a given part of the object.
79+
80+
:param int color: The color to set, can be an integer (hex) or a lv.color object.
81+
:param int opa: The opacity level (0-255).
82+
:param int part: The part of the object to apply the style to (e.g., lv.PART.MAIN).
83+
:return: None
84+
"""
85+
if isinstance(color, int):
86+
color = lv.color_hex(color)
87+
88+
self.set_style_line_color(color, part)
89+
time.sleep(0.01)
90+
self.set_style_line_opa(opa, part)
91+
7692
@staticmethod
7793
def set_bg_color(self, color: int, opa: int, part: int) -> None:
7894
"""Set the background color and opacity for a given part of the object.

m5stack/libs/m5ui/line.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def __init__(
4545
super().__init__(parent)
4646

4747
self.set_points(points)
48-
self.set_line_color(color, 255)
48+
self.set_line_color(color, 255, lv.PART.MAIN)
4949
self.set_style_line_width(width, lv.PART.MAIN)
5050
self.set_style_line_rounded(rounded, lv.PART.MAIN)
5151

0 commit comments

Comments
 (0)