begin reimplementing TextBuilder functions to use line-wrapping instead of char-wrap
This commit is contained in:
@@ -1,27 +1,35 @@
|
|||||||
structure TextBuilder =
|
structure TextBuilder =
|
||||||
struct
|
struct
|
||||||
open TextConstants
|
|
||||||
structure TC = TextConstants
|
structure TC = TextConstants
|
||||||
|
|
||||||
type env_data =
|
type env_data =
|
||||||
{ r: Real32.real
|
{ charR: Real32.real
|
||||||
, g: Real32.real
|
, charG: Real32.real
|
||||||
, b: Real32.real
|
, charB: Real32.real
|
||||||
|
|
||||||
(* hr/hg/hb = highlight red/green/blue *)
|
(* different colours for char when cursor is on char *)
|
||||||
, hr: Real32.real
|
, cusorOnCharR: Real32.real
|
||||||
, hg: Real32.real
|
, cusorOnCharG: Real32.real
|
||||||
, hb: Real32.real
|
, cusorOnCharB: Real32.real
|
||||||
|
|
||||||
|
, cursorR: Real32.real
|
||||||
|
, cursorG: Real32.real
|
||||||
|
, cursorB: Real32.real
|
||||||
|
|
||||||
|
, highlightR: Real32.real
|
||||||
|
, highlightG: Real32.real
|
||||||
|
, highlightB: Real32.real
|
||||||
|
|
||||||
|
, charZ: Real32.real
|
||||||
|
, cursorZ: Real32.real
|
||||||
|
, highlightZ: Real32.real
|
||||||
|
|
||||||
, startX: int
|
, startX: int
|
||||||
, startY: int
|
, startY: int
|
||||||
|
|
||||||
(* w = width, h = height.
|
, scrollColumnStart: int
|
||||||
* These do no necessarily correspond to the whole window's width and height.
|
, scrollColumnEnd: int
|
||||||
* For example, in some cases we want to horizontally centre text on the screen.
|
, lastLineNumber: int
|
||||||
* In that case, "w" means "end width/pixel, which causes a line break". *)
|
|
||||||
, w: int
|
|
||||||
, h: int
|
|
||||||
|
|
||||||
(* fw/fh = float window width and float window height *)
|
(* fw/fh = float window width and float window height *)
|
||||||
, fw: Real32.real
|
, fw: Real32.real
|
||||||
@@ -31,63 +39,114 @@ struct
|
|||||||
, searchLen: int
|
, searchLen: int
|
||||||
}
|
}
|
||||||
|
|
||||||
fun accToDrawMsg (textAcc, cursorAcc, bgAcc, env: env_data) =
|
(* different functions to make vectors of different things we want to draw. *)
|
||||||
let
|
fun makeCursor (posX, posY, env: t) =
|
||||||
open MailboxType
|
|
||||||
open DrawMsg
|
|
||||||
|
|
||||||
val msgs = #msgs env
|
|
||||||
|
|
||||||
val textAcc = Vector.concat textAcc
|
|
||||||
val bgAcc = Vector.concat bgAcc
|
|
||||||
val vec = Vector.concat [textAcc, bgAcc, cursorAcc]
|
|
||||||
val drawMsg = DRAW_TEXT vec
|
|
||||||
in
|
|
||||||
DRAW drawMsg :: msgs
|
|
||||||
end
|
|
||||||
|
|
||||||
(* builds text from a string with char-wrap.
|
|
||||||
* char-wrap is a similar concept to word-wrap,
|
|
||||||
* but it breaks on character in the middle of a word.
|
|
||||||
*
|
|
||||||
* Will likely want multiple versions of these two mutually recursive
|
|
||||||
* functions for each selection and cursor type:
|
|
||||||
* cursor over an individual character,
|
|
||||||
* range selection where multiple characters are selected, etc.
|
|
||||||
*
|
|
||||||
* Todo:
|
|
||||||
* - Possibly add visual horizontal indentation when char-wrap occurs
|
|
||||||
* on an indented line *)
|
|
||||||
(* same as buildTextStringAfterCursor, except this keeps track of absolute
|
|
||||||
* index and cursor pos too *)
|
|
||||||
|
|
||||||
fun makeRect (posX, posY, fw, fh, r, g, b) =
|
|
||||||
Rect.lerp
|
Rect.lerp
|
||||||
( Real32.fromInt (posX - 1)
|
( Real32.fromInt (posX - 1)
|
||||||
, Real32.fromInt posY
|
, Real32.fromInt posY
|
||||||
, 0.9
|
, #cursorZ env
|
||||||
, scale
|
, scale
|
||||||
, fw
|
, #fw env
|
||||||
, fh
|
, #fh env
|
||||||
, 1.0
|
, #cursorR env
|
||||||
, 1.0
|
, #cursorG env
|
||||||
, 1.0
|
, #cursorB env
|
||||||
)
|
)
|
||||||
|
|
||||||
fun makeChr (chr, posX, posY, windowWidth, windowHeight, r, g, b) =
|
fun makeHighlight (posX, posY, env: t) =
|
||||||
|
Rect.lerp
|
||||||
|
( Real32.fromInt (posX - 1)
|
||||||
|
, Real32.fromInt posY
|
||||||
|
, #highLightZ env
|
||||||
|
, scale
|
||||||
|
, #fw env
|
||||||
|
, #fh env
|
||||||
|
, #highLightR env
|
||||||
|
, #highLightG env
|
||||||
|
, #highLightB env
|
||||||
|
)
|
||||||
|
|
||||||
|
fun makeChr (chr, posX, posY, env: t) =
|
||||||
CozetteAscii.make
|
CozetteAscii.make
|
||||||
( chr
|
( chr
|
||||||
, Real32.fromInt posX
|
, Real32.fromInt posX
|
||||||
, Real32.fromInt posY
|
, Real32.fromInt posY
|
||||||
, 0.1
|
, #charZ env
|
||||||
, scale
|
, scale
|
||||||
, windowWidth
|
, #fw env
|
||||||
, windowHeight
|
, #fh env
|
||||||
, r
|
, #charR env
|
||||||
, g
|
, #charG env
|
||||||
, b
|
, #charB env
|
||||||
)
|
)
|
||||||
|
|
||||||
|
fun makeCursorOnChr (chr, posX, posY, env: t) =
|
||||||
|
CozetteAscii.make
|
||||||
|
( chr
|
||||||
|
, Real32.fromInt posX
|
||||||
|
, Real32.fromInt posY
|
||||||
|
, #charZ env
|
||||||
|
, scale
|
||||||
|
, #fw env
|
||||||
|
, #fh env
|
||||||
|
, #cursorOnCharR env
|
||||||
|
, #cursorOnCharG env
|
||||||
|
, #cursorOnCharB env
|
||||||
|
)
|
||||||
|
|
||||||
|
fun buildTextString
|
||||||
|
( pos
|
||||||
|
, str
|
||||||
|
, stl
|
||||||
|
, line
|
||||||
|
, ltl
|
||||||
|
, posX
|
||||||
|
, posY
|
||||||
|
, column
|
||||||
|
, lineNumber
|
||||||
|
, absIdx
|
||||||
|
, cursorIdx
|
||||||
|
, env: env_data
|
||||||
|
, acc
|
||||||
|
) =
|
||||||
|
if pos = String.size str then
|
||||||
|
case (stl, ltl) of
|
||||||
|
(str :: stl, line :: ltl) =>
|
||||||
|
buildTextString
|
||||||
|
( 0
|
||||||
|
, str
|
||||||
|
, stl
|
||||||
|
, line
|
||||||
|
, ltl
|
||||||
|
, posX
|
||||||
|
, posY
|
||||||
|
, column
|
||||||
|
, lineNumber absIdx
|
||||||
|
, cursorIdx
|
||||||
|
, env
|
||||||
|
, acc
|
||||||
|
)
|
||||||
|
| (_, _) => acc
|
||||||
|
else if column < #scrollColumnStart env then
|
||||||
|
skipToColumnStart
|
||||||
|
( pos
|
||||||
|
, str
|
||||||
|
, stl
|
||||||
|
, line
|
||||||
|
, ltl
|
||||||
|
, posY
|
||||||
|
, lineNumber
|
||||||
|
, absIdx
|
||||||
|
, cursorIdx
|
||||||
|
, env
|
||||||
|
, acc
|
||||||
|
)
|
||||||
|
else if lineNumber > #lastLineNumber env then
|
||||||
|
acc
|
||||||
|
else
|
||||||
|
case String.sub (str, pos) of
|
||||||
|
chr => raise Fail "unimplemented"
|
||||||
|
|
||||||
fun buildTextString
|
fun buildTextString
|
||||||
( pos
|
( pos
|
||||||
, str
|
, str
|
||||||
@@ -758,6 +817,7 @@ struct
|
|||||||
, h = windowHeight
|
, h = windowHeight
|
||||||
, startX = 5
|
, startX = 5
|
||||||
, startY = 5
|
, startY = 5
|
||||||
|
, z = 0.01
|
||||||
, fw = floatWindowWidth
|
, fw = floatWindowWidth
|
||||||
, fh = floatWindowHeight
|
, fh = floatWindowHeight
|
||||||
, r = 0.67
|
, r = 0.67
|
||||||
@@ -779,6 +839,7 @@ struct
|
|||||||
, h = windowHeight
|
, h = windowHeight
|
||||||
, startX = startX
|
, startX = startX
|
||||||
, startY = 5
|
, startY = 5
|
||||||
|
, z = 0.01
|
||||||
, fw = floatWindowWidth
|
, fw = floatWindowWidth
|
||||||
, fh = floatWindowHeight
|
, fh = floatWindowHeight
|
||||||
, r = 0.67
|
, r = 0.67
|
||||||
|
|||||||
Reference in New Issue
Block a user