@@ -219,8 +219,43 @@ def download_zip(url: str, name: str|None = None) -> str:
219219 "outline_color" : (config .palette_fg if config is not None else 0xffffff ),
220220 "selected_fill" : (config .palette_fg if config is not None else 0xffffff ),
221221 "selected_label" : (config .palette_bg if config is not None else 0x222222 ),
222+ "selected_outline" : (config .palette_fg if config is not None else 0xffffff ),
222223}
223224
225+ class ActionButton (Button ):
226+
227+ def __init__ (self , action : typing .Callable = None , ** kwargs ):
228+ self ._action = action
229+ super ().__init__ (** kwargs )
230+
231+ def click (self ) -> None :
232+ if self ._action is not None :
233+ self .selected = True
234+ self ._action ()
235+
236+ class TileGridButton (Button ):
237+
238+ def __init__ (self , bitmap : displayio .Bitmap = None , pixel_shader : displayio .PixelShader = None , pixel_shader_index : int = 0 , ** kwargs ):
239+ super ().__init__ (** kwargs )
240+ self ._pixel_shader_index = pixel_shader_index
241+ self ._tilegrid = AnchoredTileGrid (
242+ bitmap = bitmap ,
243+ pixel_shader = pixel_shader ,
244+ )
245+ self ._tilegrid .anchor_point = (0.5 , 0.5 )
246+ self ._tilegrid .anchored_position = (self .width // 2 , self .height // 2 )
247+ self ._tilegrid .pixel_shader [pixel_shader_index ] = self .label_color
248+ self .append (self ._tilegrid )
249+
250+ @property
251+ def selected (self ) -> bool :
252+ return self ._selected
253+
254+ @selected .setter
255+ def selected (self , value : bool ) -> None :
256+ super ().selected = value
257+ self ._tilegrid .pixel_shader [self ._pixel_shader_index ] = self .selected_label if value else self .label_color
258+
224259# create groups
225260root_group = displayio .Group ()
226261display .root_group = root_group
@@ -412,13 +447,22 @@ def reset(timeout:int = 0) -> None:
412447arrow_group .append (right_arrow )
413448
414449# setup exit icon
415- exit_tg = AnchoredTileGrid (
450+ exit_button = TileGridButton (
416451 bitmap = exit_bmp ,
417452 pixel_shader = exit_palette ,
453+ pixel_shader_index = 1 ,
454+ x = 0 ,
455+ y = 0 ,
456+ width = TITLE_HEIGHT ,
457+ height = TITLE_HEIGHT ,
458+ fill_color = (config .palette_bg if config is not None else 0x222222 ),
459+ label_color = (config .palette_fg if config is not None else 0xffffff ),
460+ outline_color = (config .palette_bg if config is not None else 0x222222 ),
461+ selected_fill = (config .palette_fg if config is not None else 0xffffff ),
462+ selected_label = (config .palette_bg if config is not None else 0x222222 ),
463+ selected_outline = (config .palette_fg if config is not None else 0xffffff ),
418464)
419- exit_tg .anchor_point = (0.5 , 0.5 )
420- exit_tg .anchored_position = (TITLE_HEIGHT // 2 , TITLE_HEIGHT // 2 )
421- arrow_group .append (exit_tg )
465+ arrow_group .append (exit_button )
422466
423467# setup dialog
424468dialog_group = displayio .Group ()
@@ -457,15 +501,6 @@ def reset(timeout:int = 0) -> None:
457501dialog_buttons .hidden = True
458502root_group .append (dialog_buttons )
459503
460- class DialogButton (Button ):
461- def __init__ (self , action : typing .Callable = None , ** kwargs ):
462- self ._action = action
463- super ().__init__ (** kwargs )
464- def click (self ) -> None :
465- if self ._action is not None :
466- self .selected = True
467- self ._action ()
468-
469504def show_dialog (content : str , actions : list = None ) -> None :
470505 # update content
471506 dialog_content .text = content
@@ -478,7 +513,7 @@ def show_dialog(content: str, actions: list = None) -> None:
478513 )
479514 buttons_width = (button_width + MENU_GAP ) * len (actions ) - MENU_GAP
480515 for index , (label , action ) in enumerate (actions ):
481- dialog_buttons .append (DialogButton (
516+ dialog_buttons .append (ActionButton (
482517 action = action ,
483518 label = label ,
484519 x = (DISPLAY_WIDTH - buttons_width ) // 2 + (button_width + MENU_GAP ) * index ,
@@ -877,7 +912,7 @@ def atexit_callback() -> None:
877912 next_page ()
878913 elif not left_arrow .hidden and left_arrow .contains ((mouse .x , mouse .y , 0 )):
879914 previous_page ()
880- elif exit_tg .contains ((mouse .x , mouse .y , 0 )):
915+ elif exit_button .contains ((mouse .x , mouse .y )):
881916 reset ()
882917 else :
883918 for button in category_group :
0 commit comments