@@ -41,7 +41,10 @@ class IconWidget(Widget, Control):
4141 :param string icon: the filepath of the bmp image to be used as the icon.
4242 :param boolean on_disk: if True use OnDiskBitmap instead of imageload.
4343 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.
4548 :param int x: x location the icon widget should be placed. Pixel coordinates.
4649 :param int y: y location the icon widget should be placed. Pixel coordinates.
4750 :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):
5154 :type anchored_position: Tuple[int, int]
5255 """
5356
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+ ):
5568 super ().__init__ (** kwargs )
5669
5770 self ._icon = icon
5871
5972 if on_disk :
6073 image = OnDiskBitmap (self ._icon )
74+ if transparent_index is not None :
75+ image .pixel_shader .make_transparent (transparent_index )
6176 tile_grid = TileGrid (image , pixel_shader = image .pixel_shader )
6277 else :
6378 image , palette = adafruit_imageload .load (icon )
79+ if transparent_index is not None :
80+ palette .make_transparent (transparent_index )
6481 tile_grid = TileGrid (image , pixel_shader = palette )
6582 self .append (tile_grid )
6683 _label = bitmap_label .Label (
@@ -70,6 +87,10 @@ def __init__(self, label_text, icon, on_disk=False, **kwargs):
7087 anchor_point = (0.5 , 0 ),
7188 anchored_position = (image .width // 2 , image .height ),
7289 )
90+
91+ if label_background is not None :
92+ _label .background_color = label_background
93+
7394 self .append (_label )
7495 self .touch_boundary = (
7596 0 ,
0 commit comments