Skip to content

Commit 5ecc517

Browse files
committed
Update to new typography.
1 parent 85c86d3 commit 5ecc517

File tree

3 files changed

+39
-8
lines changed

3 files changed

+39
-8
lines changed

fidget.nimble

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ srcDir = "src"
1010

1111
requires "nim >= 1.0.0"
1212
requires "chroma >= 0.1.3"
13-
requires "typography >= 0.3.3"
13+
requires "typography >= 0.4.0"
1414
requires "flippy >= 0.4.4"
1515
requires "vmath >= 0.3.1"
1616
requires "print >= 0.1.0"

src/fidget/opengl/context.nim

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,9 +335,35 @@ proc setVertColor(buf: var seq[uint8], i: int, color: ColorRGBA) =
335335
buf[i * 4 + 2] = color.b
336336
buf[i * 4 + 3] = color.a
337337

338-
func `*`(m: Mat4, v: Vec2): Vec2 =
338+
func `*`*(m: Mat4, v: Vec2): Vec2 =
339339
(m * vec3(v, 0.0)).xy
340340

341+
proc drawQuad*(
342+
ctx: Context,
343+
verts: array[4, Vec2],
344+
uvs: array[4, Vec2],
345+
colors: array[4, ColorRGBA],
346+
) =
347+
ctx.checkBatch()
348+
349+
let offset = ctx.quadCount * 4
350+
ctx.positions.data.setVert2(offset + 0, verts[0])
351+
ctx.positions.data.setVert2(offset + 1, verts[1])
352+
ctx.positions.data.setVert2(offset + 2, verts[2])
353+
ctx.positions.data.setVert2(offset + 3, verts[3])
354+
355+
ctx.uvs.data.setVert2(offset + 0, uvs[0])
356+
ctx.uvs.data.setVert2(offset + 1, uvs[1])
357+
ctx.uvs.data.setVert2(offset + 2, uvs[2])
358+
ctx.uvs.data.setVert2(offset + 3, uvs[3])
359+
360+
ctx.colors.data.setVertColor(offset + 0, colors[0])
361+
ctx.colors.data.setVertColor(offset + 1, colors[1])
362+
ctx.colors.data.setVertColor(offset + 2, colors[2])
363+
ctx.colors.data.setVertColor(offset + 3, colors[3])
364+
365+
inc ctx.quadCount
366+
341367
proc drawUvRect(ctx: Context, at, to: Vec2, uvAt, uvTo: Vec2, color: Color) =
342368
## Adds an image rect with a path to an ctx
343369
ctx.checkBatch()

src/fidget/openglbackend.nim

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,12 @@ proc focus*(keyboard: Keyboard, node: Node) =
5151
keyboard.onFocusNode = node
5252
keyboard.focusNode = node
5353

54+
var font = fonts[node.textStyle.fontFamily]
55+
font.size = node.textStyle.fontSize
56+
font.lineHeight = node.textStyle.lineHeight
5457
keyboard.input = node.text
5558
textBox = newTextBox(
56-
fonts[node.textStyle.fontFamily],
59+
font,
5760
int node.screenBox.w,
5861
int node.screenBox.h,
5962
node.text,
@@ -116,8 +119,8 @@ proc drawText(node: Node) =
116119
let editing = keyboard.focusNode == node
117120

118121
if editing:
119-
if textBox.size != node.box.wh:
120-
textBox.resize(node.box.wh)
122+
if textBox.size != node.screenBox.wh:
123+
textBox.resize(node.screenBox.wh)
121124
node.textLayout = textBox.layout
122125
ctx.saveTransform()
123126
ctx.translate(-textBox.scroll)
@@ -128,7 +131,7 @@ proc drawText(node: Node) =
128131

129132
# draw characters
130133
for glyphIdx, pos in node.textLayout:
131-
if pos.character notin font.glyphs:
134+
if pos.character notin font.typeface.glyphs:
132135
continue
133136
if pos.rune == Rune(32):
134137
# Don't draw space, even if font has a char for it.
@@ -162,7 +165,7 @@ proc drawText(node: Node) =
162165

163166
if hashFill notin ctx.entries:
164167
var
165-
glyph = font.glyphs[pos.character]
168+
glyph = font.typeface.glyphs[pos.character]
166169
glyphOffset: Vec2
167170
let glyphFill = font.getGlyphImage(
168171
glyph,
@@ -174,7 +177,7 @@ proc drawText(node: Node) =
174177

175178
if node.strokeWeight > 0 and hashStroke notin ctx.entries:
176179
var
177-
glyph = font.glyphs[pos.character]
180+
glyph = font.typeface.glyphs[pos.character]
178181
glyphOffset: Vec2
179182
let glyphFill = font.getGlyphImage(
180183
glyph,
@@ -323,6 +326,8 @@ proc setupFidget(
323326

324327
drawMain()
325328

329+
root.removeExtraChildren()
330+
326331
computeLayout(nil, root)
327332
computeScreenBox(nil, root)
328333

0 commit comments

Comments
 (0)