Skip to content

Commit 6dbd1ff

Browse files
committed
Fixed arrow positioning
- if modifier is set to unbounded, content also needs to be aligned.
1 parent f2ec953 commit 6dbd1ff

File tree

3 files changed

+10
-71
lines changed

3 files changed

+10
-71
lines changed

workflow-trace-viewer/src/jvmMain/kotlin/com/squareup/workflow1/traceviewer/Arrow.kt

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import androidx.compose.foundation.clickable
55
import androidx.compose.foundation.layout.Box
66
import androidx.compose.foundation.layout.fillMaxSize
77
import androidx.compose.foundation.layout.size
8-
import androidx.compose.material.Text
98
import androidx.compose.runtime.Composable
109
import androidx.compose.ui.Modifier
1110
import androidx.compose.ui.geometry.Offset
@@ -26,11 +25,13 @@ public fun Arrow(
2625
) {
2726
Box(
2827
modifier = Modifier
29-
.size(20.dp)
30-
.clickable { print("clicked") }
28+
.clickable { println("arrow clicked") }
3129
) {
32-
Text("top left corner")
33-
Canvas (modifier = Modifier.fillMaxSize()){
30+
Canvas(
31+
modifier = Modifier
32+
.fillMaxSize()
33+
.size(100.dp,100.dp)
34+
) {
3435
drawArrow(
3536
start = start,
3637
end = end,
@@ -41,24 +42,6 @@ public fun Arrow(
4142
}
4243
}
4344

44-
// iterative
45-
// @Composable
46-
// public fun drawAllArrows(
47-
// arrowLocations: List<Pair<NodePosition, NodePosition>>,
48-
// ) {
49-
// Canvas(modifier = Modifier.fillMaxSize()) {
50-
// arrowLocations.forEach { (start, end) ->
51-
// drawArrow(
52-
// start = start.position,
53-
// end = end.position,
54-
// color = Color.Black,
55-
// strokeWidth = 2f
56-
// )
57-
// }
58-
// }
59-
// }
60-
61-
6245
private fun DrawScope.drawArrow(
6346
start: Offset,
6447
end: Offset,

workflow-trace-viewer/src/jvmMain/kotlin/com/squareup/workflow1/traceviewer/SandboxBackground.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import androidx.compose.runtime.getValue
88
import androidx.compose.runtime.mutableStateOf
99
import androidx.compose.runtime.remember
1010
import androidx.compose.runtime.setValue
11+
import androidx.compose.ui.Alignment
1112
import androidx.compose.ui.Modifier
1213
import androidx.compose.ui.geometry.Offset
1314
import androidx.compose.ui.graphics.graphicsLayer
@@ -28,7 +29,7 @@ public fun SandboxBackground(content: @Composable () -> Unit) {
2829

2930
Box(
3031
modifier = Modifier
31-
.wrapContentSize(unbounded = true) // this allows the content to be larger than the initial screen of the app
32+
.wrapContentSize(unbounded = true, align = Alignment.TopStart) // this allows the content to be larger than the initial screen of the app
3233
.pointerInput(Unit) { // this allows for user's panning to view different parts of content
3334
awaitEachGesture {
3435
val event = awaitPointerEvent()

workflow-trace-viewer/src/jvmMain/kotlin/com/squareup/workflow1/traceviewer/WorkflowTree.kt

Lines changed: 2 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.squareup.workflow1.traceviewer
22

3+
import androidx.compose.foundation.background
34
import androidx.compose.foundation.border
45
import androidx.compose.foundation.clickable
56
import androidx.compose.foundation.layout.Arrangement
@@ -47,13 +48,11 @@ public fun DrawWorkflowTree(root: WorkflowNode) {
4748
val nodeCount = remember { mutableStateOf(0) }
4849
val nodeMapSize = remember { mutableStateOf(0)}
4950
val readyToDraw = remember { mutableStateOf(false) }
50-
// val allArrows = remember { mutableListOf<Pair<NodePosition, NodePosition>>() }
5151

5252
drawTree(root, nodePositions, nodeCount, nodeMapSize)
5353

5454
LaunchedEffect(nodeMapSize.value) {
5555
if (nodePositions.size == nodeCount.value) {
56-
// aggregateArrows(root, nodePositions, allArrows)
5756
readyToDraw.value = true
5857
}
5958
}
@@ -75,7 +74,7 @@ private fun drawTree(
7574
nodeMapSize: MutableState<Int>
7675
) {
7776
Column(
78-
modifier = Modifier.padding(20.dp).border(1.dp, Color.Black),
77+
modifier = Modifier.padding(10.dp),
7978
horizontalAlignment = Alignment.CenterHorizontally,
8079
) {
8180
drawNode(node, nodePositions, nodeMapSize)
@@ -105,12 +104,10 @@ private fun drawNode(
105104
nodeMapSize: MutableState<Int>
106105
) {
107106
val open = remember { mutableStateOf(false) }
108-
109107
Box (
110108
modifier = Modifier
111109
.border(1.dp, Color.Black)
112110
.clickable { open.value = !open.value }
113-
.padding(10.dp)
114111
.onGloballyPositioned {
115112
val coords = it.positionInRoot()
116113
nodePositions[node.id] = coords
@@ -146,45 +143,3 @@ private fun drawArrows(
146143
drawArrows(childNode, nodePositions)
147144
}
148145
}
149-
150-
// iterative
151-
// @Composable
152-
// private fun drawArrows(
153-
// arrowLocations: List<Pair<NodePosition, NodePosition>>,
154-
// ) {
155-
// drawAllArrows(arrowLocations)
156-
// }
157-
158-
//
159-
// /**
160-
// * Recurively adds all the arrows from each parent node to its children
161-
// *
162-
// */
163-
// private fun aggregateArrows(
164-
// node: WorkflowNode,
165-
// nodePositions: MutableMap<String, Offset>,
166-
// allArrows: MutableList<Pair<NodePosition, NodePosition>>
167-
// ){
168-
// for (childNode in node.children) {
169-
// val parent = NodePosition(
170-
// id = node.id,
171-
// position = nodePositions[node.id] ?: Offset.Zero
172-
// )
173-
// val child = NodePosition(
174-
// id = childNode.id,
175-
// position = nodePositions[childNode.id] ?: Offset.Zero
176-
// )
177-
// allArrows.add(Pair(parent, child))
178-
//
179-
// aggregateArrows(childNode, nodePositions, allArrows)
180-
// }
181-
// }
182-
//
183-
// /**
184-
// * provides structure for each arrow to be drawn. Also allows more data to be stored if we planned
185-
// * each arrow to be clickable and show more information about the data being passed
186-
// */
187-
// public data class NodePosition(
188-
// val id: String,
189-
// val position: Offset
190-
// )

0 commit comments

Comments
 (0)