scaffolding for concurrent ml
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
structure AppType =
|
||||
struct
|
||||
|
||||
type app_type =
|
||||
{buffer: LineGap.t, windowWidth: int, windowHeight: int}
|
||||
end
|
||||
|
||||
24
fcore/app-update.sml
Normal file
24
fcore/app-update.sml
Normal file
@@ -0,0 +1,24 @@
|
||||
structure AppUpdate =
|
||||
struct
|
||||
open AppType
|
||||
|
||||
open MailboxType
|
||||
open DrawMsg
|
||||
open InputMsg
|
||||
|
||||
fun resizeText (app: app_type, newWidth, newHeight) =
|
||||
let
|
||||
val {buffer, windowWidth, windowHeight} = app
|
||||
val (textVec, newBuffer) =
|
||||
TextBuilder.build (0, buffer, newWidth, newHeight)
|
||||
|
||||
val newApp =
|
||||
{buffer = newBuffer, windowWidth = newWidth, windowHeight = newHeight}
|
||||
val msg = REDRAW_TEXT textVec
|
||||
in
|
||||
(newApp, [DRAW msg])
|
||||
end
|
||||
|
||||
fun update (app, msg) =
|
||||
case msg of RESIZE_EVENT (width, height) => resizeText (app, width, height)
|
||||
end
|
||||
@@ -136,45 +136,6 @@ struct
|
||||
)
|
||||
| [] => acc
|
||||
|
||||
(* todo:
|
||||
* before calling continueBuildTextLineGap,
|
||||
* find start position inside LineGap
|
||||
* to start building from *)
|
||||
fun startBuildTextLineGap (startLine, lineGap: LineGap.t, windowWidth, windowHeight) =
|
||||
let
|
||||
val lineGap = LineGap.goToLine (startLine, lineGap)
|
||||
val {rightStrings, rightLines, line = curLine, ...} = lineGap
|
||||
|
||||
val acc = case (rightStrings, rightLines) of
|
||||
(rStrHd::rStrTl, rLnHd::_) =>
|
||||
let
|
||||
(* get index of line to start building from *)
|
||||
val lnPos = startLine - curLine
|
||||
val startIdx = Vector.sub (rLnHd, lnPos)
|
||||
val startIdx =
|
||||
if String.sub (rStrHd, startIdx) = #"\r" andalso startIdx
|
||||
< String.size rStrHd - 1 andalso String.sub (rStrHd,
|
||||
startIdx + 1) = #"\n"
|
||||
then
|
||||
(* handle \r\n pair *)
|
||||
startIdx + 2
|
||||
else startIdx + 1
|
||||
in
|
||||
buildTextString ( startIdx, rStrHd, [], 5, 5, 5
|
||||
, windowWidth, windowHeight,
|
||||
Real32.fromInt windowWidth, Real32.fromInt windowHeight
|
||||
, 0.0, 0.0, 0.0, rStrTl
|
||||
)
|
||||
end
|
||||
| (_, _) =>
|
||||
(* requested line goes beyond the buffer,
|
||||
* so just return empty list as there is nothig
|
||||
* else we can do. *)
|
||||
[]
|
||||
in
|
||||
Vector.concat acc
|
||||
end
|
||||
|
||||
fun build
|
||||
(startLine, lineGap: LineGap.t, windowWidth, windowHeight) =
|
||||
let
|
||||
|
||||
Reference in New Issue
Block a user