done for the moment with text rendering
This commit is contained in:
@@ -4,14 +4,12 @@ struct
|
|||||||
* char-wrap is a similar concept to word-wrap,
|
* char-wrap is a similar concept to word-wrap,
|
||||||
* but it breaks on character in the middle of a word.
|
* but it breaks on character in the middle of a word.
|
||||||
* Todo:
|
* Todo:
|
||||||
* - Let caller know which termination case was reached.
|
|
||||||
* Did we reach the end of the string or did we exhaust the screen space?
|
|
||||||
* - Possibly add visual horizontal indentation when char-wrap occurs
|
* - Possibly add visual horizontal indentation when char-wrap occurs
|
||||||
* on an indented line *)
|
* on an indented line *)
|
||||||
fun buildTextString
|
fun buildTextString
|
||||||
( pos, str, acc, posX, posY, startX
|
( pos, str, acc, posX, posY, startX
|
||||||
, windowWidth, windowHeight, fWindowWidth, fWindowHeight
|
, windowWidth, windowHeight, fWindowWidth, fWindowHeight
|
||||||
, r, g, b
|
, r, g, b, tl
|
||||||
) =
|
) =
|
||||||
if pos < String.size str then
|
if pos < String.size str then
|
||||||
case String.sub (str, pos) of
|
case String.sub (str, pos) of
|
||||||
@@ -19,18 +17,18 @@ struct
|
|||||||
(* if space, then proceed forward one char
|
(* if space, then proceed forward one char
|
||||||
* without adding to acc *)
|
* without adding to acc *)
|
||||||
buildTextString
|
buildTextString
|
||||||
( pos + 1, str, acc, posX + 25, posY, startX
|
( pos + 1, str, acc, posX + 25, posY, startX
|
||||||
, windowWidth, windowHeight, fWindowWidth, fWindowHeight
|
, windowWidth, windowHeight, fWindowWidth, fWindowHeight
|
||||||
, r, g, b
|
, r, g, b, tl
|
||||||
)
|
)
|
||||||
| #"\t" =>
|
| #"\t" =>
|
||||||
(* if tab, proceed forward one char,
|
(* if tab, proceed forward one char,
|
||||||
* and jump visually forwards three chars *)
|
* and jump visually forwards three chars *)
|
||||||
buildTextString
|
buildTextString
|
||||||
( pos + 1, str, acc, posX + 75, posY, startX
|
( pos + 1, str, acc, posX + 75, posY, startX
|
||||||
, windowWidth, windowHeight, fWindowWidth, fWindowHeight
|
, windowWidth, windowHeight, fWindowWidth, fWindowHeight
|
||||||
, r, g, b
|
, r, g, b, tl
|
||||||
)
|
)
|
||||||
| #"\n" =>
|
| #"\n" =>
|
||||||
(* if \n, move down vertically, and move to start horizontally
|
(* if \n, move down vertically, and move to start horizontally
|
||||||
* assuming we have not exceeded the window's height.
|
* assuming we have not exceeded the window's height.
|
||||||
@@ -39,9 +37,10 @@ struct
|
|||||||
buildTextString
|
buildTextString
|
||||||
( pos + 1, str, acc, startX, posY + 25, startX
|
( pos + 1, str, acc, startX, posY + 25, startX
|
||||||
, windowWidth, windowHeight, fWindowWidth, fWindowHeight
|
, windowWidth, windowHeight, fWindowWidth, fWindowHeight
|
||||||
, r, g, b
|
, r, g, b, tl
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
|
(* return if there is no more vertical space after line break *)
|
||||||
acc
|
acc
|
||||||
| #"\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,
|
||||||
@@ -54,15 +53,16 @@ struct
|
|||||||
buildTextString
|
buildTextString
|
||||||
( pos + 2, str, acc, startX, posY + 25, startX
|
( pos + 2, str, acc, startX, posY + 25, startX
|
||||||
, windowWidth, windowHeight, fWindowWidth, fWindowHeight
|
, windowWidth, windowHeight, fWindowWidth, fWindowHeight
|
||||||
, r, g, b
|
, r, g, b, tl
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
buildTextString
|
buildTextString
|
||||||
( pos + 1, str, acc, startX, posY + 25, startX
|
( pos + 1, str, acc, startX, posY + 25, startX
|
||||||
, windowWidth, windowHeight, fWindowWidth, fWindowHeight
|
, windowWidth, windowHeight, fWindowWidth, fWindowHeight
|
||||||
, r, g, b
|
, r, g, b, tl
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
|
(* return if there is no more vertical space after line break *)
|
||||||
acc
|
acc
|
||||||
| 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,
|
||||||
@@ -80,7 +80,7 @@ struct
|
|||||||
buildTextString
|
buildTextString
|
||||||
( pos + 1, str, acc, posX + 25, posY, startX
|
( pos + 1, str, acc, posX + 25, posY, startX
|
||||||
, windowWidth, windowHeight, fWindowWidth, fWindowHeight
|
, windowWidth, windowHeight, fWindowWidth, fWindowHeight
|
||||||
, r, g, b
|
, r, g, b, tl
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
else if posY + 25 < windowHeight then
|
else if posY + 25 < windowHeight then
|
||||||
@@ -96,13 +96,51 @@ struct
|
|||||||
buildTextString
|
buildTextString
|
||||||
( pos + 1, str, acc, startX + 25, posY + 25, startX
|
( pos + 1, str, acc, startX + 25, posY + 25, startX
|
||||||
, windowWidth, windowHeight, fWindowWidth, fWindowHeight
|
, windowWidth, windowHeight, fWindowWidth, fWindowHeight
|
||||||
, r, g, b
|
, r, g, b, tl
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
(* if no space horizontally or vertically, just return *)
|
(* return if no space horizontally or vertically *)
|
||||||
acc
|
acc
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
acc
|
(* if we reached the end of the string,
|
||||||
|
* call function to build next string *)
|
||||||
|
continueBuildTextLineGap
|
||||||
|
( tl, acc, posX, posY, startX
|
||||||
|
, windowWidth, windowHeight, fWindowWidth, fWindowWidth
|
||||||
|
, r, g, b
|
||||||
|
)
|
||||||
|
|
||||||
|
and continueBuildTextLineGap
|
||||||
|
( strList, acc, posX, posY, startX
|
||||||
|
, windowWidth, windowHeight, fWindowWidth, fWindowHeight
|
||||||
|
, r, g, b
|
||||||
|
) =
|
||||||
|
case strList of
|
||||||
|
hd :: tl =>
|
||||||
|
buildTextString
|
||||||
|
( 0, hd, acc, posX, posY, startX
|
||||||
|
, windowWidth, windowHeight, fWindowWidth, fWindowHeight
|
||||||
|
, r, g, b, tl
|
||||||
|
)
|
||||||
|
| [] => acc
|
||||||
|
|
||||||
|
(* todo:
|
||||||
|
* before calling continueBuildTextLineGap,
|
||||||
|
* find start position inside LineGap
|
||||||
|
* to start building from *)
|
||||||
|
fun startBuildTextLineGap (startLine, lineGap: LineGap.t, windowWidth, windowHeight) =
|
||||||
|
let
|
||||||
|
val acc =
|
||||||
|
continueBuildTextLineGap
|
||||||
|
( #rightStrings lineGap, [], 10, 10, 10
|
||||||
|
, windowWidth, windowHeight
|
||||||
|
, Real32.fromInt windowWidth
|
||||||
|
, Real32.fromInt windowHeight
|
||||||
|
, 0.0, 0.0, 0.0
|
||||||
|
)
|
||||||
|
in
|
||||||
|
Vector.concat acc
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user