Skip to content

Commit 2e0b4c1

Browse files
committed
Added width limit to side panes
1 parent 5c5a102 commit 2e0b4c1

File tree

2 files changed

+63
-14
lines changed

2 files changed

+63
-14
lines changed

src/main/kotlin/com/jetpackduba/gitnuro/ui/RepositoryOpen.kt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,11 @@ fun MainContentView(
398398
}
399399
}
400400
},
401-
onFirstSizeDrag = {
401+
onFirstSizeDragStarted = { currentWidth ->
402+
firstWidth = currentWidth
403+
tabViewModel.setFirstPaneWidth(currentWidth)
404+
},
405+
onFirstSizeChange = {
402406
val newWidth = firstWidth + it / density
403407

404408
if (newWidth > 150 && rebaseInteractiveState !is RebaseInteractiveState.AwaitingInteraction) {
@@ -411,14 +415,18 @@ fun MainContentView(
411415
tabViewModel.persistFirstPaneWidth()
412416
}
413417
},
414-
onThirdSizeDrag = {
418+
onThirdSizeChange = {
415419
val newWidth = thirdWidth - it / density
416420

417421
if (newWidth > 150) {
418422
thirdWidth = newWidth
419423
tabViewModel.setThirdPaneWidth(newWidth)
420424
}
421425
},
426+
onThirdSizeDragStarted = { currentWidth ->
427+
thirdWidth = currentWidth
428+
tabViewModel.setThirdPaneWidth(currentWidth)
429+
},
422430
onThirdSizeDragStopped = {
423431
scope.launch {
424432
tabViewModel.persistThirdPaneWidth()

src/main/kotlin/com/jetpackduba/gitnuro/ui/components/TripleVerticalSplitPanel.kt

Lines changed: 53 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,23 @@ package com.jetpackduba.gitnuro.ui.components
33
import androidx.compose.foundation.gestures.Orientation
44
import androidx.compose.foundation.gestures.draggable
55
import 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.*
814
import androidx.compose.ui.Modifier
915
import androidx.compose.ui.input.pointer.pointerHoverIcon
16+
import androidx.compose.ui.layout.onSizeChanged
17+
import androidx.compose.ui.platform.LocalDensity
1018
import androidx.compose.ui.unit.dp
1119
import com.jetpackduba.gitnuro.ui.resizePointerIconEast
1220

21+
const val MAX_SIDE_PANE_PROPORTION = 0.4f
22+
1323
@Composable
1424
fun 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

Comments
 (0)