Skip to content

Commit 97dde86

Browse files
Update docs
1 parent c77c47d commit 97dde86

4 files changed

Lines changed: 198 additions & 139 deletions

File tree

docs/architecture/frameworks.md

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,16 +213,32 @@ class MyActivity(Activity):
213213

214214
See [FileExplorerActivity](../frameworks/file-explorer-activity.md) for details.
215215

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.
218218

219219
```python
220-
from mpos import add_focus_border
220+
from mpos import add_focus_highlight
221221

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()
223239
```
224240

225-
See [Focus Borders](../frameworks/focus.md) for details.
241+
See [LightsManager](../frameworks/lights-manager.md) for details.
226242

227243
### CameraManager
228244
Provides access to camera hardware.

docs/frameworks/focus.md

Lines changed: 53 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,73 @@
1-
# Focus Borders
1+
# Focus Highlight
22

33
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.
44

55
## Overview
66

7-
`add_focus_border` registers two LVGL event callbacks on a widget:
7+
`add_focus_highlight` registers two LVGL event callbacks on a widget:
88

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.
1111

1212
The helper is re-exported from the top-level `mpos` module, so apps can import it directly.
1313

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. |
20+
1421
## API
1522

1623
```python
17-
from mpos import add_focus_border
24+
from mpos import add_focus_highlight
25+
26+
# Border mode (default)
27+
add_focus_highlight(widget)
28+
add_focus_highlight(widget, width=2)
29+
add_focus_highlight(widget, width=2, color=lv.color_hex(0xFFFFFF))
30+
add_focus_highlight(widget, width=2, opacity=lv.OPA._50, radius=5)
1831

19-
add_focus_border(widget)
20-
add_focus_border(widget, width=2)
21-
add_focus_border(widget, width=2, color=lv.color_hex(0xFFFFFF))
22-
add_focus_border(widget, width=2, opacity=lv.OPA._50, radius=5)
32+
# Background mode
33+
add_focus_highlight(widget, mode="bg")
34+
add_focus_highlight(widget, mode="bg", color=lv.color_hex(0x444444))
2335
```
2436

2537
### Parameters
2638

2739
| Parameter | Default | Description |
2840
|-----------|---------|-------------|
2941
| `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). |
3847

39-
```python
40-
focusgroup = lv.group_get_default()
41-
if focusgroup:
42-
focusgroup.add_obj(my_widget)
43-
```
48+
### Widget and focus group
4449

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.
4651

4752
### Touch-aware behavior
4853

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.
5055

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:
5257

5358
```python
5459
focusgroup = lv.group_get_default()
5560
if focusgroup:
56-
focusgroup.add_obj(btn)
5761
focusgroup.focus_obj(btn)
5862
```
5963

6064
## Examples
6165

62-
### Basic usage
66+
### Basic usage (border mode)
6367

6468
```python
6569
import lvgl as lv
66-
from mpos import Activity, add_focus_border
70+
from mpos import Activity, add_focus_highlight
6771

6872
class MyActivity(Activity):
6973
def onCreate(self):
@@ -74,38 +78,48 @@ class MyActivity(Activity):
7478
btn_label = lv.label(btn)
7579
btn_label.set_text("Focus me")
7680

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)
8282

8383
self.setContentView(screen)
8484
```
8585

86+
### Background mode
87+
88+
Use `mode="bg"` when the widget already has a persistent border that shouldn't be overwritten:
89+
90+
```python
91+
btn = lv.button(screen)
92+
btn.set_style_border_width(2, lv.PART.MAIN)
93+
btn.set_style_border_color(lv.color_hex(0x333333), lv.PART.MAIN)
94+
add_focus_highlight(btn, mode="bg")
95+
```
96+
8697
### Thicker, semi-transparent border
8798

8899
```python
89-
add_focus_border(btn, width=3, opacity=lv.OPA._50, radius=5)
100+
add_focus_highlight(btn, width=3, opacity=lv.OPA._50, radius=5)
90101
```
91102

92103
### Focus highlight on a label
93104

94-
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:
95106

96107
```python
97108
row = lv.label(screen)
98109
row.set_text("Setting row")
99110
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)
102112
```
103113

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+
104118
## When to use it
105119

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`.
107121

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.
109123

110124
## See Also
111125

0 commit comments

Comments
 (0)