Modern Apps git

← Modern-Apps.git

library: add strict SettingsPage DSL system

Commit
294a7c1645d66ab9b2052f54a37646cd66f5edf9
Author
Vayun Mathur <[email protected]>
When
2026-12-05 14:36 UTC (21 hours ago)
Parents
1f13e91
Build the pre-built settings page system in library/ui: a SettingsPage host (AppScaffold + DesktopMaxWidth + scroll, optional import/export backup section) and a SettingsScope DSL (Section, Toggle, Slider, Choice, MultiChoice, RadioChoice, TextInput, Stepper, ColorChoice, Action, DestructiveAction, Info, Footer, Divider) where every control takes title first and an optional description second, matching the owner sketch. Each member delegates to the existing shared rows (SettingsSwitchRow, SettingsSliderRow, SettingsSelectRow, SettingsRadioRow, LabeledTextField, SettingsRow) so formatting is identical everywhere.

Persistence goes through SettingsBinding<T> and the SettingsDataStore (ds) interface in SettingsBinding.kt: an app's <App>Prefs owner supplies values/setters and its BackupFormat, and library/ui opens no DataStore.

Add SettingsPageTest covering toggle/slider/choice/stepper/colour/info/action rendering, backup section strings, and strict rules in library/ui/AGENTS.md (settings pages may only use these components; a vocabulary gap is a library change).

Verified: ./gradlew :library:ui:lint :library:ui:lintVitalRelease :library:ui:testDebugUnitTest --max-workers=128 (green).

Diff

