add ability to move from normal mode to move mode, and from move mode back to normal mode

This commit is contained in:
2025-08-09 00:13:02 +01:00
parent 50bdd31d59
commit f46ca01d42
7 changed files with 38 additions and 9 deletions

View File

@@ -7,9 +7,6 @@ struct
(* todo: resize message, escape button to go back to normal mode *)
fun makeBlankYAxis length =
Vector.tabulate (length, fn _ => {r = 0, g = 0, b = 0, a = 0})
fun getDrawMsg (model: app_type) =
let
val
@@ -40,6 +37,9 @@ struct
(model, [DRAW drawMsg])
end
fun makeBlankYAxis length =
Vector.tabulate (length, fn _ => {r = 0, g = 0, b = 0, a = 0})
fun moveImageUp (model: app_type) =
let
val {squares, ...} = model
@@ -79,8 +79,10 @@ struct
val squares =
Vector.mapi
(fn (idx, yAxis) =>
if idx = 0 then makeBlankYAxis (Vector.length squares)
else Vector.sub (squares, idx - 1)) squares
if idx + 1 = Vector.length squares then
makeBlankYAxis (Vector.length squares)
else
Vector.sub (squares, idx + 1)) squares
val model = AppWith.squares (model, squares)
in
@@ -94,21 +96,25 @@ struct
val squares =
Vector.mapi
(fn (idx, yAxis) =>
if idx + 1 = Vector.length squares then
makeBlankYAxis (Vector.length squares)
else
Vector.sub (squares, idx + 1)) squares
if idx = 0 then makeBlankYAxis (Vector.length squares)
else Vector.sub (squares, idx - 1)) squares
val model = AppWith.squares (model, squares)
in
getDrawMsg model
end
fun enterNormalMode model =
let val model = AppWith.mode (model, AppType.NORMAL_MODE)
in (model, [])
end
fun update (model, inputMsg) =
case inputMsg of
ARROW_UP => moveImageUp model
| ARROW_DOWN => moveImageDown model
| ARROW_LEFT => moveImageLeft model
| ARROW_RIGHT => moveImageRight model
| KEY_ESC => enterNormalMode model
| _ => (model, [])
end