diff --git a/foundation/api/foundation.api b/foundation/api/foundation.api index d32349966..32a8f9c53 100644 --- a/foundation/api/foundation.api +++ b/foundation/api/foundation.api @@ -254,6 +254,10 @@ public final class org/jetbrains/jewel/foundation/code/highlighting/NoOpCodeHigh public fun highlight-C7ITchA (Ljava/lang/String;Ljava/lang/String;)Lkotlinx/coroutines/flow/Flow; } +public final class org/jetbrains/jewel/foundation/lazy/BasicSelectableLazyColumnKt { + public static final fun BasicSelectableLazyColumn (Landroidx/compose/ui/Modifier;Lorg/jetbrains/jewel/foundation/lazy/SelectionMode;Lorg/jetbrains/jewel/foundation/lazy/SelectableLazyListState;Landroidx/compose/foundation/layout/PaddingValues;ZLkotlin/jvm/functions/Function1;Landroidx/compose/foundation/layout/Arrangement$Vertical;Landroidx/compose/ui/Alignment$Horizontal;Landroidx/compose/foundation/gestures/FlingBehavior;Lorg/jetbrains/jewel/foundation/lazy/tree/KeyActions;Lorg/jetbrains/jewel/foundation/lazy/tree/PointerEventActions;Landroidx/compose/foundation/interaction/MutableInteractionSource;Lkotlin/jvm/functions/Function1;Landroidx/compose/runtime/Composer;III)V +} + public class org/jetbrains/jewel/foundation/lazy/DefaultMacOsSelectableColumnKeybindings : org/jetbrains/jewel/foundation/lazy/DefaultSelectableColumnKeybindings { public static final field $stable I public static final field Companion Lorg/jetbrains/jewel/foundation/lazy/DefaultMacOsSelectableColumnKeybindings$Companion; @@ -372,10 +376,6 @@ public final class org/jetbrains/jewel/foundation/lazy/SelectableColumnOnKeyEven public static fun onSelectPreviousItem (Lorg/jetbrains/jewel/foundation/lazy/SelectableColumnOnKeyEvent;Ljava/util/List;Lorg/jetbrains/jewel/foundation/lazy/SelectableLazyListState;)V } -public final class org/jetbrains/jewel/foundation/lazy/SelectableLazyColumnKt { - public static final fun SelectableLazyColumn (Landroidx/compose/ui/Modifier;Lorg/jetbrains/jewel/foundation/lazy/SelectionMode;Lorg/jetbrains/jewel/foundation/lazy/SelectableLazyListState;Landroidx/compose/foundation/layout/PaddingValues;ZLkotlin/jvm/functions/Function1;Landroidx/compose/foundation/layout/Arrangement$Vertical;Landroidx/compose/ui/Alignment$Horizontal;Landroidx/compose/foundation/gestures/FlingBehavior;Lorg/jetbrains/jewel/foundation/lazy/tree/KeyActions;Lorg/jetbrains/jewel/foundation/lazy/tree/PointerEventActions;Landroidx/compose/foundation/interaction/MutableInteractionSource;Lkotlin/jvm/functions/Function1;Landroidx/compose/runtime/Composer;III)V -} - public abstract interface class org/jetbrains/jewel/foundation/lazy/SelectableLazyItemScope : androidx/compose/foundation/lazy/LazyItemScope { public abstract fun isActive ()Z public abstract fun isSelected ()Z diff --git a/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/lazy/SelectableLazyColumn.kt b/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/lazy/BasicSelectableLazyColumn.kt similarity index 99% rename from foundation/src/main/kotlin/org/jetbrains/jewel/foundation/lazy/SelectableLazyColumn.kt rename to foundation/src/main/kotlin/org/jetbrains/jewel/foundation/lazy/BasicSelectableLazyColumn.kt index d3f4e74d5..e7419e888 100644 --- a/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/lazy/SelectableLazyColumn.kt +++ b/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/lazy/BasicSelectableLazyColumn.kt @@ -43,7 +43,7 @@ import org.jetbrains.jewel.foundation.lazy.tree.PointerEventActions /** A composable that displays a scrollable and selectable list of items in a column arrangement. */ @Composable -public fun SelectableLazyColumn( +public fun BasicSelectableLazyColumn( modifier: Modifier = Modifier, selectionMode: SelectionMode = SelectionMode.Multiple, state: SelectableLazyListState = rememberSelectableLazyListState(), diff --git a/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/lazy/tree/BasicLazyTree.kt b/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/lazy/tree/BasicLazyTree.kt index 28f81cc39..ff981a778 100644 --- a/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/lazy/tree/BasicLazyTree.kt +++ b/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/lazy/tree/BasicLazyTree.kt @@ -26,7 +26,7 @@ import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp import kotlin.time.Duration import kotlin.time.Duration.Companion.milliseconds -import org.jetbrains.jewel.foundation.lazy.SelectableLazyColumn +import org.jetbrains.jewel.foundation.lazy.BasicSelectableLazyColumn import org.jetbrains.jewel.foundation.lazy.SelectableLazyItemScope import org.jetbrains.jewel.foundation.lazy.SelectionMode import org.jetbrains.jewel.foundation.lazy.itemsIndexed @@ -109,7 +109,7 @@ public fun BasicLazyTree( ) } - SelectableLazyColumn( + BasicSelectableLazyColumn( modifier = modifier, state = treeState.delegate, selectionMode = selectionMode, diff --git a/foundation/src/test/kotlin/org/jetbrains/jewel/foundation/lazy/SelectableLazyColumnTest.kt b/foundation/src/test/kotlin/org/jetbrains/jewel/foundation/lazy/SelectableLazyColumnTest.kt index d48790a39..b6b2366ae 100644 --- a/foundation/src/test/kotlin/org/jetbrains/jewel/foundation/lazy/SelectableLazyColumnTest.kt +++ b/foundation/src/test/kotlin/org/jetbrains/jewel/foundation/lazy/SelectableLazyColumnTest.kt @@ -33,7 +33,7 @@ internal class SelectableLazyColumnTest { val scrollState = SelectableLazyListState(LazyListState()) composeRule.setContent { Box(modifier = Modifier.requiredHeight(100.dp)) { - SelectableLazyColumn(state = scrollState) { + BasicSelectableLazyColumn(state = scrollState) { items(items1.size, key = { items1[it] }) { val itemText = "Item ${items1[it]}" BasicText(itemText, modifier = Modifier.testTag(itemText)) @@ -59,7 +59,7 @@ internal class SelectableLazyColumnTest { val state = SelectableLazyListState(LazyListState()) composeRule.setContent { Box(modifier = Modifier.requiredHeight(300.dp)) { - SelectableLazyColumn(state = state, modifier = Modifier.testTag("list")) { + BasicSelectableLazyColumn(state = state, modifier = Modifier.testTag("list")) { items(items.size, key = { items[it] }) { val itemText = "Item ${items[it]}" BasicText(itemText, modifier = Modifier.testTag(itemText)) @@ -115,7 +115,7 @@ internal class SelectableLazyColumnTest { val state = SelectableLazyListState(LazyListState()) composeRule.setContent { Box(modifier = Modifier.requiredHeight(300.dp)) { - SelectableLazyColumn(state = state, modifier = Modifier.testTag("list")) { + BasicSelectableLazyColumn(state = state, modifier = Modifier.testTag("list")) { items(items.size, key = { items[it] }) { val itemText = "Item ${items[it]}" BasicText(itemText, modifier = Modifier.testTag(itemText)) @@ -179,7 +179,7 @@ internal class SelectableLazyColumnTest { val state = SelectableLazyListState(LazyListState()) composeRule.setContent { Box(modifier = Modifier.requiredHeight(300.dp)) { - SelectableLazyColumn(state = state, modifier = Modifier.testTag("list")) { + BasicSelectableLazyColumn(state = state, modifier = Modifier.testTag("list")) { items(items.size, key = { items[it] }) { val itemText = "Item ${items[it]}" BasicText(itemText, modifier = Modifier.testTag(itemText)) @@ -226,7 +226,7 @@ internal class SelectableLazyColumnTest { composeRule.setContent { Box(modifier = Modifier.requiredHeight(300.dp)) { val items = currentItems.value - SelectableLazyColumn(state = state, modifier = Modifier.testTag("list")) { + BasicSelectableLazyColumn(state = state, modifier = Modifier.testTag("list")) { items(items.size, key = { items[it] }) { val itemText = "Item ${items[it]}" BasicText(itemText, modifier = Modifier.testTag(itemText)) diff --git a/samples/ide-plugin/src/main/kotlin/org/jetbrains/jewel/samples/ideplugin/releasessample/ReleasesSampleCompose.kt b/samples/ide-plugin/src/main/kotlin/org/jetbrains/jewel/samples/ideplugin/releasessample/ReleasesSampleCompose.kt index eb63152ee..3432fb692 100644 --- a/samples/ide-plugin/src/main/kotlin/org/jetbrains/jewel/samples/ideplugin/releasessample/ReleasesSampleCompose.kt +++ b/samples/ide-plugin/src/main/kotlin/org/jetbrains/jewel/samples/ideplugin/releasessample/ReleasesSampleCompose.kt @@ -69,7 +69,6 @@ import org.jetbrains.jewel.bridge.medium import org.jetbrains.jewel.bridge.regular import org.jetbrains.jewel.bridge.retrieveColorOrUnspecified import org.jetbrains.jewel.bridge.toComposeColor -import org.jetbrains.jewel.foundation.lazy.SelectableLazyColumn import org.jetbrains.jewel.foundation.lazy.SelectionMode import org.jetbrains.jewel.foundation.lazy.items import org.jetbrains.jewel.foundation.lazy.rememberSelectableLazyListState @@ -79,6 +78,7 @@ import org.jetbrains.jewel.ui.component.HorizontalSplitLayout import org.jetbrains.jewel.ui.component.Icon import org.jetbrains.jewel.ui.component.IconButton import org.jetbrains.jewel.ui.component.PopupMenu +import org.jetbrains.jewel.ui.component.SelectableLazyColumn import org.jetbrains.jewel.ui.component.Text import org.jetbrains.jewel.ui.component.TextField import org.jetbrains.jewel.ui.component.Typography diff --git a/samples/standalone/src/main/kotlin/org/jetbrains/jewel/samples/standalone/view/component/ChipsAndTree.kt b/samples/standalone/src/main/kotlin/org/jetbrains/jewel/samples/standalone/view/component/ChipsAndTree.kt index 28666f988..b1a74064e 100644 --- a/samples/standalone/src/main/kotlin/org/jetbrains/jewel/samples/standalone/view/component/ChipsAndTree.kt +++ b/samples/standalone/src/main/kotlin/org/jetbrains/jewel/samples/standalone/view/component/ChipsAndTree.kt @@ -29,7 +29,6 @@ import androidx.compose.ui.unit.dp import kotlin.random.Random import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch -import org.jetbrains.jewel.foundation.lazy.SelectableLazyColumn import org.jetbrains.jewel.foundation.lazy.SelectionMode import org.jetbrains.jewel.foundation.lazy.rememberSelectableLazyListState import org.jetbrains.jewel.foundation.lazy.tree.buildTree @@ -41,6 +40,7 @@ import org.jetbrains.jewel.ui.component.GroupHeader import org.jetbrains.jewel.ui.component.LazyTree import org.jetbrains.jewel.ui.component.OutlinedButton import org.jetbrains.jewel.ui.component.RadioButtonChip +import org.jetbrains.jewel.ui.component.SelectableLazyColumn import org.jetbrains.jewel.ui.component.Text import org.jetbrains.jewel.ui.component.ToggleableChip import org.jetbrains.jewel.ui.theme.colorPalette diff --git a/ui/api/ui.api b/ui/api/ui.api index 5f3b9d687..dca803f2d 100644 --- a/ui/api/ui.api +++ b/ui/api/ui.api @@ -716,6 +716,10 @@ public final class org/jetbrains/jewel/ui/component/SelectableIconButtonState$Co public static synthetic fun of-z9lnavA$default (Lorg/jetbrains/jewel/ui/component/SelectableIconButtonState$Companion;ZZZZZZILjava/lang/Object;)J } +public final class org/jetbrains/jewel/ui/component/SelectableLazyColumnKt { + public static final fun SelectableLazyColumn (Landroidx/compose/ui/Modifier;Lorg/jetbrains/jewel/foundation/lazy/SelectionMode;Lorg/jetbrains/jewel/foundation/lazy/SelectableLazyListState;Landroidx/compose/foundation/layout/PaddingValues;ZLkotlin/jvm/functions/Function1;Landroidx/compose/foundation/layout/Arrangement$Vertical;Landroidx/compose/ui/Alignment$Horizontal;Landroidx/compose/foundation/gestures/FlingBehavior;Lorg/jetbrains/jewel/foundation/lazy/tree/KeyActions;Lorg/jetbrains/jewel/foundation/lazy/tree/PointerEventActions;Landroidx/compose/foundation/interaction/MutableInteractionSource;Lkotlin/jvm/functions/Function1;Landroidx/compose/runtime/Composer;III)V +} + public final class org/jetbrains/jewel/ui/component/SliderKt { public static final fun Slider (FLkotlin/jvm/functions/Function1;Landroidx/compose/ui/Modifier;ZLkotlin/ranges/ClosedFloatingPointRange;ILkotlin/jvm/functions/Function0;Landroidx/compose/foundation/interaction/MutableInteractionSource;Lorg/jetbrains/jewel/ui/component/styling/SliderStyle;Landroidx/compose/runtime/Composer;II)V } diff --git a/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/SelectableLazyColumn.kt b/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/SelectableLazyColumn.kt new file mode 100644 index 000000000..65f156484 --- /dev/null +++ b/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/SelectableLazyColumn.kt @@ -0,0 +1,55 @@ +package org.jetbrains.jewel.ui.component + +import androidx.compose.foundation.gestures.FlingBehavior +import androidx.compose.foundation.gestures.ScrollableDefaults +import androidx.compose.foundation.interaction.MutableInteractionSource +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.PaddingValues +import androidx.compose.runtime.Composable +import androidx.compose.runtime.remember +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.dp +import org.jetbrains.jewel.foundation.lazy.BasicSelectableLazyColumn +import org.jetbrains.jewel.foundation.lazy.SelectableLazyListScope +import org.jetbrains.jewel.foundation.lazy.SelectableLazyListState +import org.jetbrains.jewel.foundation.lazy.SelectionMode +import org.jetbrains.jewel.foundation.lazy.rememberSelectableLazyListState +import org.jetbrains.jewel.foundation.lazy.tree.DefaultSelectableLazyColumnEventAction +import org.jetbrains.jewel.foundation.lazy.tree.DefaultSelectableLazyColumnKeyActions +import org.jetbrains.jewel.foundation.lazy.tree.KeyActions +import org.jetbrains.jewel.foundation.lazy.tree.PointerEventActions + +@Composable +public fun SelectableLazyColumn( + modifier: Modifier = Modifier, + selectionMode: SelectionMode = SelectionMode.Multiple, + state: SelectableLazyListState = rememberSelectableLazyListState(), + contentPadding: PaddingValues = PaddingValues(0.dp), + reverseLayout: Boolean = false, + onSelectedIndexesChanged: (List) -> Unit = {}, + verticalArrangement: Arrangement.Vertical = if (!reverseLayout) Arrangement.Top else Arrangement.Bottom, + horizontalAlignment: Alignment.Horizontal = Alignment.Start, + flingBehavior: FlingBehavior = ScrollableDefaults.flingBehavior(), + keyActions: KeyActions = DefaultSelectableLazyColumnKeyActions, + pointerEventActions: PointerEventActions = DefaultSelectableLazyColumnEventAction(), + interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }, + // TODO: We will add support for styling in the near future + content: SelectableLazyListScope.() -> Unit, +) { + BasicSelectableLazyColumn( + modifier = modifier, + selectionMode = selectionMode, + state = state, + contentPadding = contentPadding, + reverseLayout = reverseLayout, + onSelectedIndexesChanged = onSelectedIndexesChanged, + verticalArrangement = verticalArrangement, + horizontalAlignment = horizontalAlignment, + flingBehavior = flingBehavior, + keyActions = keyActions, + pointerEventActions = pointerEventActions, + interactionSource = interactionSource, + content = content, + ) +}