done fiddling with cursor; looks fine now

This commit is contained in:
2024-10-09 12:42:07 +01:00
parent 306d693877
commit 6344dca6cb
3 changed files with 107 additions and 63 deletions

View File

@@ -12,7 +12,7 @@ struct
val newBuffer = LineGap.goToLine (startLine, buffer) val newBuffer = LineGap.goToLine (startLine, buffer)
val drawMsg = TextBuilder.build val drawMsg = TextBuilder.build
(startLine, cursorIdx, newBuffer, newWidth, newHeight) (startLine, 2, newBuffer, newWidth, newHeight)
val newApp = AppWith.bufferAndSize (app, newBuffer, newWidth, newHeight) val newApp = AppWith.bufferAndSize (app, newBuffer, newWidth, newHeight)
in in

View File

@@ -26,12 +26,14 @@ struct
[DRAW textMsg, DRAW cursorMsg] [DRAW textMsg, DRAW cursorMsg]
end end
fun buildCursor (posX, posY, fWindowWidth, fWindowHeight) = fun buildCursor (posX, posY, fWindowWidth, fWindowHeight, r, g, b) =
let let
val top = Real32.fromInt posX val left = posX + 9
val left = Real32.fromInt posY val left = Real32.fromInt left
val right = left + fontSize val right = left + 12.0
val bottom = top + fontSize
val top = Real32.fromInt posY
val bottom = top + fontSize + 2.0
val halfHeight = fWindowHeight / 2.0 val halfHeight = fWindowHeight / 2.0
val top = (~(top - halfHeight)) / halfHeight val top = (~(top - halfHeight)) / halfHeight
@@ -42,13 +44,13 @@ struct
val right = (right - halfWidth) / halfWidth val right = (right - halfWidth) / halfWidth
val vec = val vec =
#[ left, top, 1.0, 1.0, 1.0 #[ left, top, r, g, b
, right, top, 1.0, 1.0, 1.0 , right, top, r, g, b
, left, bottom, 1.0, 1.0, 1.0 , left, bottom, r, g, b
, left, bottom, 1.0, 1.0, 1.0 , left, bottom, r, g, b
, right, bottom, 1.0, 1.0, 1.0 , right, bottom, r, g, b
, right, top, 1.0, 1.0, 1.0 , right, top, r, g, b
] ]
in in
[vec] [vec]
@@ -191,7 +193,7 @@ struct
fun buildTextStringBeforeCursor fun buildTextStringBeforeCursor
( 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, hr, hg, hb
) = ) =
if pos < String.size str then if pos < String.size str then
case String.sub (str, pos) of case String.sub (str, pos) of
@@ -199,20 +201,20 @@ struct
buildTextStringBeforeCursor buildTextStringBeforeCursor
( 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, hr, hg, hb
) )
| #"\t" => | #"\t" =>
buildTextStringBeforeCursor buildTextStringBeforeCursor
( 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, hr, hg, hb
) )
| #"\n" => | #"\n" =>
if posY + ySpace < windowHeight then if posY + ySpace < windowHeight then
buildTextStringBeforeCursor buildTextStringBeforeCursor
( 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, hr, hg, hb
) )
else else
accToDrawMsg (acc, []) accToDrawMsg (acc, [])
@@ -225,13 +227,13 @@ struct
buildTextStringBeforeCursor buildTextStringBeforeCursor
( 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, hr, hg, hb
) )
else else
buildTextStringBeforeCursor buildTextStringBeforeCursor
( 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, hr, hg, hb
) )
else else
accToDrawMsg (acc, []) accToDrawMsg (acc, [])
@@ -248,7 +250,7 @@ struct
buildTextStringBeforeCursor buildTextStringBeforeCursor
( 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, hr, hg, hb
) )
end end
else if posY + ySpace < windowHeight then else if posY + ySpace < windowHeight then
@@ -263,7 +265,7 @@ struct
buildTextStringBeforeCursor buildTextStringBeforeCursor
( 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, hr, hg, hb
) )
end end
else else
@@ -273,13 +275,13 @@ struct
continueBuildTextLineGapBeforeCursor continueBuildTextLineGapBeforeCursor
( tl, acc, posX, posY, startX ( tl, acc, posX, posY, startX
, windowWidth, windowHeight, fWindowWidth, fWindowHeight , windowWidth, windowHeight, fWindowWidth, fWindowHeight
, r, g, b, absIdx, cursorPos , r, g, b, absIdx, cursorPos, hr, hg, hb
) )
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, cursorAcc , r, g, b, tl, absIdx, cursorPos, cursorAcc, hr, hg, hb
) = ) =
if pos < String.size str then if pos < String.size str then
case String.sub (str, pos) of case String.sub (str, pos) of
@@ -287,20 +289,20 @@ 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, cursorAcc , r, g, b, tl, absIdx + 1, cursorPos, cursorAcc, hr, hg, hb
) )
| #"\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, cursorAcc , r, g, b, tl, absIdx + 1, cursorPos, cursorAcc, hr, hg, hb
) )
| #"\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, cursorAcc , r, g, b, tl, absIdx + 1, cursorPos, cursorAcc, hr, hg, hb
) )
else else
accToDrawMsg (acc, cursorAcc) accToDrawMsg (acc, cursorAcc)
@@ -313,55 +315,95 @@ 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, cursorAcc , r, g, b, tl, absIdx + 1, cursorPos, cursorAcc, hr, hg, hb
) )
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, cursorAcc , r, g, b, tl, absIdx + 1, cursorPos, cursorAcc, hr, hg, hb
) )
else else
accToDrawMsg (acc, cursorAcc) 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)
val cursorAcc =
if absIdx <> cursorPos then
cursorAcc
else
buildCursor (posX, posY, fWindowWidth, fWindowHeight)
in in
if posX + xSpace < windowWidth then if absIdx <> cursorPos then
let (* not equal to cursor *)
val chrVec = chrFun if posX + xSpace < windowWidth then
(posX, posY, fontSize, fontSize, fWindowWidth, fWindowHeight, r, g, b) let
val acc = chrVec :: acc val chrVec = chrFun
in (posX, posY, fontSize, fontSize, fWindowWidth, fWindowHeight, r, g, b)
buildTextStringWithinCursor val acc = chrVec :: acc
( pos + 1, str, acc, posX + xSpace, posY, startX in
, windowWidth, windowHeight, fWindowWidth, fWindowHeight buildTextStringWithinCursor
, r, g, b, tl, absIdx + 1, cursorPos, cursorAcc ( pos + 1, str, acc, posX + xSpace, posY, startX
) , windowWidth, windowHeight, fWindowWidth, fWindowHeight
end , r, g, b, tl, absIdx + 1, cursorPos, cursorAcc, hr, hg, hb
else if posY + ySpace < windowHeight then )
let end
val chrVec = chrFun else if posY + ySpace < windowHeight then
( startX, posY + ySpace, fontSize, fontSize let
, fWindowWidth, fWindowHeight val chrVec = chrFun
, r, g, b ( startX, posY + ySpace, fontSize, fontSize
) , fWindowWidth, fWindowHeight
val acc = chrVec :: acc , r, g, b
in )
buildTextStringWithinCursor val acc = chrVec :: acc
( pos + 1, str, acc, startX + xSpace, posY + ySpace, startX in
, windowWidth, windowHeight, fWindowWidth, fWindowHeight buildTextStringWithinCursor
, r, g, b, tl, absIdx + 1, cursorPos, cursorAcc ( pos + 1, str, acc, startX + xSpace, posY + ySpace, startX
) , windowWidth, windowHeight, fWindowWidth, fWindowHeight
end , r, g, b, tl, absIdx + 1, cursorPos, cursorAcc, hr, hg, hb
)
end
else
accToDrawMsg (acc, cursorAcc)
else else
accToDrawMsg (acc, cursorAcc) (* equal to cursor *)
let
val cursorAcc = buildCursor (posX, posY, fWindowWidth, fWindowHeight, r, g ,b)
in
if posX + xSpace < windowWidth then
let
val chrVec = chrFun
( posX, posY, fontSize, fontSize
, fWindowWidth, fWindowHeight
, hr, hg, hb
)
val acc = chrVec :: acc
in
(* can start building after cursor now,
* since cursor was built *)
buildTextStringAfterCursor
( pos + 1, str, acc, posX + xSpace, posY, startX
, windowWidth, windowHeight, fWindowWidth, fWindowHeight
, r, g, b, tl, cursorAcc
)
end
else if posY + ySpace < windowHeight then
let
val chrVec = chrFun
( startX, posY + ySpace, fontSize, fontSize
, fWindowWidth, fWindowHeight
, hr, hg, hb
)
val acc = chrVec :: acc
in
(* can start building after cursor now,
* since cursor was built *)
buildTextStringAfterCursor
( pos + 1, str, acc, startX + xSpace, posY + ySpace, startX
, windowWidth, windowHeight, fWindowWidth, fWindowHeight
, r, g, b, tl, cursorAcc
)
end
else
accToDrawMsg (acc, cursorAcc)
end
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
* to build rest of text *) * to build rest of text *)
@@ -374,7 +416,7 @@ struct
and continueBuildTextLineGapBeforeCursor and continueBuildTextLineGapBeforeCursor
( strList, acc, posX, posY, startX ( strList, acc, posX, posY, startX
, windowWidth, windowHeight, fWindowWidth, fWindowHeight , windowWidth, windowHeight, fWindowWidth, fWindowHeight
, r, g, b, absIdx, cursorPos , r, g, b, absIdx, cursorPos, hr, hg, hb
) = ) =
case strList of case strList of
hd :: tl => hd :: tl =>
@@ -383,14 +425,14 @@ struct
buildTextStringBeforeCursor buildTextStringBeforeCursor
( 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, hr, hg, hb
) )
else else
(* if within cursor *) (* if within cursor *)
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, [], hr, hg, hb
) )
| [] => accToDrawMsg (acc, []) | [] => accToDrawMsg (acc, [])
@@ -434,6 +476,7 @@ struct
, Real32.fromInt windowWidth, Real32.fromInt windowHeight , Real32.fromInt windowWidth, Real32.fromInt windowHeight
, 0.67, 0.51, 0.83 , 0.67, 0.51, 0.83
, rStrTl, absIdx, cursorPos, [] , rStrTl, absIdx, cursorPos, []
, 0.211, 0.219, 0.25
) )
else else
(* if cursor is after string *) (* if cursor is after string *)
@@ -444,6 +487,7 @@ struct
, Real32.fromInt windowWidth, Real32.fromInt windowHeight , Real32.fromInt windowWidth, Real32.fromInt windowHeight
, 0.67, 0.51, 0.83 , 0.67, 0.51, 0.83
, rStrTl, absIdx, cursorPos , rStrTl, absIdx, cursorPos
, 0.211, 0.219, 0.25
) )
end end
| (_, _) => | (_, _) =>

BIN
shf

Binary file not shown.