@@ -3,13 +3,23 @@ package com.jetpackduba.gitnuro.ui.components
33import androidx.compose.foundation.gestures.Orientation
44import androidx.compose.foundation.gestures.draggable
55import androidx.compose.foundation.gestures.rememberDraggableState
6- import androidx.compose.foundation.layout.*
7- import androidx.compose.runtime.Composable
6+ import androidx.compose.foundation.hoverable
7+ import androidx.compose.foundation.interaction.MutableInteractionSource
8+ import androidx.compose.foundation.interaction.collectIsHoveredAsState
9+ import androidx.compose.foundation.layout.Box
10+ import androidx.compose.foundation.layout.Row
11+ import androidx.compose.foundation.layout.fillMaxHeight
12+ import androidx.compose.foundation.layout.width
13+ import androidx.compose.runtime.*
814import androidx.compose.ui.Modifier
915import androidx.compose.ui.input.pointer.pointerHoverIcon
16+ import androidx.compose.ui.layout.onSizeChanged
17+ import androidx.compose.ui.platform.LocalDensity
1018import androidx.compose.ui.unit.dp
1119import com.jetpackduba.gitnuro.ui.resizePointerIconEast
1220
21+ const val MAX_SIDE_PANE_PROPORTION = 0.4f
22+
1323@Composable
1424fun TripleVerticalSplitPanel (
1525 modifier : Modifier = Modifier ,
@@ -18,18 +28,35 @@ fun TripleVerticalSplitPanel(
1828 third : @Composable () -> Unit ,
1929 firstWidth : Float ,
2030 thirdWidth : Float ,
21- onFirstSizeDrag : (Float ) -> Unit ,
22- onFirstSizeDragStopped : (Float ) -> Unit ,
23- onThirdSizeDrag : (Float ) -> Unit ,
24- onThirdSizeDragStopped : (Float ) -> Unit ,
31+ onFirstSizeDragStarted : (Float ) -> Unit ,
32+ onFirstSizeChange : (Float ) -> Unit ,
33+ onFirstSizeDragStopped : () -> Unit ,
34+ onThirdSizeDragStarted : (Float ) -> Unit ,
35+ onThirdSizeChange : (Float ) -> Unit ,
36+ onThirdSizeDragStopped : () -> Unit ,
2537) {
38+ val density = LocalDensity .current.density
39+ var screenWidth by remember { mutableStateOf(0 ) }
40+ val screenWidthInDp = remember(screenWidth) { (screenWidth / density) }
41+
42+ val firstWidthLimited = remember(firstWidth, screenWidthInDp) {
43+ calcLimitedWidth(screenWidthInDp, firstWidth)
44+ }
45+
46+ val thirdWidthLimited = remember(thirdWidth, screenWidthInDp) {
47+ calcLimitedWidth(screenWidthInDp, thirdWidth)
48+ }
49+
2650 Row (
2751 modifier = modifier
52+ .onSizeChanged {
53+ screenWidth = it.width
54+ }
2855 ) {
2956 if (firstWidth > 0 ) {
3057 Box (
3158 modifier = Modifier
32- .width(firstWidth .dp)
59+ .width(firstWidthLimited .dp)
3360 ) {
3461 first()
3562 }
@@ -39,11 +66,14 @@ fun TripleVerticalSplitPanel(
3966 .width(8 .dp)
4067 .draggable(
4168 state = rememberDraggableState {
42- onFirstSizeDrag (it)
69+ onFirstSizeChange (it)
4370 },
4471 orientation = Orientation .Horizontal ,
72+ onDragStarted = {
73+ onFirstSizeDragStarted(firstWidthLimited)
74+ },
4575 onDragStopped = {
46- onFirstSizeDragStopped(it )
76+ onFirstSizeDragStopped()
4777 },
4878 )
4979 .pointerHoverIcon(resizePointerIconEast)
@@ -63,21 +93,32 @@ fun TripleVerticalSplitPanel(
6393 .width(8 .dp)
6494 .draggable(
6595 state = rememberDraggableState {
66- onThirdSizeDrag (it)
96+ onThirdSizeChange (it)
6797 },
6898 orientation = Orientation .Horizontal ,
99+ onDragStarted = {
100+ onThirdSizeDragStarted(thirdWidthLimited)
101+ },
69102 onDragStopped = {
70- onThirdSizeDragStopped(it )
103+ onThirdSizeDragStopped()
71104 },
72105 )
73106 .pointerHoverIcon(resizePointerIconEast)
74107 )
75108
76109 Box (
77110 modifier = Modifier
78- .width(thirdWidth .dp)
111+ .width(thirdWidthLimited .dp)
79112 ) {
80113 third()
81114 }
82115 }
116+ }
117+
118+ private fun calcLimitedWidth (maxSize : Float , currentSize : Float ): Float {
119+ return if (currentSize > maxSize * MAX_SIDE_PANE_PROPORTION ) {
120+ maxSize * MAX_SIDE_PANE_PROPORTION
121+ } else {
122+ currentSize
123+ }
83124}
0 commit comments