Skip to content

Commit cad2ea2

Browse files
bitcoin3usclaude
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 41dda22 commit cad2ea2

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
@@ -39,7 +39,7 @@ Each setting is defined as a dictionary with the following properties:
3939

4040
### Optional Properties
4141
- **`ui`** (string): UI type to use for editing. Options: `"textarea"` (default), `"radiobuttons"`, `"dropdown"`, `"slider"`, `"activity"`
42-
- **`ui_options`** (list): Options for `radiobuttons` and `dropdown` UI types
42+
- **`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.
4343
- **`placeholder`** (string): Placeholder text for textarea input
4444
- **`default_value`** (string): Default value to select or fill in
4545
- **`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"`, `"slider"`, `"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): Boolean or function to determine if this setting should be displayed in the list
@@ -132,6 +132,28 @@ Use a custom Activity class for advanced UI implementations.
132132
}
133133
```
134134

135+
## Display Labels for `ui_options`
136+
137+
For `radiobuttons` and `dropdown` settings, each entry in `ui_options` is a `(label, value)` tuple:
138+
139+
```python
140+
"ui_options": [
141+
("Lightning Piggy", "lightningpiggy"), # ← label ← stored value
142+
("Lightning Penguin", "lightningpenguin"),
143+
("None", "none"),
144+
]
145+
```
146+
147+
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.
148+
149+
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.
150+
151+
Tips for choosing labels and values:
152+
153+
- **Labels** should be human-readable with spaces, casing, and punctuation as you want them shown to the user ("Lightning Piggy", not "lightningpiggy").
154+
- **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.
155+
- **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.
156+
135157
## Advanced Features
136158

137159
### Conditional Visibility with should_show

0 commit comments

Comments
 (0)