You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/architecture/frameworks.md
+21-5Lines changed: 21 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -213,16 +213,32 @@ class MyActivity(Activity):
213
213
214
214
See [FileExplorerActivity](../frameworks/file-explorer-activity.md) for details.
215
215
216
-
### Focus Borders
217
-
Provides a single helper, `add_focus_border`, for drawing a focus border around any widget. It replaces the duplicated `FOCUSED`/`DEFOCUSED` handlers that used to exist in many apps.
216
+
### Focus Highlight
217
+
Provides a single helper, `add_focus_highlight`, for drawing a focus border or background tint around any widget. It replaces the duplicated `FOCUSED`/`DEFOCUSED` handlers that used to exist in many apps.
218
218
219
219
```python
220
-
from mpos importadd_focus_border
220
+
from mpos importadd_focus_highlight
221
221
222
-
add_focus_border(button, width=2)
222
+
# Border mode (default)
223
+
add_focus_highlight(button, width=2)
224
+
225
+
# Background mode (keep existing border intact)
226
+
add_focus_highlight(button, mode="bg")
227
+
```
228
+
229
+
See [Focus Highlight](../frameworks/focus.md) for details.
230
+
231
+
### LightsManager
232
+
Controls NeoPixel RGB LEDs on supported hardware. Provides buffered LED control, predefined notification colors, and frame-based animation support.
233
+
234
+
```python
235
+
from mpos import lights
236
+
237
+
lights.set_all(0, 0, 255)
238
+
lights.write()
223
239
```
224
240
225
-
See [Focus Borders](../frameworks/focus.md) for details.
241
+
See [LightsManager](../frameworks/lights-manager.md) for details.
Copy file name to clipboardExpand all lines: docs/frameworks/focus.md
+53-39Lines changed: 53 additions & 39 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,69 +1,73 @@
1
-
# Focus Borders
1
+
# Focus Highlight
2
2
3
3
MicroPythonOS provides a single, reusable helper for focus highlighting so that apps and framework screens do not have to duplicate the same `FOCUSED`/`DEFOCUSED` event handlers.
4
4
5
5
## Overview
6
6
7
-
`add_focus_border` registers two LVGL event callbacks on a widget:
7
+
`add_focus_highlight` registers two LVGL event callbacks on a widget:
8
8
9
-
-**`FOCUSED`**: draw a border around the widget and scroll it into view.
10
-
-**`DEFOCUSED`**: hide the border again.
9
+
-**`FOCUSED`**: draw a border around the widget (or tint its background) and scroll it into view.
10
+
-**`DEFOCUSED`**: remove the highlight again.
11
11
12
12
The helper is re-exported from the top-level `mpos` module, so apps can import it directly.
13
13
14
+
Two highlight modes are available:
15
+
16
+
| Mode | Effect |
17
+
|------|--------|
18
+
|`"border"` (default) | Draws a border around the widget on focus. |
19
+
|`"bg"`| Tints the widget's background on focus, leaving border styles intact. |
|`widget`| required | The LVGL object that should receive focus highlighting. |
30
-
|`width`|`1`| Border width in pixels when focused. |
31
-
|`color`| theme primary color | Border color. Falls back to `lv.theme_get_color_primary(None)` when omitted. |
32
-
|`opacity`|`None`| Optional `lv.OPA.*` value for the focused border. |
33
-
|`radius`|`None`| Optional corner radius for the focused border. |
34
-
35
-
### Requirements
36
-
37
-
For the callbacks to fire, the widget must be part of the default LVGL focus group:
42
+
|`mode`|`"border"`| Highlight mode: `"border"` draws a border, `"bg"` tints the background. |
43
+
|`width`|`1`| Border width in pixels when focused (ignored in `"bg"` mode). |
44
+
|`color`| theme primary color | Highlight color. Falls back to `lv.theme_get_color_primary(None)` when omitted. |
45
+
|`opacity`|`None`| Optional `lv.OPA.*` value for the focused border (ignored in `"bg"` mode). |
46
+
|`radius`|`None`| Optional corner radius for the focused border (ignored in `"bg"` mode). |
38
47
39
-
```python
40
-
focusgroup = lv.group_get_default()
41
-
if focusgroup:
42
-
focusgroup.add_obj(my_widget)
43
-
```
48
+
### Widget and focus group
44
49
45
-
`add_focus_border` only draws the visual feedback; it does **not** add the widget to the focus group.
50
+
`add_focus_highlight` adds the widget to the default LVGL focus group automatically. You do not need to call `focusgroup.add_obj()` manually.
46
51
47
52
### Touch-aware behavior
48
53
49
-
On devices that are primarily controlled with a touchscreen, the focus border is intentionally hidden until the user first navigates with a directional input (keyboard, hardware buttons, or a rotary encoder). This keeps touch-only screens clean while still making focused elements obvious once physical navigation begins.
54
+
On devices that are primarily controlled with a touchscreen, the focus highlight is intentionally hidden until the user first navigates with a directional input (keyboard, hardware buttons, or a rotary encoder). This keeps touch-only screens clean while still making focused elements obvious once physical navigation begins.
50
55
51
-
If you want a widget to reveal the focus border immediately, ensure it is added to the default focus group and focus it programmatically:
56
+
If you want a widget to reveal the focus highlight immediately, focus it programmatically:
52
57
53
58
```python
54
59
focusgroup = lv.group_get_default()
55
60
if focusgroup:
56
-
focusgroup.add_obj(btn)
57
61
focusgroup.focus_obj(btn)
58
62
```
59
63
60
64
## Examples
61
65
62
-
### Basic usage
66
+
### Basic usage (border mode)
63
67
64
68
```python
65
69
import lvgl as lv
66
-
from mpos import Activity, add_focus_border
70
+
from mpos import Activity, add_focus_highlight
67
71
68
72
classMyActivity(Activity):
69
73
defonCreate(self):
@@ -74,38 +78,48 @@ class MyActivity(Activity):
74
78
btn_label = lv.label(btn)
75
79
btn_label.set_text("Focus me")
76
80
77
-
add_focus_border(btn)
78
-
79
-
focusgroup = lv.group_get_default()
80
-
if focusgroup:
81
-
focusgroup.add_obj(btn)
81
+
add_focus_highlight(btn)
82
82
83
83
self.setContentView(screen)
84
84
```
85
85
86
+
### Background mode
87
+
88
+
Use `mode="bg"` when the widget already has a persistent border that shouldn't be overwritten:
Labels are not focusable by default, but they can be added to the focus group when they act as list rows:
105
+
Labels are not focusable by default, but they can be made focusable when they act as list rows:
95
106
96
107
```python
97
108
row = lv.label(screen)
98
109
row.set_text("Setting row")
99
110
row.add_flag(lv.obj.FLAG.CLICKABLE)
100
-
add_focus_border(row, width=2)
101
-
focusgroup.add_obj(row)
111
+
add_focus_highlight(row, width=2)
102
112
```
103
113
114
+
## Compatibility
115
+
116
+
`add_focus_border` is kept as a compatibility wrapper for the pre‑0.15.0 API. It delegates to `add_focus_highlight` with `mode="border"`. New code should use `add_focus_highlight` directly.
117
+
104
118
## When to use it
105
119
106
-
Use `add_focus_border` whenever you previously wrote a pair of `FOCUSED`/`DEFOCUSED` callbacks whose only job was to show or hide a border. It is used by the framework itself in places such as the launcher, settings screens, the top-menu drawer, `ImageView`, `MusicPlayer`, `ShowFonts`, `Connect4`, `About`, `HowTo`, and `WiFi Settings`.
120
+
Use `add_focus_highlight` whenever you previously wrote a pair of `FOCUSED`/`DEFOCUSED` callbacks whose only job was to show or hide a border or background tint. It is used by the framework itself in places such as the launcher, settings screens, the top-menu drawer, `ImageView`, `MusicPlayer`, `ShowFonts`, `Connect4`, `About`, `HowTo`, and `WiFi Settings`.
107
121
108
-
If you need additional behavior on focus (for example, starting a timer or loading data), keep your own callbacks and add `add_focus_border` alongside them.
122
+
If you need additional behavior on focus (for example, starting a timer or loading data), keep your own callbacks and add `add_focus_highlight` alongside them.
0 commit comments