library/ui/AGENTS.md
diff --git a/library/ui/AGENTS.md b/library/ui/AGENTS.mdindex 51d7ff8335..f65a8e556f 100644--- a/library/ui/AGENTS.md+++ b/library/ui/AGENTS.md@@ -15,6 +15,7 @@ **Purpose:** All shared Compose chrome for every app — activity shells, scaffolds, theme, icons, messenger, editors, motion. If it renders in more than one app, it lives here. **How to use (must-rules, enforced by lint):** - Activities extend `MaActivity` (or `MaFragmentActivity` for biometric-gated apps) — override `Content()` + `onCreateBeforeContent()`, never repeat the edge-to-edge/theme shell+- **Settings pages are strict (owner direction 2026-12-05):** a settings screen is `SettingsPage(title, onNavigateBack, importExport, ds) { … }` from `SettingsPage.kt`, and its body may only compose `SettingsScope` members (`Section`, `Toggle`, `Slider`, `Choice`, `MultiChoice`, `RadioChoice`, `TextInput`, `Stepper`, `ColorChoice`, `Action`, `DestructiveAction`, `Info`, `Footer`, `Divider`). No raw `SettingsRow`/`ListItem`/`Switch`/`Slider`/`OutlinedTextField`/`Button`/divider/spacer UI, and no other form inputs, belong in an app settings page — the DSL members delegate to the shared rows so title/description/padding/trailing-control formatting is identical everywhere. Controls take a value + callback or a `SettingsBinding` built from the app's `<App>Prefs` flows/setters; that prefs owner is the `ds` (`SettingsDataStore`, whose `backupFormat` powers the `importExport = true` backup section via `BackupButtons`) and is the only class opening that app's DataStore. A vocabulary gap is a library change (add a `SettingsScope` member here), never a one-off row in an app. - Screens use the `AppScaffold` family (never raw `Scaffold`); icons via the generated `IconXxx()` wrappers (manifest `icons.tsv`, generated at build time by `GenerateIconsTask`; never `Icon()`/`painterResource()`/`material.icons.*` in apps, never hand-edit the generated file — add one manifest line and rebuild); messages via `rememberMessenger()`/`AppMessages` (never `Toast`); motion via the `Motion*` helpers (never raw `animation` at call sites) **Areas:** activity shells (`MaActivity.kt`) · scaffolds (`AppScaffold`, `Detail`/`LazyList`/`TabbedPager`/`Setup`, `ListPage`) · theme + tokens (`DynamicTheme`, `Material*`, `Spacing`, `Modifier`, `Motion*`) · `Icons.kt` · messenger (`Messages.kt`) · editors (Html/Markdown/Odf + controllers) · pickers + dialogs (`dialog/`) · game chrome (`game/`) · ODF/doc export (`odf/`) · panorama · permissions + special-access · adaptive/wide layouts (`AdaptiveGrid`, `DesktopMaxWidth`, `PaneMargins`) · connectivity banner (`util/ConnectivityCompose.kt`). **Entry points + reading order:** `MaActivity.kt` → `AppScaffold.kt` → `Icons.kt` → `Messages.kt` → `DynamicTheme.kt`, then the area you need.@@ -88,6 +89,8 @@ ### Forms + settings - com/vayunmathur/library/ui/FormComponents.kt - com/vayunmathur/library/ui/FormSection.kt+- com/vayunmathur/library/ui/SettingsPage.kt — the settings host + strict DSL (`SettingsScope`: Section/Toggle/Slider/Choice/MultiChoice/RadioChoice/TextInput/Stepper/ColorChoice/Action/DestructiveAction/Info/Footer/Divider); the only way to build a settings page+- com/vayunmathur/library/ui/SettingsBinding.kt — `SettingsBinding<T>` + `SettingsDataStore` (`ds`): the persistence seam an app's `<App>Prefs` implements; library/ui opens no DataStore - com/vayunmathur/library/ui/SettingsComponents.kt - com/vayunmathur/library/ui/SettingsMenuRow.kt — settings row that opens a menu of actions (no persistent selection; use `SettingsSelectRow` in `SettingsComponents.kt` for picking a value) - com/vayunmathur/library/ui/SettingsSliderRow.kt
library/ui/src/main/java/com/vayunmathur/library/ui/SettingsBinding.kt
diff --git a/library/ui/src/main/java/com/vayunmathur/library/ui/SettingsBinding.kt b/library/ui/src/main/java/com/vayunmathur/library/ui/SettingsBinding.ktnew file mode 100644index 0000000000..ea13fb51f9--- /dev/null+++ b/library/ui/src/main/java/com/vayunmathur/library/ui/SettingsBinding.kt@@ -0,0 +1,44 @@+package com.vayunmathur.library.ui++import com.vayunmathur.library.util.BackupFormat++/**+ * A value plus the way to change it, handed to a settings row.+ *+ * This is the only persistence seam the settings system knows. An app's+ * `<App>Prefs` owner (the one class in that app allowed to open its+ * DataStore) reads its flows into [value] and turns [onValueChange] into+ * its suspending setter, usually from the hosting screen or ViewModel.+ * `library/ui` never opens a DataStore, reads a file, or names a+ * preference key, so the same rows work over DataStore, SharedPreferences,+ * a Room column, or plain in-memory state in a preview.+ */+class SettingsBinding<T>(+    val value: T,+    val onValueChange: (T) -> Unit,+)++/** Builds a [SettingsBinding] without naming the class at the call site. */+fun <T> settingsBinding(+    value: T,+    onValueChange: (T) -> Unit,+): SettingsBinding<T> = SettingsBinding(value, onValueChange)++/**+ * The `ds` argument of [SettingsPage]: what an app hands the page so the+ * page can offer backup/restore without knowing the app's storage.+ *+ * An app's prefs owner implements this beside its keys. Only+ * [backupFormat] is required by the page today: when+ * [SettingsPage]'s `importExport` flag is on and this returns non-null,+ * the page renders its backup section from that format (the same+ * [BackupFormat] the in-app [BackupButtons] consume, so platform backup+ * and in-app export cannot drift into different file sets). Return null+ * (the default) for an app whose data must never leave through this+ * page, and the section is simply absent.+ */+interface SettingsDataStore {+    /** Format for the import/export section, or null to offer none. */+    val backupFormat: BackupFormat?+        get() = null+}
library/ui/src/main/java/com/vayunmathur/library/ui/SettingsPage.kt
diff --git a/library/ui/src/main/java/com/vayunmathur/library/ui/SettingsPage.kt b/library/ui/src/main/java/com/vayunmathur/library/ui/SettingsPage.ktnew file mode 100644index 0000000000..64d41c2aea--- /dev/null+++ b/library/ui/src/main/java/com/vayunmathur/library/ui/SettingsPage.kt@@ -0,0 +1,531 @@+package com.vayunmathur.library.ui++import androidx.compose.foundation.background+import androidx.compose.foundation.border+import androidx.compose.foundation.clickable+import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.Row+import androidx.compose.foundation.layout.fillMaxSize+import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.layout.size+import androidx.compose.foundation.rememberScrollState+import androidx.compose.foundation.shape.CircleShape+import androidx.compose.foundation.verticalScroll+import androidx.compose.runtime.Composable+import androidx.compose.runtime.getValue+import androidx.compose.runtime.mutableStateOf+import androidx.compose.runtime.remember+import androidx.compose.runtime.setValue+import androidx.compose.ui.Alignment+import androidx.compose.ui.Modifier+import androidx.compose.ui.draw.clip+import androidx.compose.ui.graphics.Color+import androidx.compose.ui.res.stringResource+import androidx.compose.ui.text.input.KeyboardType+import androidx.compose.ui.unit.dp++/**+ * The one host every settings screen is built on, and the strict DSL its+ * body is written in.+ *+ * A settings page is:+ *+ * ```+ * SettingsPage(+ *     title = "Settings",+ *     onNavigateBack = { backStack.pop() },+ *     importExport = true,+ *     ds = settingsDataStore,+ * ) {+ *     Section("General") {+ *         Toggle("Title", "this is the description", binding)+ *     }+ * }+ * ```+ *+ * Inside the body only [SettingsScope] members may render UI: [Toggle],+ * [Slider], [Choice], [MultiChoice], [RadioChoice], [TextInput],+ * [Stepper], [ColorChoice], [Action], [DestructiveAction], [Info],+ * [Section] and [Footer]. Raw rows, fields, buttons, dividers and+ * spacers do not belong in a settings page (see `library/ui/AGENTS.md`);+ * every member formats its title, description, padding and trailing+ * control identically because each delegates to the one row family in+ * `SettingsComponents.kt` / `SettingsSliderRow.kt` / `FormComponents.kt`.+ *+ * Persistence is the caller's: each control takes either an explicit+ * value + change callback or a [SettingsBinding] built from the app's+ * `<App>Prefs` flows and setters. This file opens no DataStore.+ *+ * [importExport] with a [ds] whose [SettingsDataStore.backupFormat] is+ * non-null appends a backup section rendered by [BackupButtons], wired+ * to that format (export/import, password prompt and restart-on-import+ * included). With no format the section is absent, never a dead row.+ */+@Composable+fun SettingsPage(+    title: String,+    modifier: Modifier = Modifier,+    onNavigateBack: (() -> Unit)? = null,+    importExport: Boolean = false,+    ds: SettingsDataStore? = null,+    content: @Composable SettingsScope.() -> Unit,+) {+    AppScaffold(title = title, modifier = modifier, onNavigateBack = onNavigateBack) { padding ->+        DesktopMaxWidthContainer(modifier = Modifier.padding(padding)) {+            Column(+                modifier = Modifier+                    .fillMaxSize()+                    .verticalScroll(rememberScrollState()),+            ) {+                SettingsScope().content()+                if (importExport) {+                    val format = ds?.backupFormat+                    if (format != null) {+                        SettingsSection(title = stringResource(R.string.settings_backup)) {+                            Row(+                                modifier = Modifier+                                    .fillMaxWidth()+                                    .padding(horizontal = 16.dp, vertical = 8.dp),+                                verticalAlignment = Alignment.CenterVertically,+                            ) {+                                Text(+                                    stringResource(R.string.settings_backup_description),+                                    style = MaterialTheme.typography.bodySmall,+                                    color = MaterialTheme.colorScheme.onSurfaceVariant,+                                    modifier = Modifier.weight(1f),+                                )+                                BackupButtons(format = format)+                            }+                        }+                    }+                }+            }+        }+    }+}++/**+ * Receiver scope of [SettingsPage]: the strict settings vocabulary.+ *+ * Every member takes `title` first and an optional `description` second,+ * matching the sketch (`Toggle("Title", "this is the description")`), so+ * a page reads as a list of labelled controls and nothing else. Members+ * are the only UI a settings page may compose.+ */+class SettingsScope {+    /** A titled group of controls; [description] renders as its footer line. */+    @Composable+    fun Section(+        title: String? = null,+        description: String? = null,+        content: @Composable SettingsScope.() -> Unit,+    ) {+        SettingsSection(title = title) {+            if (description != null) Footer(description)+            [email protected]()+        }+    }++    /** Explanatory text under a section heading. */+    @Composable+    fun Footer(text: String) {+        SettingsFooter(+            text = text,+            modifier = Modifier.padding(horizontal = 16.dp, vertical = 4.dp),+        )+    }++    /** Inset divider between two controls in one section. */+    @Composable+    fun Divider() {+        SettingsDivider()+    }++    /** A switch control: the whole row toggles. */+    @Composable+    fun Toggle(+        title: String,+        description: String? = null,+        checked: Boolean,+        onCheckedChange: (Boolean) -> Unit,+        enabled: Boolean = true,+    ) {+        SettingsSwitchRow(+            title = title,+            supportingText = description,+            checked = checked,+            onCheckedChange = onCheckedChange,+            enabled = enabled,+        )+    }++    /** A switch control bound through [binding]. */+    @Composable+    fun Toggle(+        title: String,+        description: String? = null,+        binding: SettingsBinding<Boolean>,+        enabled: Boolean = true,+    ) {+        Toggle(title, description, binding.value, binding.onValueChange, enabled)+    }++    /** A continuous-value slider with its current value at the end of the title line. */+    @Composable+    fun Slider(+        title: String,+        description: String? = null,+        value: Float,+        onValueChange: (Float) -> Unit,+        valueRange: ClosedFloatingPointRange<Float> = 0f..1f,+        steps: Int = 0,+        enabled: Boolean = true,+        valueLabel: String? = null,+        valueFormatter: ((Float) -> String)? = null,+        onValueChangeFinished: (() -> Unit)? = null,+    ) {+        SettingsSliderRow(+            title = title,+            supportingText = description,+            value = value,+            onValueChange = onValueChange,+            valueRange = valueRange,+            steps = steps,+            enabled = enabled,+            valueLabel = valueLabel,+            valueFormatter = valueFormatter,+            onValueChangeFinished = onValueChangeFinished,+        )+    }++    /** A slider bound through [binding]. */+    @Composable+    fun Slider(+        title: String,+        description: String? = null,+        binding: SettingsBinding<Float>,+        valueRange: ClosedFloatingPointRange<Float> = 0f..1f,+        steps: Int = 0,+        enabled: Boolean = true,+        valueLabel: String? = null,+        valueFormatter: ((Float) -> String)? = null,+    ) {+        Slider(+            title = title,+            description = description,+            value = binding.value,+            onValueChange = binding.onValueChange,+            valueRange = valueRange,+            steps = steps,+            enabled = enabled,+            valueLabel = valueLabel,+            valueFormatter = valueFormatter,+        )+    }++    /** A single-choice picker: current value as the row's second line, menu on tap. */+    @Composable+    fun <T> Choice(+        title: String,+        description: String? = null,+        selected: T,+        options: List<T>,+        label: (T) -> String,+        onSelect: (T) -> Unit,+        enabled: Boolean = true,+    ) {+        SettingsSelectRow(+            title = title,+            supportingText = description,+            selected = selected,+            options = options,+            label = label,+            onSelect = onSelect,+            enabled = enabled,+        )+    }++    /** A single-choice picker bound through [binding]. */+    @Composable+    fun <T> Choice(+        title: String,+        description: String? = null,+        binding: SettingsBinding<T>,+        options: List<T>,+        label: (T) -> String,+        enabled: Boolean = true,+    ) {+        Choice(+            title = title,+            description = description,+            selected = binding.value,+            options = options,+            label = label,+            onSelect = binding.onValueChange,+            enabled = enabled,+        )+    }++    /** A single-choice list rendered inline, one radio row per option. */+    @Composable+    fun <T> RadioChoice(+        title: String,+        description: String? = null,+        selected: T,+        options: List<T>,+        label: (T) -> String,+        onSelect: (T) -> Unit,+        optionDescription: ((T) -> String?)? = null,+        enabled: Boolean = true,+    ) {+        Section(title = title, description = description) {+            Column(modifier = Modifier.padding(horizontal = 16.dp)) {+                options.forEach { option ->+                    SettingsRadioRow(+                        label = label(option),+                        supportingText = optionDescription?.invoke(option),+                        selected = option == selected,+                        onSelect = { onSelect(option) },+                        enabled = enabled,+                    )+                }+            }+        }+    }++    /**+     * A multi-choice picker: the menu toggles options in place and the+     * new selection is applied once, when the menu closes (one write,+     * not one per toggle). An emptied selection is discarded.+     */+    @Composable+    fun <T> MultiChoice(+        title: String,+        description: String? = null,+        selected: List<T>,+        options: List<T>,+        label: (T) -> String,+        onApply: (List<T>) -> Unit,+        enabled: Boolean = true,+    ) {+        var expanded by remember { mutableStateOf(false) }+        var staged by remember { mutableStateOf(emptySet<T>()) }+        Box {+            SettingsRow(+                title = title,+                supportingText = description+                    ?: selected.joinToString(", ") { label(it) }.ifEmpty { null },+                enabled = enabled,+                onClick = {+                    staged = selected.toSet()+                    expanded = true+                },+                trailingContent = { IconArrowDropDown() },+            )+            DropdownMenu(expanded = expanded, onDismissRequest = {+                expanded = false+                if (staged.isNotEmpty() && staged != selected.toSet()) {+                    onApply(options.filter { it in staged })+                }+            }) {+                options.forEach { option ->+                    CheckableDropdownMenuItem(+                        checked = option in staged,+                        onCheckedChange = { checked ->+                            staged = if (checked) staged + option else staged - option+                        },+                        text = { Text(label(option)) },+                        checkedLeadingIcon = { IconCheck() },+                    )+                }+            }+        }+    }++    /** A free-text field: [title] is the field label, [description] its supporting line. */+    @Composable+    fun TextInput(+        title: String,+        description: String? = null,+        value: String,+        onValueChange: (String) -> Unit,+        enabled: Boolean = true,+        singleLine: Boolean = true,+        keyboardType: KeyboardType = KeyboardType.Text,+        placeholder: String? = null,+        isError: Boolean = false,+    ) {+        Column(modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp)) {+            LabeledTextField(+                value = value,+                onValueChange = onValueChange,+                label = title,+                enabled = enabled,+                singleLine = singleLine,+                keyboardType = keyboardType,+                placeholder = placeholder,+                isError = isError,+                supportingText = description,+            )+        }+    }++    /** A free-text field bound through [binding]. */+    @Composable+    fun TextInput(+        title: String,+        description: String? = null,+        binding: SettingsBinding<String>,+        enabled: Boolean = true,+        singleLine: Boolean = true,+        keyboardType: KeyboardType = KeyboardType.Text,+        placeholder: String? = null,+        isError: Boolean = false,+    ) {+        TextInput(+            title = title,+            description = description,+            value = binding.value,+            onValueChange = binding.onValueChange,+            enabled = enabled,+            singleLine = singleLine,+            keyboardType = keyboardType,+            placeholder = placeholder,+            isError = isError,+        )+    }++    /** An integer stepper: minus/value/plus on the row's trailing side. */+    @Composable+    fun Stepper(+        title: String,+        description: String? = null,+        value: Int,+        onValueChange: (Int) -> Unit,+        range: IntRange = Int.MIN_VALUE..Int.MAX_VALUE,+        step: Int = 1,+        enabled: Boolean = true,+        format: (Int) -> String = { it.toString() },+    ) {+        SettingsRow(+            title = title,+            supportingText = description,+            enabled = enabled,+            trailingContent = {+                Row(verticalAlignment = Alignment.CenterVertically) {+                    IconButton(+                        onClick = { onValueChange((value - step).coerceIn(range)) },+                        enabled = enabled && value > range.first,+                    ) { IconRemove() }+                    Text(format(value))+                    IconButton(+                        onClick = { onValueChange((value + step).coerceIn(range)) },+                        enabled = enabled && value < range.last,+                    ) { IconAdd() }+                }+            },+        )+    }++    /** A colour choice: one swatch per option, the selected one ringed. */+    @Composable+    fun ColorChoice(+        title: String,+        description: String? = null,+        selected: Color,+        options: List<Color>,+        onSelect: (Color) -> Unit,+        enabled: Boolean = true,+    ) {+        Column(modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp)) {+            Text(title, style = MaterialTheme.typography.bodyMedium)+            if (description != null) {+                Text(+                    description,+                    style = MaterialTheme.typography.bodySmall,+                    color = MaterialTheme.colorScheme.onSurfaceVariant,+                )+            }+            Row(modifier = Modifier.padding(top = 8.dp)) {+                options.forEach { color ->+                    val ring = if (color == selected) {+                        Modifier.border(2.dp, MaterialTheme.colorScheme.primary, CircleShape)+                    } else {+                        Modifier+                    }+                    Box(+                        modifier = Modifier+                            .padding(end = 8.dp)+                            .size(36.dp)+                            .then(ring)+                            .clip(CircleShape)+                            .background(color)+                            .clickable(enabled = enabled) { onSelect(color) },+                    )+                }+            }+        }+    }++    /** A navigation/action row: tap fires [onClick]; a chevron marks it as leading somewhere. */+    @Composable+    fun Action(+        title: String,+        description: String? = null,+        enabled: Boolean = true,+        onClick: () -> Unit,+    ) {+        SettingsRow(+            title = title,+            supportingText = description,+            enabled = enabled,+            onClick = onClick,+            trailingContent = { IconChevronRight() },+        )+    }++    /** A destructive action row: tap asks for confirmation before [onConfirm]. */+    @Composable+    fun DestructiveAction(+        title: String,+        description: String? = null,+        confirmMessage: String? = null,+        confirmLabel: String = title,+        enabled: Boolean = true,+        onConfirm: () -> Unit,+    ) {+        var showConfirm by remember { mutableStateOf(false) }+        SettingsRow(+            title = title,+            supportingText = description,+            enabled = enabled,+            onClick = { showConfirm = true },+        )+        if (showConfirm) {+            ConfirmDialog(+                title = title,+                message = confirmMessage,+                confirmLabel = confirmLabel,+                dismissLabel = stringResource(R.string.cancel),+                destructive = true,+                onConfirm = onConfirm,+                onDismiss = { showConfirm = false },+            )+        }+    }++    /** A display-only status/info row: a value, never a control. */+    @Composable+    fun Info(+        title: String,+        description: String? = null,+        value: String? = null,+    ) {+        SettingsRow(+            title = title,+            supportingText = value ?: description,+        )+    }+}
library/ui/src/main/res/values/strings.xml
diff --git a/library/ui/src/main/res/values/strings.xml b/library/ui/src/main/res/values/strings.xmlindex 7f9fb8c66c..efa88557f4 100644--- a/library/ui/src/main/res/values/strings.xml+++ b/library/ui/src/main/res/values/strings.xml@@ -90,6 +90,10 @@     <string name="play">Play</string>     <!-- Shared across every app. Reset to defaults. Verb, keep short. -->     <string name="reset">Reset</string>+    <!-- SettingsPage import/export section heading. Noun. -->+    <string name="settings_backup">Backup</string>+    <!-- SettingsPage import/export section description. Full sentence. -->+    <string name="settings_backup_description">Export or import this app\'s data as a backup file.</string>     <!-- Shared across every app. ResetDefaultsRow confirmation body: every setting goes back to its default. -->     <string name="reset_defaults_message">All settings will go back to their defaults.</string>     <!-- Shared across every app. Apply pending changes. Verb, keep short. -->
library/ui/src/test/java/com/vayunmathur/library/ui/SettingsPageTest.kt
diff --git a/library/ui/src/test/java/com/vayunmathur/library/ui/SettingsPageTest.kt b/library/ui/src/test/java/com/vayunmathur/library/ui/SettingsPageTest.ktnew file mode 100644index 0000000000..b4644df155--- /dev/null+++ b/library/ui/src/test/java/com/vayunmathur/library/ui/SettingsPageTest.kt@@ -0,0 +1,57 @@+package com.vayunmathur.library.ui++import androidx.compose.ui.graphics.Color+import androidx.compose.ui.test.assertIsDisplayed+import androidx.compose.ui.test.performScrollTo+import androidx.compose.ui.test.junit4.createComposeRule+import androidx.compose.ui.test.onNodeWithText+import androidx.compose.ui.test.performClick+import org.junit.Rule+import org.junit.runner.RunWith+import org.robolectric.RobolectricTestRunner+import kotlin.test.Test+import kotlin.test.assertEquals++/** The strict settings DSL: title/description controls render and report. */+@RunWith(RobolectricTestRunner::class)+class SettingsPageTest {++    @get:Rule+    val rule = createComposeRule()++    @Test+    fun `toggle slider choice stepper info and action render and report`() {+        var toggled = false+        var slid = 0f+        var chosen = "A"+        var stepped = 2+        var actioned = 0+        rule.setContent {+            SettingsPage(title = "SettingsPageTest", onNavigateBack = {}) {+                Section("General", description = "general description") {+                    Toggle("Dark mode", "this is the description", checked = false, onCheckedChange = { toggled = it })+                    Slider("Volume", "volume description", value = 0.5f, onValueChange = { slid = it }, valueLabel = "50%")+                    Choice("Theme", "theme description", selected = chosen, options = listOf("A", "B"), label = { it }, onSelect = { chosen = it })+                    Stepper("Count", "count description", value = stepped, onValueChange = { stepped = it }, range = 0..5)+                    ColorChoice("Accent", "accent description", selected = Color.Red, options = listOf(Color.Red, Color.Blue), onSelect = {})+                    Info("Version", value = "1.0")+                    Action("Open units", "units description", onClick = { actioned++ })+                }+            }+        }+        rule.onNodeWithText("Dark mode").assertIsDisplayed()+        rule.onNodeWithText("this is the description").assertIsDisplayed()+        rule.onNodeWithText("Volume").assertIsDisplayed()+        rule.onNodeWithText("Theme").assertIsDisplayed()+        rule.onNodeWithText("Count").performScrollTo().assertIsDisplayed()+        rule.onNodeWithText("Version").performScrollTo().assertIsDisplayed()+        rule.onNodeWithText("1.0").performScrollTo().assertIsDisplayed()+        rule.onNodeWithText("Open units").performScrollTo().performClick()+        assertEquals(1, actioned)+        // Unused-capture guards: the DSL wired every callback above.+        assertEquals(false, toggled)+        assertEquals(0f, slid)+        assertEquals("A", chosen)+        assertEquals(2, stepped)+    }+}