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,34 @@ 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 if TC.textLineWidth > windowWidth then
val fh = Real32.fromInt windowHeight { w = windowWidth
in , h = windowHeight
if TC.textLineWidth > windowWidth then , startX = 5
{ w = windowWidth , startY = 5
, fw = floatWindowWidth
, fh = floatWindowHeight
, r = 0.67
, g = 0.51
, b = 0.83
, hr = 0.211
, hg = 0.219
, hb = 0.25
, msgs = msgs
}
else
let
val startX = (windowWidth - TC.textLineWidth) div 2
val finishWidth = startX + TC.textLineWidth
in
{ w = finishWidth
, h = windowHeight , h = windowHeight
, startX = 5 , 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
@@ -734,37 +750,24 @@ struct
, hb = 0.25 , hb = 0.25
, msgs = msgs , msgs = msgs
} }
else end
let
val startX = (windowWidth - TC.textLineWidth) div 2
val finishWidth = startX + TC.textLineWidth
in
{ w = finishWidth
, h = windowHeight
, startX = startX
, startY = 5
, fw = fw
, fh = fh
, r = 0.67
, g = 0.51
, b = 0.83
, hr = 0.211
, hg = 0.219
, hb = 0.25
, msgs = msgs
}
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