Rename HorizontalAlignment, VerticalAlignment and TextCase enum.

This commit is contained in:
treeform 2022-02-12 10:51:14 -08:00
parent 9fdb3b8b0d
commit 65b8dad89b
2 changed files with 49 additions and 49 deletions

View file

@ -37,20 +37,20 @@ type
selectionRects*: seq[Rect] ## The selection rects for each glyph. selectionRects*: seq[Rect] ## The selection rects for each glyph.
HorizontalAlignment* = enum HorizontalAlignment* = enum
haLeft AlignLeft
haCenter AlignCenter
haRight AlignRight
VerticalAlignment* = enum VerticalAlignment* = enum
vaTop AlignTop
vaMiddle AlignMiddle
vaBottom AlignBottom
TextCase* = enum TextCase* = enum
tcNormal NormalCase
tcUpper Uppercase
tcLower Lowercase
tcTitle TitleCase
# tcSmallCaps # tcSmallCaps
# tcSmallCapsForced # tcSmallCapsForced
@ -208,15 +208,15 @@ proc newSpan*(text: string, font: Font): Span {.raises: [].} =
proc convertTextCase(runes: var seq[Rune], textCase: TextCase) = proc convertTextCase(runes: var seq[Rune], textCase: TextCase) =
case textCase: case textCase:
of tcNormal: of NormalCase:
discard discard
of tcUpper: of Uppercase:
for rune in runes.mitems: for rune in runes.mitems:
rune = rune.toUpper() rune = rune.toUpper()
of tcLower: of Lowercase:
for rune in runes.mitems: for rune in runes.mitems:
rune = rune.toLower() rune = rune.toLower()
of tcTitle: of TitleCase:
var prevRune = SP var prevRune = SP
for rune in runes.mitems: for rune in runes.mitems:
if prevRune.isWhiteSpace: if prevRune.isWhiteSpace:
@ -229,8 +229,8 @@ proc canWrap(rune: Rune): bool {.inline.} =
proc typeset*( proc typeset*(
spans: seq[Span], spans: seq[Span],
bounds = vec2(0, 0), bounds = vec2(0, 0),
hAlign = haLeft, hAlign = AlignLeft,
vAlign = vaTop, vAlign = AlignTop,
wrap = true wrap = true
): Arrangement {.raises: [].} = ): Arrangement {.raises: [].} =
## Lays out the character glyphs and returns the arrangement. ## Lays out the character glyphs and returns the arrangement.
@ -325,7 +325,7 @@ proc typeset*(
result.lines[^1][1] = result.runes.len - 1 result.lines[^1][1] = result.runes.len - 1
if hAlign != haLeft: if hAlign != AlignLeft:
# Since horizontal alignment adjustments are different for each line, # Since horizontal alignment adjustments are different for each line,
# find the start and stop of each line of text. # find the start and stop of each line of text.
for (start, stop) in result.lines: for (start, stop) in result.lines:
@ -337,11 +337,11 @@ proc typeset*(
var xAdjustment: float32 var xAdjustment: float32
case hAlign: case hAlign:
of haLeft: of AlignLeft:
discard discard
of haCenter: of AlignCenter:
xAdjustment = (bounds.x - furthestX) / 2 xAdjustment = (bounds.x - furthestX) / 2
of haRight: of AlignRight:
xAdjustment = bounds.x - furthestX xAdjustment = bounds.x - furthestX
if xAdjustment != 0: if xAdjustment != 0:
@ -415,18 +415,18 @@ proc typeset*(
baseline - round(font.typeface.ascent * font.scale) baseline - round(font.typeface.ascent * font.scale)
result.selectionRects[runeIndex].h = lineHeight result.selectionRects[runeIndex].h = lineHeight
if vAlign != vaTop: if vAlign != AlignTop:
let let
finalSelectionRect = result.selectionRects[^1] finalSelectionRect = result.selectionRects[^1]
furthestY = finalSelectionRect.y + finalSelectionRect.h furthestY = finalSelectionRect.y + finalSelectionRect.h
var yAdjustment: float32 var yAdjustment: float32
case vAlign: case vAlign:
of vaTop: of AlignTop:
discard discard
of vaMiddle: of AlignMiddle:
yAdjustment = round((bounds.y - furthestY) / 2) yAdjustment = round((bounds.y - furthestY) / 2)
of vaBottom: of AlignBottom:
yAdjustment = bounds.y - furthestY yAdjustment = bounds.y - furthestY
if yAdjustment != 0: if yAdjustment != 0:
@ -450,8 +450,8 @@ proc typeset*(
font: Font, font: Font,
text: string, text: string,
bounds = vec2(0, 0), bounds = vec2(0, 0),
hAlign = haLeft, hAlign = AlignLeft,
vAlign = vaTop, vAlign = AlignTop,
wrap = true wrap = true
): Arrangement {.inline, raises: [].} = ): Arrangement {.inline, raises: [].} =
## Lays out the character glyphs and returns the arrangement. ## Lays out the character glyphs and returns the arrangement.
@ -596,8 +596,8 @@ proc fillText*(
text: string, text: string,
transform = mat3(), transform = mat3(),
bounds = vec2(0, 0), bounds = vec2(0, 0),
hAlign = haLeft, hAlign = AlignLeft,
vAlign = vaTop vAlign = AlignTop
) {.inline, raises: [PixieError].} = ) {.inline, raises: [PixieError].} =
## Typesets and fills the text. Optional parameters: ## Typesets and fills the text. Optional parameters:
## transform: translation or matrix to apply ## transform: translation or matrix to apply
@ -636,8 +636,8 @@ proc strokeText*(
transform = mat3(), transform = mat3(),
strokeWidth: float32 = 1.0, strokeWidth: float32 = 1.0,
bounds = vec2(0, 0), bounds = vec2(0, 0),
hAlign = haLeft, hAlign = AlignLeft,
vAlign = vaTop, vAlign = AlignTop,
lineCap = ButtCap, lineCap = ButtCap,
lineJoin = MiterJoin, lineJoin = MiterJoin,
miterLimit = defaultMiterLimit, miterLimit = defaultMiterLimit,

View file

@ -223,7 +223,7 @@ block:
font, font,
"a b c d e f g h i j k l m n o p", "a b c d e f g h i j k l m n o p",
bounds = vec2(200, 0), bounds = vec2(200, 0),
hAlign = haRight hAlign = AlignRight
) )
doDiff(image, "basic10") doDiff(image, "basic10")
@ -588,72 +588,72 @@ block:
font, font,
"TopLeft", "TopLeft",
bounds = image.wh, bounds = image.wh,
hAlign = haLeft, hAlign = AlignLeft,
vAlign = vaTop vAlign = AlignTop
) )
image.fillText( image.fillText(
font, font,
"TopCenter", "TopCenter",
bounds = image.wh, bounds = image.wh,
hAlign = haCenter, hAlign = AlignCenter,
vAlign = vaTop vAlign = AlignTop
) )
image.fillText( image.fillText(
font, font,
"TopRight", "TopRight",
bounds = image.wh, bounds = image.wh,
hAlign = haRight, hAlign = AlignRight,
vAlign = vaTop vAlign = AlignTop
) )
image.fillText( image.fillText(
font, font,
"MiddleLeft", "MiddleLeft",
bounds = image.wh, bounds = image.wh,
hAlign = haLeft, hAlign = AlignLeft,
vAlign = vaMiddle vAlign = AlignMiddle
) )
image.fillText( image.fillText(
font, font,
"MiddleCenter", "MiddleCenter",
bounds = image.wh, bounds = image.wh,
hAlign = haCenter, hAlign = AlignCenter,
vAlign = vaMiddle vAlign = AlignMiddle
) )
image.fillText( image.fillText(
font, font,
"MiddleRight", "MiddleRight",
bounds = image.wh, bounds = image.wh,
hAlign = haRight, hAlign = AlignRight,
vAlign = vaMiddle vAlign = AlignMiddle
) )
image.fillText( image.fillText(
font, font,
"BottomLeft", "BottomLeft",
bounds = image.wh, bounds = image.wh,
hAlign = haLeft, hAlign = AlignLeft,
vAlign = vaBottom vAlign = AlignBottom
) )
image.fillText( image.fillText(
font, font,
"BottomCenter", "BottomCenter",
bounds = image.wh, bounds = image.wh,
hAlign = haCenter, hAlign = AlignCenter,
vAlign = vaBottom vAlign = AlignBottom
) )
image.fillText( image.fillText(
font, font,
"BottomRight", "BottomRight",
bounds = image.wh, bounds = image.wh,
hAlign = haRight, hAlign = AlignRight,
vAlign = vaBottom vAlign = AlignBottom
) )
doDiff(image, "alignments") doDiff(image, "alignments")