in 'TextBuilder.buildWithExisting' function, allow the user to pass a floatWindowWidth and floatWindowHeight which may differ from windowWidth and windowHeight parameters. This enables us to draw text only in a specified area.

This commit is contained in:
2025-09-01 00:52:27 +01:00
parent c95ae5eae3
commit 95c6af3ec7

View File

@@ -714,18 +714,15 @@ struct
| [] => (* should never happen *) 0 | [] => (* should never happen *) 0
end end
fun initEnv (windowWidth, windowHeight, msgs) = fun initEnv
let (windowWidth, windowHeight, floatWindowWidth, floatWindowHeight, msgs) =
val fw = Real32.fromInt windowWidth
val fh = Real32.fromInt windowHeight
in
if TC.textLineWidth > windowWidth then if TC.textLineWidth > windowWidth then
{ w = windowWidth { w = windowWidth
, h = windowHeight , h = windowHeight
, startX = 5 , startX = 5
, startY = 5 , startY = 5
, fw = fw , fw = floatWindowWidth
, fh = fh , fh = floatWindowHeight
, r = 0.67 , r = 0.67
, g = 0.51 , g = 0.51
, b = 0.83 , b = 0.83
@@ -743,8 +740,8 @@ struct
, h = windowHeight , h = windowHeight
, startX = startX , startX = startX
, startY = 5 , startY = 5
, fw = fw , fw = floatWindowWidth
, fh = fh , fh = floatWindowHeight
, r = 0.67 , r = 0.67
, g = 0.51 , g = 0.51
, b = 0.83 , b = 0.83
@@ -754,17 +751,23 @@ struct
, msgs = msgs , msgs = msgs
} }
end end
end
fun build (* todo: add startX and startY parameters,
* so we can control where on the * screen the text starts from.
* Not worth doing until we have/in preparation of tiling functionality *)
fun buildWithExisting
( startLine ( startLine
, cursorPos , cursorPos
, lineGap: LineGap.t , lineGap: LineGap.t
, windowWidth , windowWidth
, windowHeight , windowHeight
, floatWindowWidth
, floatWindowHeight
, searchList: SearchList.t , searchList: SearchList.t
, searchString , searchString
, msgs , msgs
, textAcc
, bgAcc
) = ) =
let let
val {rightStrings, rightLines, line = curLine, idx = curIdx, ...} = val {rightStrings, rightLines, line = curLine, idx = curIdx, ...} =
@@ -778,43 +781,34 @@ struct
(* get absolute idx of line *) (* get absolute idx of line *)
val absIdx = curIdx + startIdx val absIdx = curIdx + startIdx
val env = initEnv (windowWidth, windowHeight, msgs) val env = initEnv
( windowWidth
, windowHeight
, floatWindowWidth
, floatWindowHeight
, msgs
)
val {startX, startY, ...} = env val {startX, startY, ...} = env
val cursorAcc = Vector.fromList [] val cursorAcc = Vector.fromList []
val searchPos = BinSearch.equalOrMore (absIdx, searchList) val searchPos = BinSearch.equalOrMore (absIdx, searchList)
in in
if searchPos < Vector.length searchList then
buildTextStringSearch buildTextStringSearch
( startIdx ( startIdx
, rStrHd , rStrHd
, [] , textAcc
, startX , startX
, startY , startY
, rStrTl , rStrTl
, absIdx , absIdx
, cursorPos , cursorPos
, cursorAcc , cursorAcc
, [] , bgAcc
, env , env
, searchList , searchList
, searchPos , searchPos
, String.size searchString , String.size searchString
) )
else
buildTextString
( startIdx
, rStrHd
, []
, startX
, startY
, rStrTl
, absIdx
, cursorPos
, cursorAcc
, []
, env
)
end end
| (_, _) => | (_, _) =>
(* requested line goes beyond the buffer, (* requested line goes beyond the buffer,
@@ -822,4 +816,29 @@ struct
* else we can do. *) * else we can do. *)
[] []
end end
fun build
( startLine
, cursorPos
, lineGap: LineGap.t
, windowWidth
, windowHeight
, searchList: SearchList.t
, searchString
, msgs
) =
buildWithExisting
( startLine
, cursorPos
, lineGap : LineGap.t
, windowWidth
, windowHeight
, Real32.fromInt windowWidth
, Real32.fromInt windowHeight
, searchList : SearchList.t
, searchString
, msgs
, []
, []
)
end end