Mercurial > games > semicongine
diff 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 |
line wrap: on
line diff
--- a/tests/test_font.nim Sat Jan 27 21:08:31 2024 +0700 +++ b/tests/test_font.nim Sun Jan 28 00:41:11 2024 +0700 @@ -22,18 +22,19 @@ if engine.windowWasResized(): var winSize = engine.getWindow().size textbox.mesh.transform = scale(fontscale * (winSize[1] / winSize[0]), fontscale) - for c in [Key.A, Key.B, Key.C, Key.D, Key.E, Key.F, Key.G, Key.H, Key.I, - Key.J, Key.K, Key.L, Key.M, Key.N, Key.O, Key.P, Key.Q, Key.R, Key.S, - Key.T, Key.U, Key.V, Key.W, Key.X, Key.Y, Key.Z]: - if engine.keyWasPressed(c): - if engine.keyIsDown(ShiftL) or engine.keyIsDown(ShiftR): - textbox.text = textbox.text[0 ..< ^1] & ($c).toRunes & cursor - else: - textbox.text = textbox.text[0 ..< ^1] & ($c).toRunes[0].toLower() & cursor - if engine.keyWasPressed(Enter): - textbox.text = textbox.text[0 ..< ^1] & Rune('\n') & cursor - if engine.keyWasPressed(Space): - textbox.text = textbox.text[0 ..< ^1] & Rune(' ') & cursor + if textbox.text.len < textbox.maxLen - 1: + for c in [Key.A, Key.B, Key.C, Key.D, Key.E, Key.F, Key.G, Key.H, Key.I, + Key.J, Key.K, Key.L, Key.M, Key.N, Key.O, Key.P, Key.Q, Key.R, Key.S, + Key.T, Key.U, Key.V, Key.W, Key.X, Key.Y, Key.Z]: + if engine.keyWasPressed(c): + if engine.keyIsDown(ShiftL) or engine.keyIsDown(ShiftR): + textbox.text = textbox.text[0 ..< ^1] & ($c).toRunes & cursor + else: + textbox.text = textbox.text[0 ..< ^1] & ($c).toRunes[0].toLower() & cursor + if engine.keyWasPressed(Enter): + textbox.text = textbox.text[0 ..< ^1] & Rune('\n') & cursor + if engine.keyWasPressed(Space): + textbox.text = textbox.text[0 ..< ^1] & Rune(' ') & cursor if engine.keyWasPressed(Backspace) and textbox.text.len > 1: textbox.text = textbox.text[0 ..< ^2] & cursor engine.renderScene(scene)