progress towards toggling graph

This commit is contained in:
2024-08-14 02:31:28 +01:00
parent 575b8d009e
commit 9b639c9c53
10 changed files with 83 additions and 4 deletions

View File

@@ -23,6 +23,7 @@ struct
, redo = []
, mouseX = 0.0
, mouseY = 0.0
, showGraph = true
}
end

View File

@@ -26,6 +26,7 @@ sig
, redo: (Real32.real * Real32.real) list
, mouseX: Real32.real
, mouseY: Real32.real
, showGraph: bool
}
end
@@ -65,5 +66,6 @@ struct
, redo: (Real32.real * Real32.real) list
, mouseX: Real32.real
, mouseY: Real32.real
, showGraph: bool
}
end

View File

@@ -174,7 +174,26 @@ struct
in
(model, drawMsg)
end)
| [] => (* Nothing to redo. *) (model, NO_DRAW)
| [] =>
(* Nothing to redo. *)
(model, NO_DRAW)
fun toggleGraph (model: app_type) =
if #showGraph model then
let
val model = AppWith.graphVisibility (model, false)
val drawMsg = DRAW_GRAPH (Vector.fromList [])
in
(model, drawMsg)
end
else
let
val model = AppWith.graphVisibility (model, true)
val graphLines = GraphLines.generate model
val drawMsg = DRAW_GRAPH graphLines
in
(model, drawMsg)
end
fun update (model: app_type, inputMsg) =
case inputMsg of
@@ -187,4 +206,5 @@ struct
| RESIZE_WINDOW {width, height} => resizeWindow (model, width, height)
| UNDO_ACTION => undoAction model
| REDO_ACTION => redoAction model
| KEY_G => toggleGraph model
end

View File

@@ -1,5 +1,7 @@
signature APP_WITH =
sig
val graphVisibility: AppType.app_type * bool -> AppType.app_type
val windowResize: AppType.app_type * int * int -> AppType.app_type
val mousePosition: AppType.app_type * Real32.real * Real32.real
@@ -59,6 +61,7 @@ struct
, redo = _
, mouseX
, mouseY
, showGraph
} = app
val newUndo = newUndoHd :: undo
@@ -73,6 +76,7 @@ struct
, windowHeight = windowHeight
, mouseX = mouseX
, mouseY = mouseY
, showGraph = showGraph
}
end
@@ -89,6 +93,7 @@ struct
, redo = _
, mouseX
, mouseY
, showGraph
} = app
val newTriangle = {x1 = x1, y1 = y1, x2 = x2, y2 = y2, x3 = x3, y3 = y3}
@@ -105,6 +110,7 @@ struct
, windowHeight = windowHeight
, mouseX = mouseX
, mouseY = mouseY
, showGraph = showGraph
}
end
@@ -123,6 +129,7 @@ struct
, redo
, mouseX
, mouseY
, showGraph
} = app
val xClickPoints = ClickPoints.generate (wStart, wFinish)
@@ -138,6 +145,7 @@ struct
, redo = redo
, mouseX = mouseX
, mouseY = mouseY
, showGraph = showGraph
}
end
@@ -177,6 +185,7 @@ struct
, windowHeight
, undo
, redo
, showGraph
} = app
in
{ mouseX = mouseX
@@ -189,6 +198,7 @@ struct
, windowHeight = windowHeight
, undo = undo
, redo = redo
, showGraph = showGraph
}
end
@@ -206,6 +216,7 @@ struct
, redo
, mouseX
, mouseY
, showGraph
} = app
val newUndo =
@@ -225,6 +236,7 @@ struct
, windowHeight = windowHeight
, mouseX = mouseX
, mouseY = mouseY
, showGraph = showGraph
}
end
@@ -242,6 +254,7 @@ struct
, redo
, mouseX
, mouseY
, showGraph
} = app
val newUndo = newUndoHd :: undo
@@ -260,6 +273,37 @@ struct
, windowHeight = windowHeight
, mouseX = mouseX
, mouseY = mouseY
, showGraph = showGraph
}
end
fun graphVisibility (app: app_type, shouldShowGraph) =
let
val
{ triangleStage
, triangles
, xClickPoints
, yClickPoints
, windowWidth
, windowHeight
, undo
, redo
, mouseX
, mouseY
, showGraph = _
} = app
in
{ showGraph = shouldShowGraph
, triangleStage = triangleStage
, triangles = triangles
, undo = undo
, redo = redo
, xClickPoints = xClickPoints
, yClickPoints = yClickPoints
, windowWidth = windowWidth
, windowHeight = windowHeight
, mouseX = mouseX
, mouseY = mouseY
}
end
end