Skip to content

Commit bec047f

Browse files
Richard Taylorclaude
authored andcommitted
SettingsActivity: document ui_options label mapping for value-label row
Companion to MicroPythonOS#137 (framework change). Explains the (label, value) tuple semantics: label shown in picker AND in the settings-list row's value label; value is what gets stored. Adds a new "Display Labels for ui_options" section to settings-activity.md covering: - The (label, value) tuple format - Initial-render + post-save behavior - Fall-through for stale stored values not in current ui_options - Tips for choosing labels vs values (don't change values without a migration; labels are free to change) setting-activity.md gets a one-line cross-reference to the new section on the parent doc, since the same (label, value) contract applies in the picker UI as well. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 6a478a8 commit bec047f

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

docs/frameworks/setting-activity.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Each setting is defined as a dictionary with the following properties:
3737

3838
### Optional Properties
3939
- **`ui`** (string): UI type to use for editing. Options: `"textarea"` (default), `"radiobuttons"`, `"dropdown"`, `"activity"`
40-
- **`ui_options`** (list): Options for `radiobuttons` and `dropdown` UI types
40+
- **`ui_options`** (list): Options for `radiobuttons` and `dropdown` UI types. Each entry is a `(label, value)` tuple — the **label** appears on the radio button or dropdown row AND in the parent `SettingsActivity`'s value-label row beneath the title. The **value** is what gets stored in SharedPreferences. See [SettingsActivity → Display Labels for `ui_options`](settings-activity.md#display-labels-for-ui_options) for details.
4141
- **`placeholder`** (string): Placeholder text for textarea input
4242
- **`default_value`** (string): Default value to select or fill in
4343
- **`changed_callback`** (function): Callback function called when the setting value changes

docs/frameworks/settings-activity.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class MyApp(Activity):
3636

3737
### Optional Properties
3838
- **`ui`** (string): UI type for editing. Options: `"textarea"` (default), `"radiobuttons"`, `"dropdown"`, `"activity"`
39-
- **`ui_options`** (list): Options for `radiobuttons` and `dropdown` UI types
39+
- **`ui_options`** (list): Options for `radiobuttons` and `dropdown` UI types. Each entry is a `(label, value)` tuple — the **label** is shown in the picker AND in the row's value label below the title; the **value** is what gets stored in SharedPreferences. See [Display Labels for `ui_options`](#display-labels-for-ui_options) below.
4040
- **`placeholder`** (string): Placeholder text for textarea input
4141
- **`changed_callback`** (function): Callback function called when the setting value changes
4242
- **`should_show`** (function): Function to determine if this setting should be displayed in the list
@@ -107,6 +107,28 @@ Use a custom Activity class for advanced UI implementations.
107107
}
108108
```
109109

110+
## Display Labels for `ui_options`
111+
112+
For `radiobuttons` and `dropdown` settings, each entry in `ui_options` is a `(label, value)` tuple:
113+
114+
```python
115+
"ui_options": [
116+
("Lightning Piggy", "lightningpiggy"), # ← label ← stored value
117+
("Lightning Penguin", "lightningpenguin"),
118+
("None", "none"),
119+
]
120+
```
121+
122+
The settings-list row beneath each setting's title shows the **label** corresponding to the current stored value — not the raw value. So a row whose stored value is `"lightningpiggy"` displays "Lightning Piggy" below the title, matching what the user picked in the picker. This applies both on initial render and after a save.
123+
124+
If the stored value isn't present in the current `ui_options` list (e.g. a stale pref from before the option set changed), the raw value is shown unchanged rather than collapsing to "(not set)" — so the user can still see and recover from a now-invalid value.
125+
126+
Tips for choosing labels and values:
127+
128+
- **Labels** should be human-readable with spaces, casing, and punctuation as you want them shown to the user ("Lightning Piggy", not "lightningpiggy").
129+
- **Values** should be machine-friendly identifiers — short, no spaces, stable across releases. They appear in SharedPreferences and in any export/import flows, so keep them URL-safe and ASCII when possible.
130+
- **Don't change values for existing options** without a migration. The label can change freely (it's a presentation concern); the value is the identity.
131+
110132
## Advanced Features
111133

112134
### Conditional Visibility with should_show

0 commit comments

Comments
 (0)