comparison tests/test_font.nim @ 417:b032768df631

add: alignment for text boxes
author Sam <sam@basx.dev>
date Sun, 28 Jan 2024 00:41:11 +0700
parents 73cca428e27a
children 009d93d69170
comparison
equal deleted inserted replaced
416:73cca428e27a 417:b032768df631
20 let cursor = Rune('_') 20 let cursor = Rune('_')
21 while engine.updateInputs() == Running and not engine.keyIsDown(Escape): 21 while engine.updateInputs() == Running and not engine.keyIsDown(Escape):
22 if engine.windowWasResized(): 22 if engine.windowWasResized():
23 var winSize = engine.getWindow().size 23 var winSize = engine.getWindow().size
24 textbox.mesh.transform = scale(fontscale * (winSize[1] / winSize[0]), fontscale) 24 textbox.mesh.transform = scale(fontscale * (winSize[1] / winSize[0]), fontscale)
25 for c in [Key.A, Key.B, Key.C, Key.D, Key.E, Key.F, Key.G, Key.H, Key.I, 25 if textbox.text.len < textbox.maxLen - 1:
26 Key.J, Key.K, Key.L, Key.M, Key.N, Key.O, Key.P, Key.Q, Key.R, Key.S, 26 for c in [Key.A, Key.B, Key.C, Key.D, Key.E, Key.F, Key.G, Key.H, Key.I,
27 Key.T, Key.U, Key.V, Key.W, Key.X, Key.Y, Key.Z]: 27 Key.J, Key.K, Key.L, Key.M, Key.N, Key.O, Key.P, Key.Q, Key.R, Key.S,
28 if engine.keyWasPressed(c): 28 Key.T, Key.U, Key.V, Key.W, Key.X, Key.Y, Key.Z]:
29 if engine.keyIsDown(ShiftL) or engine.keyIsDown(ShiftR): 29 if engine.keyWasPressed(c):
30 textbox.text = textbox.text[0 ..< ^1] & ($c).toRunes & cursor 30 if engine.keyIsDown(ShiftL) or engine.keyIsDown(ShiftR):
31 else: 31 textbox.text = textbox.text[0 ..< ^1] & ($c).toRunes & cursor
32 textbox.text = textbox.text[0 ..< ^1] & ($c).toRunes[0].toLower() & cursor 32 else:
33 if engine.keyWasPressed(Enter): 33 textbox.text = textbox.text[0 ..< ^1] & ($c).toRunes[0].toLower() & cursor
34 textbox.text = textbox.text[0 ..< ^1] & Rune('\n') & cursor 34 if engine.keyWasPressed(Enter):
35 if engine.keyWasPressed(Space): 35 textbox.text = textbox.text[0 ..< ^1] & Rune('\n') & cursor
36 textbox.text = textbox.text[0 ..< ^1] & Rune(' ') & cursor 36 if engine.keyWasPressed(Space):
37 textbox.text = textbox.text[0 ..< ^1] & Rune(' ') & cursor
37 if engine.keyWasPressed(Backspace) and textbox.text.len > 1: 38 if engine.keyWasPressed(Backspace) and textbox.text.len > 1:
38 textbox.text = textbox.text[0 ..< ^2] & cursor 39 textbox.text = textbox.text[0 ..< ^2] & cursor
39 engine.renderScene(scene) 40 engine.renderScene(scene)
40 engine.destroy() 41 engine.destroy()
41 42