when text is wide enough to be centered, also centre the search bar
This commit is contained in:
@@ -27,37 +27,16 @@ struct
|
|||||||
|
|
||||||
val searchStringPosY = windowHeight - TextConstants.ySpace - 5
|
val searchStringPosY = windowHeight - TextConstants.ySpace - 5
|
||||||
|
|
||||||
val initialTextAcc = TextBuilder.buildLineToList
|
val initialTextAcc = SearchBar.build
|
||||||
( searchString
|
( searchString
|
||||||
, 5
|
, 5
|
||||||
, searchStringPosY
|
, searchStringPosY
|
||||||
, windowWidth
|
, windowWidth
|
||||||
, floatWindowWidth
|
, floatWindowWidth
|
||||||
, floatWindowHeight
|
, floatWindowHeight
|
||||||
|
, searchCursorIdx
|
||||||
)
|
)
|
||||||
|
|
||||||
val cursor =
|
|
||||||
let
|
|
||||||
val xpos = TextConstants.xSpace * (searchCursorIdx + 1) + 5
|
|
||||||
val x = Real32.fromInt xpos
|
|
||||||
val y = Real32.fromInt searchStringPosY
|
|
||||||
val r: Real32.real = 0.67
|
|
||||||
val g: Real32.real = 0.51
|
|
||||||
val b: Real32.real = 0.83
|
|
||||||
in
|
|
||||||
PipeCursor.lerp
|
|
||||||
( x
|
|
||||||
, y
|
|
||||||
, 0.01
|
|
||||||
, TextConstants.scale
|
|
||||||
, floatWindowWidth
|
|
||||||
, floatWindowHeight
|
|
||||||
, r
|
|
||||||
, g
|
|
||||||
, b
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
||||||
val cursorLine = LineGap.getLineNumberOfIdx (cursorIdx, buffer)
|
val cursorLine = LineGap.getLineNumberOfIdx (cursorIdx, buffer)
|
||||||
val startLine =
|
val startLine =
|
||||||
@@ -77,7 +56,7 @@ struct
|
|||||||
, tempSearchList
|
, tempSearchList
|
||||||
, searchString
|
, searchString
|
||||||
, visualScrollColumn
|
, visualScrollColumn
|
||||||
, cursor :: initialTextAcc
|
, initialTextAcc
|
||||||
)
|
)
|
||||||
val drawMsg = Vector.concat drawMsg
|
val drawMsg = Vector.concat drawMsg
|
||||||
val drawMsg = DrawMsg.DRAW_TEXT drawMsg
|
val drawMsg = DrawMsg.DRAW_TEXT drawMsg
|
||||||
@@ -109,13 +88,14 @@ struct
|
|||||||
|
|
||||||
val searchStringPosY = newWindowHeight - TextConstants.ySpace - 5
|
val searchStringPosY = newWindowHeight - TextConstants.ySpace - 5
|
||||||
|
|
||||||
val initialTextAcc = TextBuilder.buildLineToList
|
val initialTextAcc = SearchBar.build
|
||||||
( searchString
|
( searchString
|
||||||
, 5
|
, 5
|
||||||
, searchStringPosY
|
, searchStringPosY
|
||||||
, newWindowWidth
|
, newWindowWidth
|
||||||
, floatWindowWidth
|
, floatWindowWidth
|
||||||
, floatWindowHeight
|
, floatWindowHeight
|
||||||
|
, searchCursorIdx
|
||||||
)
|
)
|
||||||
|
|
||||||
val cursor =
|
val cursor =
|
||||||
|
|||||||
@@ -1,91 +0,0 @@
|
|||||||
structure TextBuilder =
|
|
||||||
struct
|
|
||||||
structure TC = TextConstants
|
|
||||||
structure Utils = TextBuilderUtils
|
|
||||||
|
|
||||||
local
|
|
||||||
fun loop
|
|
||||||
(pos, str, posX, posY, endX, acc, floatWindowWidth, floatWindowHeight) =
|
|
||||||
if pos = String.size str then
|
|
||||||
acc
|
|
||||||
else if posX + TC.xSpace >= endX then
|
|
||||||
acc
|
|
||||||
else
|
|
||||||
let
|
|
||||||
val chr = String.sub (str, pos)
|
|
||||||
val r: Real32.real = 0.67
|
|
||||||
val g: Real32.real = 0.51
|
|
||||||
val b: Real32.real = 0.83
|
|
||||||
val fPosX = Real32.fromInt posX
|
|
||||||
val fPosY = Real32.fromInt posY
|
|
||||||
val z: Real32.real = 0.1
|
|
||||||
|
|
||||||
val chr = CozetteAscii.make
|
|
||||||
( chr
|
|
||||||
, fPosX
|
|
||||||
, fPosY
|
|
||||||
, z
|
|
||||||
, TC.scale
|
|
||||||
, floatWindowWidth
|
|
||||||
, floatWindowHeight
|
|
||||||
, r
|
|
||||||
, g
|
|
||||||
, b
|
|
||||||
)
|
|
||||||
|
|
||||||
val acc = chr :: acc
|
|
||||||
val nextPosX = posX + TC.xSpace
|
|
||||||
in
|
|
||||||
loop
|
|
||||||
( pos + 1
|
|
||||||
, str
|
|
||||||
, nextPosX
|
|
||||||
, posY
|
|
||||||
, endX
|
|
||||||
, acc
|
|
||||||
, floatWindowWidth
|
|
||||||
, floatWindowHeight
|
|
||||||
)
|
|
||||||
end
|
|
||||||
in
|
|
||||||
(* builds a single text line from a string.
|
|
||||||
* Used for getting Real32.real vector representing search input.
|
|
||||||
* Todo: Add | cursor to show position of search-string-cursor. *)
|
|
||||||
fun buildLineToList
|
|
||||||
(str, startX, startY, endX, floatWindowWidth, floatWindowHeight) =
|
|
||||||
let
|
|
||||||
val r: Real32.real = 0.67
|
|
||||||
val g: Real32.real = 0.51
|
|
||||||
val b: Real32.real = 0.83
|
|
||||||
val fPosX = Real32.fromInt startX
|
|
||||||
val fPosY = Real32.fromInt startY
|
|
||||||
val z: Real32.real = 0.1
|
|
||||||
|
|
||||||
val chr = CozetteAscii.make
|
|
||||||
( #"/"
|
|
||||||
, fPosX
|
|
||||||
, fPosY
|
|
||||||
, z
|
|
||||||
, TC.scale
|
|
||||||
, floatWindowWidth
|
|
||||||
, floatWindowHeight
|
|
||||||
, r
|
|
||||||
, g
|
|
||||||
, b
|
|
||||||
)
|
|
||||||
|
|
||||||
val posX = startX + TC.xSpace
|
|
||||||
in
|
|
||||||
loop
|
|
||||||
( 0
|
|
||||||
, str
|
|
||||||
, posX
|
|
||||||
, startY
|
|
||||||
, endX
|
|
||||||
, [chr]
|
|
||||||
, floatWindowWidth
|
|
||||||
, floatWindowHeight
|
|
||||||
)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
128
fcore/text-builder/search-bar.sml
Normal file
128
fcore/text-builder/search-bar.sml
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
structure SearchBar =
|
||||||
|
struct
|
||||||
|
structure TC = TextConstants
|
||||||
|
structure Utils = TextBuilderUtils
|
||||||
|
|
||||||
|
fun loop
|
||||||
|
(pos, str, posX, posY, endX, acc, floatWindowWidth, floatWindowHeight) =
|
||||||
|
if pos = String.size str then
|
||||||
|
acc
|
||||||
|
else if posX >= endX then
|
||||||
|
acc
|
||||||
|
else
|
||||||
|
let
|
||||||
|
val chr = String.sub (str, pos)
|
||||||
|
val r: Real32.real = 0.67
|
||||||
|
val g: Real32.real = 0.51
|
||||||
|
val b: Real32.real = 0.83
|
||||||
|
val fPosX = Real32.fromInt posX
|
||||||
|
val fPosY = Real32.fromInt posY
|
||||||
|
val z: Real32.real = 0.1
|
||||||
|
|
||||||
|
val chr = CozetteAscii.make
|
||||||
|
( chr
|
||||||
|
, fPosX
|
||||||
|
, fPosY
|
||||||
|
, z
|
||||||
|
, TC.scale
|
||||||
|
, floatWindowWidth
|
||||||
|
, floatWindowHeight
|
||||||
|
, r
|
||||||
|
, g
|
||||||
|
, b
|
||||||
|
)
|
||||||
|
|
||||||
|
val acc = chr :: acc
|
||||||
|
val nextPosX = posX + TC.xSpace
|
||||||
|
in
|
||||||
|
loop
|
||||||
|
( pos + 1
|
||||||
|
, str
|
||||||
|
, nextPosX
|
||||||
|
, posY
|
||||||
|
, endX
|
||||||
|
, acc
|
||||||
|
, floatWindowWidth
|
||||||
|
, floatWindowHeight
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
(* builds a single text line from a string.
|
||||||
|
* Used for getting Real32.real vector representing search input.
|
||||||
|
* Todo: add scrolling, so that text scrolls horizontally when greater than width. *)
|
||||||
|
fun build
|
||||||
|
( str
|
||||||
|
, startX
|
||||||
|
, startY
|
||||||
|
, endX
|
||||||
|
, floatWindowWidth
|
||||||
|
, floatWindowHeight
|
||||||
|
, searchCursorIdx
|
||||||
|
) =
|
||||||
|
let
|
||||||
|
val r: Real32.real = 0.67
|
||||||
|
val g: Real32.real = 0.51
|
||||||
|
val b: Real32.real = 0.83
|
||||||
|
val z: Real32.real = 0.1
|
||||||
|
|
||||||
|
val width = endX - startX
|
||||||
|
val (startX, endX) =
|
||||||
|
if TC.textLineWidth > width then
|
||||||
|
(startX, endX)
|
||||||
|
else
|
||||||
|
let
|
||||||
|
val startX = (width - TC.textLineWidth) div 2
|
||||||
|
val endX = startX + TC.textLineWidth
|
||||||
|
in
|
||||||
|
(startX, endX)
|
||||||
|
end
|
||||||
|
|
||||||
|
val fPosX = Real32.fromInt startX
|
||||||
|
val fPosY = Real32.fromInt startY
|
||||||
|
|
||||||
|
val slash = CozetteAscii.make
|
||||||
|
( #"/"
|
||||||
|
, fPosX
|
||||||
|
, fPosY
|
||||||
|
, z
|
||||||
|
, TC.scale
|
||||||
|
, floatWindowWidth
|
||||||
|
, floatWindowHeight
|
||||||
|
, r
|
||||||
|
, g
|
||||||
|
, b
|
||||||
|
)
|
||||||
|
|
||||||
|
val cursor =
|
||||||
|
let
|
||||||
|
val xpos = TextConstants.xSpace * (searchCursorIdx + 1) + startX
|
||||||
|
val xpos = Int.min (endX, xpos)
|
||||||
|
val x = Real32.fromInt xpos
|
||||||
|
in
|
||||||
|
PipeCursor.lerp
|
||||||
|
( x
|
||||||
|
, fPosY
|
||||||
|
, 0.01
|
||||||
|
, TextConstants.scale
|
||||||
|
, floatWindowWidth
|
||||||
|
, floatWindowHeight
|
||||||
|
, r
|
||||||
|
, g
|
||||||
|
, b
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
val posX = startX + TC.xSpace
|
||||||
|
in
|
||||||
|
loop
|
||||||
|
( 0
|
||||||
|
, str
|
||||||
|
, posX
|
||||||
|
, startY
|
||||||
|
, endX
|
||||||
|
, [cursor, slash]
|
||||||
|
, floatWindowWidth
|
||||||
|
, floatWindowHeight
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -90,8 +90,8 @@ struct
|
|||||||
, cursorZ = 0.03
|
, cursorZ = 0.03
|
||||||
, highlightZ = 0.05
|
, highlightZ = 0.05
|
||||||
|
|
||||||
, startX = 5
|
, startX = startX
|
||||||
, startY = 5
|
, startY = startX
|
||||||
|
|
||||||
, scrollColumnStart = visualScrollColumn
|
, scrollColumnStart = visualScrollColumn
|
||||||
, scrollColumnEnd = width div TC.xSpace + visualScrollColumn
|
, scrollColumnEnd = width div TC.xSpace + visualScrollColumn
|
||||||
@@ -105,7 +105,7 @@ struct
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
let
|
let
|
||||||
val startX = (endX - TC.textLineWidth) div 2
|
val startX = (width - TC.textLineWidth) div 2
|
||||||
in
|
in
|
||||||
{ charR = 0.67
|
{ charR = 0.67
|
||||||
, charG = 0.51
|
, charG = 0.51
|
||||||
|
|||||||
2
shf.mlb
2
shf.mlb
@@ -41,7 +41,7 @@ fcore/text-builder/text-builder-utils.sml
|
|||||||
fcore/text-builder/text-builder-with-cursor.sml
|
fcore/text-builder/text-builder-with-cursor.sml
|
||||||
fcore/text-builder/text-builder-with-highlight.sml
|
fcore/text-builder/text-builder-with-highlight.sml
|
||||||
fcore/text-builder/normal-mode-text-builder.sml
|
fcore/text-builder/normal-mode-text-builder.sml
|
||||||
fcore/text-builder.sml
|
fcore/text-builder/search-bar.sml
|
||||||
|
|
||||||
fcore/cursor.sml
|
fcore/cursor.sml
|
||||||
fcore/text-scroll.sml
|
fcore/text-scroll.sml
|
||||||
|
|||||||
Reference in New Issue
Block a user