11import lvgl as lv
22import mpos .config
33
4+ # Global style for keyboard button fix
5+ _keyboard_button_fix_style = None
6+ _is_light_mode = True
7+
8+ def get_keyboard_button_fix_style ():
9+ """
10+ Get the keyboard button fix style for light mode.
11+
12+ The LVGL default theme applies bg_color_white to keyboard buttons,
13+ which makes them white-on-white (invisible) in light mode.
14+ This function returns a custom style to override that.
15+
16+ Returns:
17+ lv.style_t: Style to apply to keyboard buttons, or None if not needed
18+ """
19+ global _keyboard_button_fix_style , _is_light_mode
20+
21+ # Only return style in light mode
22+ if not _is_light_mode :
23+ return None
24+
25+ # Create style if it doesn't exist
26+ if _keyboard_button_fix_style is None :
27+ _keyboard_button_fix_style = lv .style_t ()
28+ _keyboard_button_fix_style .init ()
29+
30+ # Set button background to light gray (matches LVGL's intended design)
31+ # This provides contrast against white background
32+ # Using palette_lighten gives us the same gray as used in the theme
33+ gray_color = lv .palette_lighten (lv .PALETTE .GREY , 2 )
34+ _keyboard_button_fix_style .set_bg_color (gray_color )
35+ _keyboard_button_fix_style .set_bg_opa (lv .OPA .COVER )
36+
37+ return _keyboard_button_fix_style
38+
39+ # On ESP32, the keyboard buttons in light mode have no color, just white,
40+ # which makes them hard to see on the white background. Probably a bug in the
41+ # underlying LVGL or MicroPython or lvgl_micropython.
42+ def fix_keyboard_button_style (keyboard ):
43+ """
44+ Apply keyboard button visibility fix to a keyboard instance.
45+
46+ Call this function after creating a keyboard to ensure buttons
47+ are visible in light mode.
48+
49+ Args:
50+ keyboard: The lv.keyboard instance to fix
51+ """
52+ style = get_keyboard_button_fix_style ()
53+ if style :
54+ keyboard .add_style (style , lv .PART .ITEMS )
55+ print (f"Applied keyboard button fix for light mode to keyboard instance" )
56+
457def set_theme (prefs ):
58+ global _is_light_mode
59+
560 # Load and set theme:
661 theme_light_dark = prefs .get_string ("theme_light_dark" , "light" ) # default to a light theme
762 theme_dark_bool = ( theme_light_dark == "dark" )
63+ _is_light_mode = not theme_dark_bool # Track for keyboard button fix
64+
865 primary_color = lv .theme_get_color_primary (None )
966 color_string = prefs .get_string ("theme_primary_color" )
1067 if color_string :
@@ -18,3 +75,7 @@ def set_theme(prefs):
1875
1976 lv .theme_default_init (mpos .ui .main_display ._disp_drv , primary_color , lv .color_hex (0xFBDC05 ), theme_dark_bool , lv .font_montserrat_12 )
2077 #mpos.ui.main_display.set_theme(theme) # not needed, default theme is applied immediately
78+
79+ # Recreate keyboard button fix style if mode changed
80+ global _keyboard_button_fix_style
81+ _keyboard_button_fix_style = None # Force recreation with new theme colors
0 commit comments