diff --git a/README.md b/README.md index 8552d01..62e59fd 100644 --- a/README.md +++ b/README.md @@ -70,11 +70,12 @@ Built-in types of preferences include: - [`TwoTargetIconButtonPreference`](preference/src/commonMain/kotlin/TwoTargetIconButtonPreference.kt) - [`TwoTargetSwitchPreference`](preference/src/commonMain/kotlin/TwoTargetSwitchPreference.kt) -Each type of built-in preference includes 3 kinds of APIs: +Each type of built-in preference includes 4 kinds of APIs: 1. A `LazyListScope.*Preference` extension function, which is the easiest way to use preferences in this library, and helps developers to avoid boilerplates like having to specify the key twice for the `LazyColumn` and the `Preference`. -2. A `*Preference` composable that takes a `MutableState`, which allows developers to bring in any kind of state they currently have. -3. A `*Preference` composable that takes `value` and `onValueChange`, which allows developers to use the preference without a state and even in non-preference scenarios. +2. A `LazyListScope.*Preference` extension function, reloads the first one for `value` and `onValueChange` params. +3. A `*Preference` composable that takes a `MutableState`, which allows developers to bring in any kind of state they currently have. +4. A `*Preference` composable that takes `value` and `onValueChange`, which allows developers to use the preference without a state and even in non-preference scenarios. ### Theming diff --git a/preference/api/jvm/preference.api b/preference/api/jvm/preference.api index 3360349..0378496 100644 --- a/preference/api/jvm/preference.api +++ b/preference/api/jvm/preference.api @@ -7,7 +7,9 @@ public final class me/zhanghai/compose/preference/BasicPreferenceKt { public final class me/zhanghai/compose/preference/CheckboxPreferenceKt { public static final fun CheckboxPreference (Landroidx/compose/runtime/MutableState;Lkotlin/jvm/functions/Function2;Landroidx/compose/ui/Modifier;ZLkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Landroidx/compose/runtime/Composer;II)V public static final fun CheckboxPreference (ZLkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;Landroidx/compose/ui/Modifier;ZLkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Landroidx/compose/runtime/Composer;II)V + public static final fun checkboxPreference (Landroidx/compose/foundation/lazy/LazyListScope;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;Landroidx/compose/ui/Modifier;ZLkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)V public static final fun checkboxPreference (Landroidx/compose/foundation/lazy/LazyListScope;Ljava/lang/String;ZLkotlin/jvm/functions/Function3;Landroidx/compose/ui/Modifier;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;)V + public static synthetic fun checkboxPreference$default (Landroidx/compose/foundation/lazy/LazyListScope;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;Landroidx/compose/ui/Modifier;ZLkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)V public static synthetic fun checkboxPreference$default (Landroidx/compose/foundation/lazy/LazyListScope;Ljava/lang/String;ZLkotlin/jvm/functions/Function3;Landroidx/compose/ui/Modifier;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;ILjava/lang/Object;)V } @@ -63,7 +65,9 @@ public final class me/zhanghai/compose/preference/ListPreferenceKt { public static final fun ListPreference (Landroidx/compose/runtime/MutableState;Ljava/util/List;Lkotlin/jvm/functions/Function2;Landroidx/compose/ui/Modifier;ZLkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lme/zhanghai/compose/preference/ListPreferenceType;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function5;Landroidx/compose/runtime/Composer;II)V public static final fun ListPreference (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Ljava/util/List;Lkotlin/jvm/functions/Function2;Landroidx/compose/ui/Modifier;ZLkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lme/zhanghai/compose/preference/ListPreferenceType;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function5;Landroidx/compose/runtime/Composer;III)V public static final fun listPreference (Landroidx/compose/foundation/lazy/LazyListScope;Ljava/lang/String;Ljava/lang/Object;Ljava/util/List;Lkotlin/jvm/functions/Function3;Landroidx/compose/ui/Modifier;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lme/zhanghai/compose/preference/ListPreferenceType;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function5;)V + public static final fun listPreference (Landroidx/compose/foundation/lazy/LazyListScope;Ljava/lang/String;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Ljava/util/List;Lkotlin/jvm/functions/Function2;Landroidx/compose/ui/Modifier;ZLkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lme/zhanghai/compose/preference/ListPreferenceType;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function5;)V public static synthetic fun listPreference$default (Landroidx/compose/foundation/lazy/LazyListScope;Ljava/lang/String;Ljava/lang/Object;Ljava/util/List;Lkotlin/jvm/functions/Function3;Landroidx/compose/ui/Modifier;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lme/zhanghai/compose/preference/ListPreferenceType;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function5;ILjava/lang/Object;)V + public static synthetic fun listPreference$default (Landroidx/compose/foundation/lazy/LazyListScope;Ljava/lang/String;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Ljava/util/List;Lkotlin/jvm/functions/Function2;Landroidx/compose/ui/Modifier;ZLkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lme/zhanghai/compose/preference/ListPreferenceType;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function5;ILjava/lang/Object;)V } public final class me/zhanghai/compose/preference/ListPreferenceType : java/lang/Enum { @@ -94,7 +98,9 @@ public final class me/zhanghai/compose/preference/MultiSelectListPreferenceKt { public static final fun MultiSelectListPreference (Landroidx/compose/runtime/MutableState;Ljava/util/List;Lkotlin/jvm/functions/Function2;Landroidx/compose/ui/Modifier;ZLkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function5;Landroidx/compose/runtime/Composer;II)V public static final fun MultiSelectListPreference (Ljava/util/Set;Lkotlin/jvm/functions/Function1;Ljava/util/List;Lkotlin/jvm/functions/Function2;Landroidx/compose/ui/Modifier;ZLkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function5;Landroidx/compose/runtime/Composer;II)V public static final fun multiSelectListPreference (Landroidx/compose/foundation/lazy/LazyListScope;Ljava/lang/String;Ljava/util/Set;Ljava/util/List;Lkotlin/jvm/functions/Function3;Landroidx/compose/ui/Modifier;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function5;)V + public static final fun multiSelectListPreference (Landroidx/compose/foundation/lazy/LazyListScope;Ljava/lang/String;Ljava/util/Set;Lkotlin/jvm/functions/Function1;Ljava/util/List;Lkotlin/jvm/functions/Function2;Landroidx/compose/ui/Modifier;ZLkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function5;)V public static synthetic fun multiSelectListPreference$default (Landroidx/compose/foundation/lazy/LazyListScope;Ljava/lang/String;Ljava/util/Set;Ljava/util/List;Lkotlin/jvm/functions/Function3;Landroidx/compose/ui/Modifier;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function5;ILjava/lang/Object;)V + public static synthetic fun multiSelectListPreference$default (Landroidx/compose/foundation/lazy/LazyListScope;Ljava/lang/String;Ljava/util/Set;Lkotlin/jvm/functions/Function1;Ljava/util/List;Lkotlin/jvm/functions/Function2;Landroidx/compose/ui/Modifier;ZLkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function5;ILjava/lang/Object;)V } public final class me/zhanghai/compose/preference/MutableMapPreferences : me/zhanghai/compose/preference/MutablePreferences { @@ -187,14 +193,18 @@ public final class me/zhanghai/compose/preference/RadioButtonPreferenceKt { public final class me/zhanghai/compose/preference/SliderPreferenceKt { public static final fun SliderPreference (FLkotlin/jvm/functions/Function1;FLkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;Landroidx/compose/ui/Modifier;Lkotlin/ranges/ClosedFloatingPointRange;IZLkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Landroidx/compose/runtime/Composer;III)V public static final fun SliderPreference (Landroidx/compose/runtime/MutableState;Lkotlin/jvm/functions/Function2;Landroidx/compose/ui/Modifier;Lkotlin/ranges/ClosedFloatingPointRange;ILandroidx/compose/runtime/MutableFloatState;ZLkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Landroidx/compose/runtime/Composer;II)V + public static final fun sliderPreference (Landroidx/compose/foundation/lazy/LazyListScope;Ljava/lang/String;FLkotlin/jvm/functions/Function1;FLkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;Landroidx/compose/ui/Modifier;Lkotlin/ranges/ClosedFloatingPointRange;IZLkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)V public static final fun sliderPreference (Landroidx/compose/foundation/lazy/LazyListScope;Ljava/lang/String;FLkotlin/jvm/functions/Function3;Landroidx/compose/ui/Modifier;Lkotlin/jvm/functions/Function2;Lkotlin/ranges/ClosedFloatingPointRange;ILkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;)V + public static synthetic fun sliderPreference$default (Landroidx/compose/foundation/lazy/LazyListScope;Ljava/lang/String;FLkotlin/jvm/functions/Function1;FLkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;Landroidx/compose/ui/Modifier;Lkotlin/ranges/ClosedFloatingPointRange;IZLkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)V public static synthetic fun sliderPreference$default (Landroidx/compose/foundation/lazy/LazyListScope;Ljava/lang/String;FLkotlin/jvm/functions/Function3;Landroidx/compose/ui/Modifier;Lkotlin/jvm/functions/Function2;Lkotlin/ranges/ClosedFloatingPointRange;ILkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;ILjava/lang/Object;)V } public final class me/zhanghai/compose/preference/SwitchPreferenceKt { public static final fun SwitchPreference (Landroidx/compose/runtime/MutableState;Lkotlin/jvm/functions/Function2;Landroidx/compose/ui/Modifier;ZLkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Landroidx/compose/runtime/Composer;II)V public static final fun SwitchPreference (ZLkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;Landroidx/compose/ui/Modifier;ZLkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Landroidx/compose/runtime/Composer;II)V + public static final fun switchPreference (Landroidx/compose/foundation/lazy/LazyListScope;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;Landroidx/compose/ui/Modifier;ZLkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)V public static final fun switchPreference (Landroidx/compose/foundation/lazy/LazyListScope;Ljava/lang/String;ZLkotlin/jvm/functions/Function3;Landroidx/compose/ui/Modifier;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;)V + public static synthetic fun switchPreference$default (Landroidx/compose/foundation/lazy/LazyListScope;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;Landroidx/compose/ui/Modifier;ZLkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)V public static synthetic fun switchPreference$default (Landroidx/compose/foundation/lazy/LazyListScope;Ljava/lang/String;ZLkotlin/jvm/functions/Function3;Landroidx/compose/ui/Modifier;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;ILjava/lang/Object;)V } @@ -207,7 +217,9 @@ public final class me/zhanghai/compose/preference/TextFieldPreferenceDefaults { public final class me/zhanghai/compose/preference/TextFieldPreferenceKt { public static final fun TextFieldPreference (Landroidx/compose/runtime/MutableState;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;Landroidx/compose/ui/Modifier;ZLkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function5;Landroidx/compose/runtime/Composer;II)V public static final fun TextFieldPreference (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;Landroidx/compose/ui/Modifier;ZLkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function5;Landroidx/compose/runtime/Composer;II)V + public static final fun textFieldPreference (Landroidx/compose/foundation/lazy/LazyListScope;Ljava/lang/String;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;Landroidx/compose/ui/Modifier;ZLkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function5;)V public static final fun textFieldPreference (Landroidx/compose/foundation/lazy/LazyListScope;Ljava/lang/String;Ljava/lang/Object;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function1;Landroidx/compose/ui/Modifier;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function5;)V + public static synthetic fun textFieldPreference$default (Landroidx/compose/foundation/lazy/LazyListScope;Ljava/lang/String;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;Landroidx/compose/ui/Modifier;ZLkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function5;ILjava/lang/Object;)V public static synthetic fun textFieldPreference$default (Landroidx/compose/foundation/lazy/LazyListScope;Ljava/lang/String;Ljava/lang/Object;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function1;Landroidx/compose/ui/Modifier;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function5;ILjava/lang/Object;)V } @@ -226,7 +238,9 @@ public final class me/zhanghai/compose/preference/TwoTargetPreferenceKt { public final class me/zhanghai/compose/preference/TwoTargetSwitchPreferenceKt { public static final fun TwoTargetSwitchPreference (Landroidx/compose/runtime/MutableState;Lkotlin/jvm/functions/Function2;Landroidx/compose/ui/Modifier;ZLkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;ZLkotlin/jvm/functions/Function0;Landroidx/compose/runtime/Composer;II)V public static final fun TwoTargetSwitchPreference (ZLkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;Landroidx/compose/ui/Modifier;ZLkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;ZLkotlin/jvm/functions/Function0;Landroidx/compose/runtime/Composer;II)V + public static final fun twoTargetSwitchPreference (Landroidx/compose/foundation/lazy/LazyListScope;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;Landroidx/compose/ui/Modifier;ZLkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;ZLkotlin/jvm/functions/Function0;)V public static final fun twoTargetSwitchPreference (Landroidx/compose/foundation/lazy/LazyListScope;Ljava/lang/String;ZLkotlin/jvm/functions/Function3;Landroidx/compose/ui/Modifier;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)V + public static synthetic fun twoTargetSwitchPreference$default (Landroidx/compose/foundation/lazy/LazyListScope;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;Landroidx/compose/ui/Modifier;ZLkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;ZLkotlin/jvm/functions/Function0;ILjava/lang/Object;)V public static synthetic fun twoTargetSwitchPreference$default (Landroidx/compose/foundation/lazy/LazyListScope;Ljava/lang/String;ZLkotlin/jvm/functions/Function3;Landroidx/compose/ui/Modifier;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)V } diff --git a/preference/src/commonMain/kotlin/CheckboxPreference.kt b/preference/src/commonMain/kotlin/CheckboxPreference.kt index 38a0977..2e96384 100644 --- a/preference/src/commonMain/kotlin/CheckboxPreference.kt +++ b/preference/src/commonMain/kotlin/CheckboxPreference.kt @@ -54,6 +54,30 @@ public inline fun LazyListScope.checkboxPreference( } } +@Suppress("NOTHING_TO_INLINE") +public inline fun LazyListScope.checkboxPreference( + key: String, + value: Boolean, + noinline onValueChange: (Boolean) -> Unit, + noinline title: @Composable () -> Unit, + modifier: Modifier = Modifier, + enabled: Boolean = true, + noinline icon: @Composable (() -> Unit)? = null, + noinline summary: @Composable (() -> Unit)? = null, +) { + item(key = key, contentType = "CheckboxPreference") { + CheckboxPreference( + value = value, + onValueChange = onValueChange, + title = title, + modifier = modifier, + enabled = enabled, + icon = icon, + summary = summary, + ) + } +} + @Composable public fun CheckboxPreference( state: MutableState, diff --git a/preference/src/commonMain/kotlin/ListPreference.kt b/preference/src/commonMain/kotlin/ListPreference.kt index 3fc3d50..638c894 100644 --- a/preference/src/commonMain/kotlin/ListPreference.kt +++ b/preference/src/commonMain/kotlin/ListPreference.kt @@ -91,6 +91,39 @@ public inline fun LazyListScope.listPreference( } } +@Suppress("NOTHING_TO_INLINE") +public inline fun LazyListScope.listPreference( + key: String, + value: T, + noinline onValueChange: (T) -> Unit, + values: List, + noinline title: @Composable () -> Unit, + modifier: Modifier = Modifier, + enabled: Boolean = true, + noinline icon: @Composable (() -> Unit)? = null, + noinline summary: @Composable (() -> Unit)? = null, + type: ListPreferenceType = ListPreferenceType.ALERT_DIALOG, + noinline valueToText: @Composable (T) -> AnnotatedString = { AnnotatedString(it.toString()) }, + noinline item: @Composable (value: T, currentValue: T, onClick: () -> Unit) -> Unit = + ListPreferenceDefaults.item(type, valueToText), +) { + item(key = key, contentType = "ListPreference") { + ListPreference( + value = value, + onValueChange = onValueChange, + values = values, + title = title, + modifier = modifier, + enabled = enabled, + icon = icon, + summary = summary, + type = type, + valueToText = valueToText, + item = item, + ) + } +} + @Composable public fun ListPreference( state: MutableState, diff --git a/preference/src/commonMain/kotlin/MultiSelectListPreference.kt b/preference/src/commonMain/kotlin/MultiSelectListPreference.kt index 1a655d0..3588c4a 100644 --- a/preference/src/commonMain/kotlin/MultiSelectListPreference.kt +++ b/preference/src/commonMain/kotlin/MultiSelectListPreference.kt @@ -82,6 +82,37 @@ public inline fun LazyListScope.multiSelectListPreference( } } +@Suppress("NOTHING_TO_INLINE") +public inline fun LazyListScope.multiSelectListPreference( + key: String, + value: Set, + noinline onValueChange: (Set) -> Unit, + values: List, + noinline title: @Composable () -> Unit, + modifier: Modifier = Modifier, + enabled: Boolean = true, + noinline icon: @Composable (() -> Unit)? = null, + noinline summary: @Composable (() -> Unit)? = null, + noinline valueToText: @Composable (T) -> AnnotatedString = { AnnotatedString(it.toString()) }, + noinline item: @Composable (value: T, currentValues: Set, onToggle: (Boolean) -> Unit) -> Unit = + MultiSelectListPreferenceDefaults.item(valueToText), +) { + item(key = key, contentType = "MultiSelectListPreference") { + MultiSelectListPreference( + value = value, + onValueChange = onValueChange, + values = values, + title = title, + modifier = modifier, + enabled = enabled, + icon = icon, + summary = summary, + valueToText = valueToText, + item = item, + ) + } +} + @Composable public fun MultiSelectListPreference( state: MutableState>, diff --git a/preference/src/commonMain/kotlin/SliderPreference.kt b/preference/src/commonMain/kotlin/SliderPreference.kt index 3c001b8..212b3e8 100644 --- a/preference/src/commonMain/kotlin/SliderPreference.kt +++ b/preference/src/commonMain/kotlin/SliderPreference.kt @@ -72,6 +72,40 @@ public inline fun LazyListScope.sliderPreference( } } +@Suppress("NOTHING_TO_INLINE") +public inline fun LazyListScope.sliderPreference( + key: String, + value: Float, + noinline onValueChange: (Float) -> Unit, + sliderValue: Float, + noinline onSliderValueChange: (Float) -> Unit, + noinline title: @Composable () -> Unit, + modifier: Modifier = Modifier, + valueRange: ClosedFloatingPointRange = 0f..1f, + valueSteps: Int = 0, + enabled: Boolean = true, + noinline icon: @Composable (() -> Unit)? = null, + noinline summary: @Composable (() -> Unit)? = null, + noinline valueText: @Composable (() -> Unit)? = null, +) { + item(key = key, contentType = "SliderPreference") { + SliderPreference( + value = value, + onValueChange = onValueChange, + sliderValue = sliderValue, + onSliderValueChange = onSliderValueChange, + title = title, + modifier = modifier, + valueRange = valueRange, + valueSteps = valueSteps, + enabled = enabled, + icon = icon, + summary = summary, + valueText = valueText, + ) + } +} + @Composable public fun SliderPreference( state: MutableState, diff --git a/preference/src/commonMain/kotlin/SwitchPreference.kt b/preference/src/commonMain/kotlin/SwitchPreference.kt index 1a654dd..bc4d5ff 100644 --- a/preference/src/commonMain/kotlin/SwitchPreference.kt +++ b/preference/src/commonMain/kotlin/SwitchPreference.kt @@ -54,6 +54,30 @@ public inline fun LazyListScope.switchPreference( } } +@Suppress("NOTHING_TO_INLINE") +public inline fun LazyListScope.switchPreference( + key: String, + value: Boolean, + noinline onValueChange: (Boolean) -> Unit, + noinline title: @Composable () -> Unit, + modifier: Modifier = Modifier, + enabled: Boolean = true, + noinline icon: @Composable (() -> Unit)? = null, + noinline summary: @Composable (() -> Unit)? = null, +) { + item(key = key, contentType = "SwitchPreference") { + SwitchPreference( + value = value, + onValueChange = onValueChange, + title = title, + modifier = modifier, + enabled = enabled, + icon = icon, + summary = summary, + ) + } +} + @Composable public fun SwitchPreference( state: MutableState, diff --git a/preference/src/commonMain/kotlin/TextFieldPreference.kt b/preference/src/commonMain/kotlin/TextFieldPreference.kt index 11011ea..a19c7fe 100644 --- a/preference/src/commonMain/kotlin/TextFieldPreference.kt +++ b/preference/src/commonMain/kotlin/TextFieldPreference.kt @@ -78,6 +78,39 @@ public inline fun LazyListScope.textFieldPreference( } } +@Suppress("NOTHING_TO_INLINE") +public inline fun LazyListScope.textFieldPreference( + key: String, + value: T, + noinline onValueChange: (T) -> Unit, + noinline title: @Composable () -> Unit, + noinline textToValue: (String) -> T?, + modifier: Modifier = Modifier, + enabled: Boolean = true, + noinline icon: @Composable (() -> Unit)? = null, + noinline summary: @Composable (() -> Unit)? = null, + noinline valueToText: (T) -> String = { it.toString() }, + noinline textField: + @Composable + (value: TextFieldValue, onValueChange: (TextFieldValue) -> Unit, onOk: () -> Unit) -> Unit = + TextFieldPreferenceDefaults.TextField, +) { + item(key = key, contentType = "TextFieldPreference") { + TextFieldPreference( + value = value, + onValueChange = onValueChange, + title = title, + textToValue = textToValue, + modifier = modifier, + enabled = enabled, + icon = icon, + summary = summary, + valueToText = valueToText, + textField = textField, + ) + } +} + @Composable public fun TextFieldPreference( state: MutableState, diff --git a/preference/src/commonMain/kotlin/TwoTargetSwitchPreference.kt b/preference/src/commonMain/kotlin/TwoTargetSwitchPreference.kt index db48f62..f6005f3 100644 --- a/preference/src/commonMain/kotlin/TwoTargetSwitchPreference.kt +++ b/preference/src/commonMain/kotlin/TwoTargetSwitchPreference.kt @@ -57,6 +57,34 @@ public inline fun LazyListScope.twoTargetSwitchPreference( } } +@Suppress("NOTHING_TO_INLINE") +public inline fun LazyListScope.twoTargetSwitchPreference( + key: String, + value: Boolean, + noinline onValueChange: (Boolean) -> Unit, + noinline title: @Composable () -> Unit, + modifier: Modifier = Modifier, + enabled: Boolean = true, + noinline icon: @Composable (() -> Unit)? = null, + noinline summary: @Composable (() -> Unit)? = null, + switchEnabled: Boolean = enabled, + noinline onClick: (() -> Unit)? = null, +) { + item(key = key, contentType = "TwoTargetSwitchPreference") { + TwoTargetSwitchPreference( + value = value, + onValueChange = onValueChange, + title = title, + modifier = modifier, + enabled = enabled, + icon = icon, + summary = summary, + switchEnabled = switchEnabled, + onClick = onClick, + ) + } +} + @Composable public fun TwoTargetSwitchPreference( state: MutableState,