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