From 11052e801f611b01a73aa928fd747dbb7a6df6c9 Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Sun, 6 Jul 2025 14:08:44 +0100 Subject: [PATCH] port function to handlw window resizing event --- temp-squares/fcore/app-update.sml | 59 +++++++++++++++++++------------ 1 file changed, 37 insertions(+), 22 deletions(-) diff --git a/temp-squares/fcore/app-update.sml b/temp-squares/fcore/app-update.sml index b0391ce..5036644 100644 --- a/temp-squares/fcore/app-update.sml +++ b/temp-squares/fcore/app-update.sml @@ -14,29 +14,21 @@ struct val ypos = Vector.sub (yClickPoints, vIdx) val endXpos = - if hIdx + 1 = Vector.length xClickPoints then - xpos - else - Vector.sub (xClickPoints, hIdx + 1) + if hIdx + 1 = Vector.length xClickPoints then xpos + else Vector.sub (xClickPoints, hIdx + 1) val endYpos = - if vIdx + 1 = Vector.length yClickPoints then - ypos - else - Vector.sub (yClickPoints, vIdx + 1) + if vIdx + 1 = Vector.length yClickPoints then ypos + else Vector.sub (yClickPoints, vIdx + 1) - val tl = - ClickPoints.getDrawDotRgb - (xpos, ypos, 0.0, 0.0, 1.0, windowWidth, windowHeight) - val tr = - ClickPoints.getDrawDotRgb - (endXpos, ypos, 0.0, 0.0, 1.0, windowWidth, windowHeight) - val bl = - ClickPoints.getDrawDotRgb - (xpos, endYpos, 0.0, 0.0, 1.0, windowWidth, windowHeight) - val br = - ClickPoints.getDrawDotRgb - (endXpos, endYpos, 0.0, 0.0, 1.0, windowWidth, windowHeight) + val tl = ClickPoints.getDrawDotRgb + (xpos, ypos, 0.0, 0.0, 1.0, windowWidth, windowHeight) + val tr = ClickPoints.getDrawDotRgb + (endXpos, ypos, 0.0, 0.0, 1.0, windowWidth, windowHeight) + val bl = ClickPoints.getDrawDotRgb + (xpos, endYpos, 0.0, 0.0, 1.0, windowWidth, windowHeight) + val br = ClickPoints.getDrawDotRgb + (endXpos, endYpos, 0.0, 0.0, 1.0, windowWidth, windowHeight) in Vector.concat [tl, tr, bl, br] end @@ -157,7 +149,8 @@ struct val xpos = Vector.sub (xClickPoints, hIdx) val ypos = Vector.sub (yClickPoints, vIdx) - val model = AppWith.addSquare (model, realToInt xpos, realToInt ypos, hIdx, vIdx) + val model = AppWith.addSquare + (model, realToInt xpos, realToInt ypos, hIdx, vIdx) val squares = #squares model val dotVec = getDotVecFromIndices (model, hIdx, vIdx) @@ -166,7 +159,7 @@ struct val halfHeight = Real32.fromInt (windowHeight div 2) val maxSide = Int.max (canvasWidth, canvasHeight) - val squares = + val squares = CollisionTree.toTriangles (windowWidth, windowHeight, squares, maxSide) val drawMsg = DRAW_SQUARES_AND_DOTS {squares = squares, dots = dotVec} in @@ -183,4 +176,26 @@ struct in addCoordinates (model, arrowX, arrowY) end + fun resizeWindow (model, width, height) = + let + val model = AppWith.windowResize (model, width, height) + + val {squares, canvasWidth, canvasHeight, showGraph, arrowX, arrowY, ...} = + model + val maxSide = Int.max (canvasWidth, canvasHeight) + + val squares = CollisionTree.toTriangles (width, height, squares, maxSide) + + val graphLines = + if showGraph then GraphLines.generate model else Vector.fromList [] + + val dots = getDotVecFromIndices (model, arrowX, arrowY) + + val drawMsg = + RESIZE_SQUARES_DOTS_AND_GRAPH + {squares = squares, graphLines = graphLines, dots = dots} + val drawMsg = [DRAW drawMsg] + in + (model, drawMsg) + end end