@@ -41,7 +41,10 @@ class IconWidget(Widget, Control):
41
41
:param string icon: the filepath of the bmp image to be used as the icon.
42
42
:param boolean on_disk: if True use OnDiskBitmap instead of imageload.
43
43
This can be helpful to save memory. Defaults to False
44
-
44
+ :param Optional[int] transparent_index: if not None this color index will get set to
45
+ transparent on the palette of the icon.
46
+ :param Optional[int] label_background: if not None this color will be used as a background
47
+ for the icon label.
45
48
:param int x: x location the icon widget should be placed. Pixel coordinates.
46
49
:param int y: y location the icon widget should be placed. Pixel coordinates.
47
50
:param anchor_point: (X,Y) values from 0.0 to 1.0 to define the anchor point relative to the
@@ -51,16 +54,30 @@ class IconWidget(Widget, Control):
51
54
:type anchored_position: Tuple[int, int]
52
55
"""
53
56
54
- def __init__ (self , label_text , icon , on_disk = False , ** kwargs ):
57
+ # pylint: disable=too-many-arguments
58
+
59
+ def __init__ (
60
+ self ,
61
+ label_text ,
62
+ icon ,
63
+ on_disk = False ,
64
+ transparent_index = None ,
65
+ label_background = None ,
66
+ ** kwargs
67
+ ):
55
68
super ().__init__ (** kwargs )
56
69
57
70
self ._icon = icon
58
71
59
72
if on_disk :
60
73
image = OnDiskBitmap (self ._icon )
74
+ if transparent_index is not None :
75
+ image .pixel_shader .make_transparent (transparent_index )
61
76
tile_grid = TileGrid (image , pixel_shader = image .pixel_shader )
62
77
else :
63
78
image , palette = adafruit_imageload .load (icon )
79
+ if transparent_index is not None :
80
+ palette .make_transparent (transparent_index )
64
81
tile_grid = TileGrid (image , pixel_shader = palette )
65
82
self .append (tile_grid )
66
83
_label = bitmap_label .Label (
@@ -70,6 +87,10 @@ def __init__(self, label_text, icon, on_disk=False, **kwargs):
70
87
anchor_point = (0.5 , 0 ),
71
88
anchored_position = (image .width // 2 , image .height ),
72
89
)
90
+
91
+ if label_background is not None :
92
+ _label .background_color = label_background
93
+
73
94
self .append (_label )
74
95
self .touch_boundary = (
75
96
0 ,
0 commit comments