a bit of refactoring, moving code to update 'squares' vector in app-with.sml to its own function (to make it reuseable)

This commit is contained in:
2025-07-11 17:03:48 +01:00
parent c898d83d6e
commit 5cd909430d
2 changed files with 15 additions and 10 deletions

View File

@@ -2,6 +2,14 @@ structure AppWith =
struct
open AppType
fun updateSquares (squares, newX, newY, item) =
Vector.mapi
(fn (idx, el) =>
if idx = newX then
Vector.mapi (fn (iidx, iel) => if iidx = newY then item else iel) el
else
el) squares
fun addSquare (app, newX, newY, arrowX, arrowY) : app_type =
let
val
@@ -31,16 +39,13 @@ struct
, redo
} = app
val squares =
Vector.mapi
(fn (idx, el) =>
if idx = newX then
Vector.mapi
(fn (iidx, iel) =>
if iidx = newY then {r = r, g = g, b = b, a = a} else iel)
el
else
el) squares
val yAxis = Vector.sub (squares, newX)
val undoData = Vector.sub (yAxis, newY)
val undo = undoData :: undo
val redo = []
val item = {r = r, g = g, b = b, a = a}
val squares = updateSquares (squares, newX, newY, item)
in
{ mode = mode
, squares = squares