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