Skip to content

Commit be572aa

Browse files
Settings: add slider
1 parent 6a478a8 commit be572aa

2 files changed

Lines changed: 60 additions & 5 deletions

File tree

docs/frameworks/setting-activity.md

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# SettingActivity
22

3-
`SettingActivity` is used to edit a single setting with various UI options. It provides a flexible framework for collecting user input with support for text input, radio buttons, dropdowns, and custom Activity implementations.
3+
`SettingActivity` is used to edit a single setting with various UI options. It provides a flexible framework for collecting user input with support for text input, radio buttons, dropdowns, sliders, and custom Activity implementations.
44

55
## Overview
66

@@ -36,13 +36,15 @@ Each setting is defined as a dictionary with the following properties:
3636
- **`key`** (string): Unique identifier used as the SharedPreferences key
3737

3838
### Optional Properties
39-
- **`ui`** (string): UI type to use for editing. Options: `"textarea"` (default), `"radiobuttons"`, `"dropdown"`, `"activity"`
39+
- **`ui`** (string): UI type to use for editing. Options: `"textarea"` (default), `"radiobuttons"`, `"dropdown"`, `"slider"`, `"activity"`
4040
- **`ui_options`** (list): Options for `radiobuttons` and `dropdown` UI types
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
4444
- **`should_show`** (function): Function to determine if this setting should be displayed
4545
- **`dont_persist`** (bool): If `True`, the setting won't be saved to SharedPreferences
46+
- **`min`** (int): Minimum value for `"slider"` UI (default: `0`)
47+
- **`max`** (int): Maximum value for `"slider"` UI (default: `100`)
4648
- **`activity_class`** (class): Custom Activity class for `"activity"` UI type
4749
- **`value_label`** (widget): Internal reference to the value label (set by SettingsActivity)
4850
- **`cont`** (widget): Internal reference to the container (set by SettingsActivity)
@@ -140,7 +142,36 @@ ui_options = [
140142
- Shows label and value if different
141143
- Automatically selects the current value
142144

143-
### 4. Custom Activity
145+
### 4. Slider
146+
147+
Slider widget for integer values with real-time value display.
148+
149+
**When to use:** For numeric settings like volume, brightness, speed, or any integer within a range.
150+
151+
**Keys:**
152+
- **`min`** (int, default `0`): Minimum value (leftmost position)
153+
- **`max`** (int, default `100`): Maximum value (rightmost position)
154+
155+
**Example:**
156+
```python
157+
{
158+
"title": "Volume",
159+
"key": "volume",
160+
"ui": "slider",
161+
"default_value": "50",
162+
"min": 0,
163+
"max": 100,
164+
"changed_callback": self.on_volume_changed
165+
}
166+
```
167+
168+
**Features:**
169+
- Large label showing the current value above the slider
170+
- Real-time value updates as the user drags
171+
- Automatic clamping to `[min, max]` range
172+
- Value is persisted as a string (e.g. `"50"`)
173+
174+
### 5. Custom Activity
144175

145176
Use a custom Activity class for advanced UI implementations.
146177

docs/frameworks/settings-activity.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,14 @@ class MyApp(Activity):
3535
- **`key`** (string): Unique identifier used as the SharedPreferences key
3636

3737
### Optional Properties
38-
- **`ui`** (string): UI type for editing. Options: `"textarea"` (default), `"radiobuttons"`, `"dropdown"`, `"activity"`
38+
- **`ui`** (string): UI type for editing. Options: `"textarea"` (default), `"radiobuttons"`, `"dropdown"`, `"slider"`, `"activity"`
3939
- **`ui_options`** (list): Options for `radiobuttons` and `dropdown` UI types
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
4343
- **`dont_persist`** (bool): If `True`, the setting won't be saved to SharedPreferences
44+
- **`min`** (int): Minimum value for `"slider"` UI (default: `0`)
45+
- **`max`** (int): Maximum value for `"slider"` UI (default: `100`)
4446
- **`activity_class`** (class): Custom Activity class for `"activity"` UI type
4547
- **`value_label`** (widget): Internal reference to the value label (set by SettingsActivity)
4648
- **`cont`** (widget): Internal reference to the container (set by SettingsActivity)
@@ -94,7 +96,29 @@ Dropdown selection from a list of options.
9496
}
9597
```
9698

97-
### 4. Custom Activity
99+
### 4. Slider
100+
101+
Slider widget for integer values with real-time value display.
102+
103+
```python
104+
{
105+
"title": "Volume",
106+
"key": "volume",
107+
"ui": "slider",
108+
"default_value": "50",
109+
"min": 0,
110+
"max": 100,
111+
"changed_callback": self.on_volume_changed
112+
}
113+
```
114+
115+
**Keys:**
116+
- **`min`** (int, default `0`): Minimum value
117+
- **`max`** (int, default `100`): Maximum value
118+
119+
See [`SettingActivity`](setting-activity.md) for full details.
120+
121+
### 5. Custom Activity
98122

99123
Use a custom Activity class for advanced UI implementations.
100124

0 commit comments

Comments
 (0)