|
|
|
@ -1,21 +1,22 @@
|
|
|
|
|
package org.jetbrains.compose.demo.widgets.ui |
|
|
|
|
|
|
|
|
|
import androidx.compose.animation.animate |
|
|
|
|
import androidx.compose.animation.core.Spring |
|
|
|
|
import androidx.compose.animation.core.SpringSpec |
|
|
|
|
import androidx.compose.animation.core.animateDpAsState |
|
|
|
|
import androidx.compose.foundation.clickable |
|
|
|
|
import androidx.compose.foundation.layout.* |
|
|
|
|
import androidx.compose.foundation.lazy.LazyColumnFor |
|
|
|
|
import androidx.compose.foundation.lazy.LazyColumn |
|
|
|
|
import androidx.compose.foundation.lazy.items |
|
|
|
|
import androidx.compose.foundation.lazy.rememberLazyListState |
|
|
|
|
import androidx.compose.material.AmbientContentColor |
|
|
|
|
import androidx.compose.foundation.text.selection.DisableSelection |
|
|
|
|
import androidx.compose.material.LocalContentColor |
|
|
|
|
import androidx.compose.material.Text |
|
|
|
|
import androidx.compose.runtime.* |
|
|
|
|
import androidx.compose.runtime.saveable.rememberSaveable |
|
|
|
|
import androidx.compose.ui.Alignment |
|
|
|
|
import androidx.compose.ui.Modifier |
|
|
|
|
import androidx.compose.ui.draw.clipToBounds |
|
|
|
|
import androidx.compose.ui.platform.AmbientDensity |
|
|
|
|
import androidx.compose.ui.selection.DisableSelection |
|
|
|
|
import androidx.compose.ui.platform.LocalDensity |
|
|
|
|
import androidx.compose.ui.text.style.TextOverflow |
|
|
|
|
import androidx.compose.ui.unit.Dp |
|
|
|
|
import androidx.compose.ui.unit.TextUnit |
|
|
|
@ -46,10 +47,10 @@ fun WidgetsPanel() {
|
|
|
|
|
val animatedSize = if (panelState.splitter.isResizing) { |
|
|
|
|
if (panelState.isExpanded) panelState.expandedSize else panelState.collapsedSize |
|
|
|
|
} else { |
|
|
|
|
animate( |
|
|
|
|
animateDpAsState( |
|
|
|
|
if (panelState.isExpanded) panelState.expandedSize else panelState.collapsedSize, |
|
|
|
|
SpringSpec(stiffness = Spring.StiffnessLow) |
|
|
|
|
) |
|
|
|
|
).value |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
VerticalSplittable( |
|
|
|
@ -82,24 +83,26 @@ fun WidgetsPanel() {
|
|
|
|
|
@Composable |
|
|
|
|
private fun WidgetsListView(widgetsTypeState: MutableState<WidgetsType>) { |
|
|
|
|
Box { |
|
|
|
|
with(AmbientDensity.current) { |
|
|
|
|
with(LocalDensity.current) { |
|
|
|
|
val scrollState = rememberLazyListState() |
|
|
|
|
|
|
|
|
|
val fontSize = 14.sp |
|
|
|
|
val lineHeight = fontSize.toDp() * 1.5f |
|
|
|
|
|
|
|
|
|
val items = WidgetsType.sortedValues |
|
|
|
|
LazyColumnFor( |
|
|
|
|
items, |
|
|
|
|
val sortedItems = WidgetsType.sortedValues |
|
|
|
|
LazyColumn( |
|
|
|
|
modifier = Modifier.fillMaxSize().withoutWidthConstraints(), |
|
|
|
|
state = scrollState, |
|
|
|
|
itemContent = { WidgetsListItemViewImpl(it, widgetsTypeState, fontSize, lineHeight) } |
|
|
|
|
) |
|
|
|
|
state = scrollState |
|
|
|
|
) { |
|
|
|
|
items(sortedItems) { |
|
|
|
|
WidgetsListItemViewImpl(it, widgetsTypeState, fontSize, lineHeight) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
VerticalScrollbar( |
|
|
|
|
Modifier.align(Alignment.CenterEnd), |
|
|
|
|
scrollState, |
|
|
|
|
items.size, |
|
|
|
|
sortedItems.size, |
|
|
|
|
lineHeight |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
@ -124,7 +127,7 @@ private fun WidgetsListItemViewImpl(
|
|
|
|
|
.padding(start = 16.dp) |
|
|
|
|
) { |
|
|
|
|
var inFocus by remember { mutableStateOf(false) } |
|
|
|
|
val textColor = AmbientContentColor.current.let { |
|
|
|
|
val textColor = LocalContentColor.current.let { |
|
|
|
|
when { |
|
|
|
|
isCurrent -> it |
|
|
|
|
inFocus -> it.copy(alpha = 0.6f) |
|
|
|
|