done implementing load-squares functionality

This commit is contained in:
2025-07-12 07:17:52 +01:00
parent dcf6bc074d
commit b58100ca7e
5 changed files with 83 additions and 12 deletions

BIN
dotscape

Binary file not shown.

View File

@@ -1011,7 +1011,65 @@ struct
} }
end end
(* todo: fun useSquares (app: app_type, squares, canvasWidth, canvasHeight) =
fun useSquaresAndSetNormalMode (app: app_type, squares, canvasWidth, canvasHeight) = let
*) val
{ mode
, canvasHeight = _
, canvasWidth = _
, squares = _
, arrowX
, arrowY
, windowWidth
, windowHeight
, xClickPoints
, yClickPoints
, showGraph
, mouseX
, mouseY
, openFilePath
, fileBrowser
, fileBrowserIdx
, r
, g
, b
, a
, modalNum
, undo
, redo
} = app
val arrowX = Int.min (arrowX, canvasWidth)
val arrowY = Int.min (arrowY, canvasHeight)
val (xClickPoints, yClickPoints) =
ClickPoints.generate
(windowWidth, windowHeight, canvasWidth, canvasHeight)
in
{ mode = mode
, canvasHeight = canvasHeight
, canvasWidth = canvasWidth
, arrowX = arrowX
, mouseX = mouseX
, mouseY = mouseY
, squares = squares
, arrowY = arrowY
, windowWidth = windowWidth
, windowHeight = windowHeight
, xClickPoints = xClickPoints
, yClickPoints = yClickPoints
, showGraph = showGraph
, openFilePath = openFilePath
, fileBrowser = fileBrowser
, fileBrowserIdx = fileBrowserIdx
, r = r
, g = g
, b = b
, a = a
, modalNum = 0
, undo = undo
, redo = redo
}
end
end end

View File

@@ -265,9 +265,6 @@ struct
fun updateCanvas (model, canvasWidth, canvasHeight) = fun updateCanvas (model, canvasWidth, canvasHeight) =
let let
val newCanvaidth = #modalNum model
val model = AppWith.canvasWidth (model, canvasWidth)
val val
{ arrowX { arrowX
, arrowY , arrowY
@@ -308,6 +305,7 @@ struct
val newCanvasWidth = #modalNum model val newCanvasWidth = #modalNum model
val (model as {canvasWidth, canvasHeight, ...}) = val (model as {canvasWidth, canvasHeight, ...}) =
AppWith.canvasWidth (model, newCanvasWidth) AppWith.canvasWidth (model, newCanvasWidth)
val {canvasWidth, canvasHeight, ...} = model
in in
updateCanvas (model, canvasWidth, canvasHeight) updateCanvas (model, canvasWidth, canvasHeight)
end end
@@ -315,8 +313,15 @@ struct
fun updateCanvasHeight model = fun updateCanvasHeight model =
let let
val newCanvasHeight = #modalNum model val newCanvasHeight = #modalNum model
val (model as {canvasWidth, canvasHeight, ...}) = val model = AppWith.canvasHeight (model, newCanvasHeight)
AppWith.canvasHeight (model, newCanvasHeight) val {canvasWidth, canvasHeight, ...} = model
in
updateCanvas (model, canvasWidth, canvasHeight)
end
fun useSquares (model, squares, canvasWidth, canvasHeight) =
let
val model = AppWith.useSquares (model, squares, canvasWidth, canvasHeight)
in in
updateCanvas (model, canvasWidth, canvasHeight) updateCanvas (model, canvasWidth, canvasHeight)
end end
@@ -358,8 +363,8 @@ struct
| KEY_CTRL_S => CommonUpdate.getSaveSquaresMsg model | KEY_CTRL_S => CommonUpdate.getSaveSquaresMsg model
| KEY_CTRL_L => CommonUpdate.getLoadSquaresMsg model | KEY_CTRL_L => CommonUpdate.getLoadSquaresMsg model
| KEY_CTRL_E => CommonUpdate.getExportSquaresMsg model | KEY_CTRL_E => CommonUpdate.getExportSquaresMsg model
| USE_SQUARES squares => | USE_SQUARES {squares, canvasWidth, canvasHeight} =>
CommonUpdate.useSquaresInNormalMode (model, squares) useSquares (model, squares, canvasWidth, canvasHeight)
| SQUARES_LOAD_ERROR => CommonUpdate.squaresLoadError model | SQUARES_LOAD_ERROR => CommonUpdate.squaresLoadError model
| KEY_CTRL_O => enterBrowseMode model | KEY_CTRL_O => enterBrowseMode model
| ARROW_UP => moveArrowUp model | ARROW_UP => moveArrowUp model

View File

@@ -59,7 +59,12 @@ struct
val () = TextIO.closeIn io val () = TextIO.closeIn io
in in
case Parser.parse str of case Parser.parse str of
SOME (canvasWidth, canvasHeight, grid) => () SOME (canvasWidth, canvasHeight, grid) =>
Mailbox.send (inputMailbox, USE_SQUARES
{ squares = grid
, canvasWidth = canvasWidth
, canvasHeight = canvasHeight
})
| NONE => () | NONE => ()
end end

View File

@@ -27,7 +27,10 @@ struct
| KEY_ENTER | KEY_ENTER
| KEY_SPACE | KEY_SPACE
| USE_SQUARES of | USE_SQUARES of
{squares: int vector vector, canvasWidth: int, canvasHeight: int} { squares: {r: int, g: int, b: int, a: int} vector vector
, canvasWidth: int
, canvasHeight: int
}
| SQUARES_LOAD_ERROR | SQUARES_LOAD_ERROR
| FILE_BROWSER_AND_PATH of | FILE_BROWSER_AND_PATH of
{fileBrowser: AppType.file_browser_item vector, path: string} {fileBrowser: AppType.file_browser_item vector, path: string}