additional preparation for drawing cursor (next, just need to send cursor vector)
This commit is contained in:
@@ -11,13 +11,12 @@ struct
|
|||||||
val {buffer, windowWidth, windowHeight, startLine, cursorIdx} = app
|
val {buffer, windowWidth, windowHeight, startLine, cursorIdx} = app
|
||||||
|
|
||||||
val newBuffer = LineGap.goToLine (startLine, buffer)
|
val newBuffer = LineGap.goToLine (startLine, buffer)
|
||||||
val textVec = TextBuilder.build
|
val drawMsg = TextBuilder.build
|
||||||
(startLine, cursorIdx, newBuffer, newWidth, newHeight)
|
(startLine, cursorIdx, newBuffer, newWidth, newHeight)
|
||||||
|
|
||||||
val newApp = AppWith.bufferAndSize (app, newBuffer, newWidth, newHeight)
|
val newApp = AppWith.bufferAndSize (app, newBuffer, newWidth, newHeight)
|
||||||
val msg = REDRAW_TEXT textVec
|
|
||||||
in
|
in
|
||||||
(newApp, [DRAW msg])
|
(newApp, drawMsg)
|
||||||
end
|
end
|
||||||
|
|
||||||
fun update (app, msg) =
|
fun update (app, msg) =
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ signature TEXT_BUILDER =
|
|||||||
sig
|
sig
|
||||||
(* Prerequisite: LineGap is moved to requested line first. *)
|
(* Prerequisite: LineGap is moved to requested line first. *)
|
||||||
val build: int * int * LineGap.t * int * int
|
val build: int * int * LineGap.t * int * int
|
||||||
-> Real32.real vector
|
-> MailboxType.t list
|
||||||
end
|
end
|
||||||
|
|
||||||
structure TextBuilder :> TEXT_BUILDER =
|
structure TextBuilder :> TEXT_BUILDER =
|
||||||
@@ -12,7 +12,7 @@ struct
|
|||||||
val ySpace = 25
|
val ySpace = 25
|
||||||
val fontSize = 30.0
|
val fontSize = 30.0
|
||||||
|
|
||||||
fun buildTextAccToDrawMsg (textAcc, cursorAcc) =
|
fun accToDrawMsg (textAcc, cursorAcc) =
|
||||||
let
|
let
|
||||||
open MailboxType
|
open MailboxType
|
||||||
open DrawMsg
|
open DrawMsg
|
||||||
@@ -41,7 +41,7 @@ struct
|
|||||||
fun buildTextStringAfterCursor
|
fun buildTextStringAfterCursor
|
||||||
( pos, str, acc, posX, posY, startX
|
( pos, str, acc, posX, posY, startX
|
||||||
, windowWidth, windowHeight, fWindowWidth, fWindowHeight
|
, windowWidth, windowHeight, fWindowWidth, fWindowHeight
|
||||||
, r, g, b, tl
|
, r, g, b, tl, cursorAcc
|
||||||
) =
|
) =
|
||||||
if pos < String.size str then
|
if pos < String.size str then
|
||||||
case String.sub (str, pos) of
|
case String.sub (str, pos) of
|
||||||
@@ -51,7 +51,7 @@ struct
|
|||||||
buildTextStringAfterCursor
|
buildTextStringAfterCursor
|
||||||
( pos + 1, str, acc, posX + xSpace, posY, startX
|
( pos + 1, str, acc, posX + xSpace, posY, startX
|
||||||
, windowWidth, windowHeight, fWindowWidth, fWindowHeight
|
, windowWidth, windowHeight, fWindowWidth, fWindowHeight
|
||||||
, r, g, b, tl
|
, r, g, b, tl, cursorAcc
|
||||||
)
|
)
|
||||||
| #"\t" =>
|
| #"\t" =>
|
||||||
(* if tab, proceed forward one char,
|
(* if tab, proceed forward one char,
|
||||||
@@ -59,7 +59,7 @@ struct
|
|||||||
buildTextStringAfterCursor
|
buildTextStringAfterCursor
|
||||||
( pos + 1, str, acc, posX + xSpace3, posY, startX
|
( pos + 1, str, acc, posX + xSpace3, posY, startX
|
||||||
, windowWidth, windowHeight, fWindowWidth, fWindowHeight
|
, windowWidth, windowHeight, fWindowWidth, fWindowHeight
|
||||||
, r, g, b, tl
|
, r, g, b, tl, cursorAcc
|
||||||
)
|
)
|
||||||
| #"\n" =>
|
| #"\n" =>
|
||||||
(* if \n, move down vertically, and move to start horizontally
|
(* if \n, move down vertically, and move to start horizontally
|
||||||
@@ -69,11 +69,11 @@ struct
|
|||||||
buildTextStringAfterCursor
|
buildTextStringAfterCursor
|
||||||
( pos + 1, str, acc, startX, posY + ySpace, startX
|
( pos + 1, str, acc, startX, posY + ySpace, startX
|
||||||
, windowWidth, windowHeight, fWindowWidth, fWindowHeight
|
, windowWidth, windowHeight, fWindowWidth, fWindowHeight
|
||||||
, r, g, b, tl
|
, r, g, b, tl, cursorAcc
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
(* return if there is no more vertical space after line break *)
|
(* return if there is no more vertical space after line break *)
|
||||||
acc
|
accToDrawMsg (acc, cursorAcc)
|
||||||
| #"\r" =>
|
| #"\r" =>
|
||||||
(* same as \n, except we also check if we are in a \r\n pair,
|
(* same as \n, except we also check if we are in a \r\n pair,
|
||||||
* and proceed two characters forward if so *)
|
* and proceed two characters forward if so *)
|
||||||
@@ -85,17 +85,17 @@ struct
|
|||||||
buildTextStringAfterCursor
|
buildTextStringAfterCursor
|
||||||
( pos + 2, str, acc, startX, posY + ySpace, startX
|
( pos + 2, str, acc, startX, posY + ySpace, startX
|
||||||
, windowWidth, windowHeight, fWindowWidth, fWindowHeight
|
, windowWidth, windowHeight, fWindowWidth, fWindowHeight
|
||||||
, r, g, b, tl
|
, r, g, b, tl, cursorAcc
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
buildTextStringAfterCursor
|
buildTextStringAfterCursor
|
||||||
( pos + 1, str, acc, startX, posY + ySpace, startX
|
( pos + 1, str, acc, startX, posY + ySpace, startX
|
||||||
, windowWidth, windowHeight, fWindowWidth, fWindowHeight
|
, windowWidth, windowHeight, fWindowWidth, fWindowHeight
|
||||||
, r, g, b, tl
|
, r, g, b, tl, cursorAcc
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
(* return if there is no more vertical space after line break *)
|
(* return if there is no more vertical space after line break *)
|
||||||
acc
|
accToDrawMsg (acc, cursorAcc)
|
||||||
| chr =>
|
| chr =>
|
||||||
(* for any other character, add it to acc if there is space,
|
(* for any other character, add it to acc if there is space,
|
||||||
* and proceed forward one character in the string *)
|
* and proceed forward one character in the string *)
|
||||||
@@ -112,7 +112,7 @@ struct
|
|||||||
buildTextStringAfterCursor
|
buildTextStringAfterCursor
|
||||||
( pos + 1, str, acc, posX + xSpace, posY, startX
|
( pos + 1, str, acc, posX + xSpace, posY, startX
|
||||||
, windowWidth, windowHeight, fWindowWidth, fWindowHeight
|
, windowWidth, windowHeight, fWindowWidth, fWindowHeight
|
||||||
, r, g, b, tl
|
, r, g, b, tl, cursorAcc
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
else if posY + ySpace < windowHeight then
|
else if posY + ySpace < windowHeight then
|
||||||
@@ -128,12 +128,12 @@ struct
|
|||||||
buildTextStringAfterCursor
|
buildTextStringAfterCursor
|
||||||
( pos + 1, str, acc, startX + xSpace, posY + ySpace, startX
|
( pos + 1, str, acc, startX + xSpace, posY + ySpace, startX
|
||||||
, windowWidth, windowHeight, fWindowWidth, fWindowHeight
|
, windowWidth, windowHeight, fWindowWidth, fWindowHeight
|
||||||
, r, g, b, tl
|
, r, g, b, tl, cursorAcc
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
(* return if no space horizontally or vertically *)
|
(* return if no space horizontally or vertically *)
|
||||||
acc
|
accToDrawMsg (acc, cursorAcc)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
(* if we reached the end of the string,
|
(* if we reached the end of the string,
|
||||||
@@ -141,22 +141,22 @@ struct
|
|||||||
continueBuildTextLineGapAfterCursor
|
continueBuildTextLineGapAfterCursor
|
||||||
( tl, acc, posX, posY, startX
|
( tl, acc, posX, posY, startX
|
||||||
, windowWidth, windowHeight, fWindowWidth, fWindowHeight
|
, windowWidth, windowHeight, fWindowWidth, fWindowHeight
|
||||||
, r, g, b
|
, r, g, b, cursorAcc
|
||||||
)
|
)
|
||||||
|
|
||||||
and continueBuildTextLineGapAfterCursor
|
and continueBuildTextLineGapAfterCursor
|
||||||
( strList, acc, posX, posY, startX
|
( strList, acc, posX, posY, startX
|
||||||
, windowWidth, windowHeight, fWindowWidth, fWindowHeight
|
, windowWidth, windowHeight, fWindowWidth, fWindowHeight
|
||||||
, r, g, b
|
, r, g, b, cursorAcc
|
||||||
) =
|
) =
|
||||||
case strList of
|
case strList of
|
||||||
hd :: tl =>
|
hd :: tl =>
|
||||||
buildTextStringAfterCursor
|
buildTextStringAfterCursor
|
||||||
( 0, hd, acc, posX, posY, startX
|
( 0, hd, acc, posX, posY, startX
|
||||||
, windowWidth, windowHeight, fWindowWidth, fWindowHeight
|
, windowWidth, windowHeight, fWindowWidth, fWindowHeight
|
||||||
, r, g, b, tl
|
, r, g, b, tl, cursorAcc
|
||||||
)
|
)
|
||||||
| [] => acc
|
| [] => accToDrawMsg (acc, cursorAcc)
|
||||||
|
|
||||||
(* same as buildTextStringAfterCursor, except this keeps track of absolute
|
(* same as buildTextStringAfterCursor, except this keeps track of absolute
|
||||||
* index and cursor pos too *)
|
* index and cursor pos too *)
|
||||||
@@ -187,7 +187,7 @@ struct
|
|||||||
, r, g, b, tl, absIdx + 1, cursorPos
|
, r, g, b, tl, absIdx + 1, cursorPos
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
acc
|
accToDrawMsg (acc, [])
|
||||||
| #"\r" =>
|
| #"\r" =>
|
||||||
if posY + ySpace < windowHeight then
|
if posY + ySpace < windowHeight then
|
||||||
if
|
if
|
||||||
@@ -206,7 +206,7 @@ struct
|
|||||||
, r, g, b, tl, absIdx + 1, cursorPos
|
, r, g, b, tl, absIdx + 1, cursorPos
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
acc
|
accToDrawMsg (acc, [])
|
||||||
| chr =>
|
| chr =>
|
||||||
let
|
let
|
||||||
val chrFun = Vector.sub (CozetteAscii.asciiTable, Char.ord chr)
|
val chrFun = Vector.sub (CozetteAscii.asciiTable, Char.ord chr)
|
||||||
@@ -239,7 +239,7 @@ struct
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
acc
|
accToDrawMsg (acc, [])
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
continueBuildTextLineGapBeforeCursor
|
continueBuildTextLineGapBeforeCursor
|
||||||
@@ -251,7 +251,7 @@ struct
|
|||||||
and buildTextStringWithinCursor
|
and buildTextStringWithinCursor
|
||||||
( pos, str, acc, posX, posY, startX
|
( pos, str, acc, posX, posY, startX
|
||||||
, windowWidth, windowHeight, fWindowWidth, fWindowHeight
|
, windowWidth, windowHeight, fWindowWidth, fWindowHeight
|
||||||
, r, g, b, tl, absIdx, cursorPos
|
, r, g, b, tl, absIdx, cursorPos, cursorAcc
|
||||||
) =
|
) =
|
||||||
if pos < String.size str then
|
if pos < String.size str then
|
||||||
case String.sub (str, pos) of
|
case String.sub (str, pos) of
|
||||||
@@ -259,23 +259,23 @@ struct
|
|||||||
buildTextStringWithinCursor
|
buildTextStringWithinCursor
|
||||||
( pos + 1, str, acc, posX + xSpace, posY, startX
|
( pos + 1, str, acc, posX + xSpace, posY, startX
|
||||||
, windowWidth, windowHeight, fWindowWidth, fWindowHeight
|
, windowWidth, windowHeight, fWindowWidth, fWindowHeight
|
||||||
, r, g, b, tl, absIdx + 1, cursorPos
|
, r, g, b, tl, absIdx + 1, cursorPos, cursorAcc
|
||||||
)
|
)
|
||||||
| #"\t" =>
|
| #"\t" =>
|
||||||
buildTextStringWithinCursor
|
buildTextStringWithinCursor
|
||||||
( pos + 1, str, acc, posX + xSpace3, posY, startX
|
( pos + 1, str, acc, posX + xSpace3, posY, startX
|
||||||
, windowWidth, windowHeight, fWindowWidth, fWindowHeight
|
, windowWidth, windowHeight, fWindowWidth, fWindowHeight
|
||||||
, r, g, b, tl, absIdx + 1, cursorPos
|
, r, g, b, tl, absIdx + 1, cursorPos, cursorAcc
|
||||||
)
|
)
|
||||||
| #"\n" =>
|
| #"\n" =>
|
||||||
if posY + ySpace < windowHeight then
|
if posY + ySpace < windowHeight then
|
||||||
buildTextStringWithinCursor
|
buildTextStringWithinCursor
|
||||||
( pos + 1, str, acc, startX, posY + ySpace, startX
|
( pos + 1, str, acc, startX, posY + ySpace, startX
|
||||||
, windowWidth, windowHeight, fWindowWidth, fWindowHeight
|
, windowWidth, windowHeight, fWindowWidth, fWindowHeight
|
||||||
, r, g, b, tl, absIdx + 1, cursorPos
|
, r, g, b, tl, absIdx + 1, cursorPos, cursorAcc
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
acc
|
accToDrawMsg (acc, cursorAcc)
|
||||||
| #"\r" =>
|
| #"\r" =>
|
||||||
if posY + ySpace < windowHeight then
|
if posY + ySpace < windowHeight then
|
||||||
if
|
if
|
||||||
@@ -285,16 +285,16 @@ struct
|
|||||||
buildTextStringWithinCursor
|
buildTextStringWithinCursor
|
||||||
( pos + 2, str, acc, startX, posY + ySpace, startX
|
( pos + 2, str, acc, startX, posY + ySpace, startX
|
||||||
, windowWidth, windowHeight, fWindowWidth, fWindowHeight
|
, windowWidth, windowHeight, fWindowWidth, fWindowHeight
|
||||||
, r, g, b, tl, absIdx + 1, cursorPos
|
, r, g, b, tl, absIdx + 1, cursorPos, cursorAcc
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
buildTextStringWithinCursor
|
buildTextStringWithinCursor
|
||||||
( pos + 1, str, acc, startX, posY + ySpace, startX
|
( pos + 1, str, acc, startX, posY + ySpace, startX
|
||||||
, windowWidth, windowHeight, fWindowWidth, fWindowHeight
|
, windowWidth, windowHeight, fWindowWidth, fWindowHeight
|
||||||
, r, g, b, tl, absIdx + 1, cursorPos
|
, r, g, b, tl, absIdx + 1, cursorPos, cursorAcc
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
acc
|
accToDrawMsg (acc, cursorAcc)
|
||||||
| chr =>
|
| chr =>
|
||||||
let
|
let
|
||||||
val chrFun = Vector.sub (CozetteAscii.asciiTable, Char.ord chr)
|
val chrFun = Vector.sub (CozetteAscii.asciiTable, Char.ord chr)
|
||||||
@@ -308,7 +308,7 @@ struct
|
|||||||
buildTextStringWithinCursor
|
buildTextStringWithinCursor
|
||||||
( pos + 1, str, acc, posX + xSpace, posY, startX
|
( pos + 1, str, acc, posX + xSpace, posY, startX
|
||||||
, windowWidth, windowHeight, fWindowWidth, fWindowHeight
|
, windowWidth, windowHeight, fWindowWidth, fWindowHeight
|
||||||
, r, g, b, tl, absIdx + 1, cursorPos
|
, r, g, b, tl, absIdx + 1, cursorPos, cursorAcc
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
else if posY + ySpace < windowHeight then
|
else if posY + ySpace < windowHeight then
|
||||||
@@ -323,11 +323,11 @@ struct
|
|||||||
buildTextStringWithinCursor
|
buildTextStringWithinCursor
|
||||||
( pos + 1, str, acc, startX + xSpace, posY + ySpace, startX
|
( pos + 1, str, acc, startX + xSpace, posY + ySpace, startX
|
||||||
, windowWidth, windowHeight, fWindowWidth, fWindowHeight
|
, windowWidth, windowHeight, fWindowWidth, fWindowHeight
|
||||||
, r, g, b, tl, absIdx + 1, cursorPos
|
, r, g, b, tl, absIdx + 1, cursorPos, cursorAcc
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
acc
|
accToDrawMsg (acc, cursorAcc)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
(* we have built cursor now, so can call after-cursor function
|
(* we have built cursor now, so can call after-cursor function
|
||||||
@@ -335,7 +335,7 @@ struct
|
|||||||
continueBuildTextLineGapAfterCursor
|
continueBuildTextLineGapAfterCursor
|
||||||
( tl, acc, posX, posY, startX
|
( tl, acc, posX, posY, startX
|
||||||
, windowWidth, windowHeight, fWindowWidth, fWindowHeight
|
, windowWidth, windowHeight, fWindowWidth, fWindowHeight
|
||||||
, r, g, b
|
, r, g, b, cursorAcc
|
||||||
)
|
)
|
||||||
|
|
||||||
and continueBuildTextLineGapBeforeCursor
|
and continueBuildTextLineGapBeforeCursor
|
||||||
@@ -357,17 +357,16 @@ struct
|
|||||||
buildTextStringWithinCursor
|
buildTextStringWithinCursor
|
||||||
( 0, hd, acc, posX, posY, startX
|
( 0, hd, acc, posX, posY, startX
|
||||||
, windowWidth, windowHeight, fWindowWidth, fWindowHeight
|
, windowWidth, windowHeight, fWindowWidth, fWindowHeight
|
||||||
, r, g, b, tl, absIdx, cursorPos
|
, r, g, b, tl, absIdx, cursorPos, []
|
||||||
)
|
)
|
||||||
| [] => acc
|
| [] => accToDrawMsg (acc, [])
|
||||||
|
|
||||||
fun build
|
fun build
|
||||||
(startLine, cursorPos, lineGap: LineGap.t, windowWidth, windowHeight) =
|
(startLine, cursorPos, lineGap: LineGap.t, windowWidth, windowHeight) =
|
||||||
let
|
let
|
||||||
val lineGap = LineGap.goToLine (startLine, lineGap)
|
val lineGap = LineGap.goToLine (startLine, lineGap)
|
||||||
val {rightStrings, rightLines, line = curLine, idx = curIdx, ...} = lineGap
|
val {rightStrings, rightLines, line = curLine, idx = curIdx, ...} = lineGap
|
||||||
|
in
|
||||||
val acc =
|
|
||||||
case (rightStrings, rightLines) of
|
case (rightStrings, rightLines) of
|
||||||
(rStrHd :: rStrTl, rLnHd :: _) =>
|
(rStrHd :: rStrTl, rLnHd :: _) =>
|
||||||
let
|
let
|
||||||
@@ -392,15 +391,20 @@ struct
|
|||||||
|
|
||||||
val absIdx = curIdx + startIdx
|
val absIdx = curIdx + startIdx
|
||||||
|
|
||||||
val f =
|
in
|
||||||
if cursorPos < curIdx + String.size rStrHd then
|
if cursorPos < curIdx + String.size rStrHd then
|
||||||
(* if cursor is within string *)
|
(* if cursor is within string *)
|
||||||
buildTextStringWithinCursor
|
buildTextStringWithinCursor
|
||||||
|
( startIdx, rStrHd, []
|
||||||
|
, 5, 5, 5
|
||||||
|
, windowWidth, windowHeight
|
||||||
|
, Real32.fromInt windowWidth, Real32.fromInt windowHeight
|
||||||
|
, 0.67, 0.51, 0.83
|
||||||
|
, rStrTl, absIdx, cursorPos, []
|
||||||
|
)
|
||||||
else
|
else
|
||||||
(* if cursor is after string *)
|
(* if cursor is after string *)
|
||||||
buildTextStringBeforeCursor
|
buildTextStringBeforeCursor
|
||||||
in
|
|
||||||
f
|
|
||||||
( startIdx, rStrHd, []
|
( startIdx, rStrHd, []
|
||||||
, 5, 5, 5
|
, 5, 5, 5
|
||||||
, windowWidth, windowHeight
|
, windowWidth, windowHeight
|
||||||
@@ -414,7 +418,5 @@ struct
|
|||||||
* so just return empty list as there is nothig
|
* so just return empty list as there is nothig
|
||||||
* else we can do. *)
|
* else we can do. *)
|
||||||
[]
|
[]
|
||||||
in
|
|
||||||
Vector.concat acc
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user