test19.nim 860 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. # --- Test 19. Use RichEditText node. --- #
  2. import
  3. strutils,
  4. nodesnim
  5. Window("hello world")
  6. var
  7. mainobj: SceneObj
  8. main = Scene("Main", mainobj)
  9. labelobj: RichEditTextObj
  10. label = RichEditText(labelobj)
  11. main.addChild(label)
  12. label.setSizeAnchor(1, 1)
  13. label.on_process =
  14. proc(self: NodePtr) =
  15. label.text.setColor(Color(1f, 1f, 1f))
  16. label.text.setUnderline(false)
  17. # Nim highlight
  18. var start_position = ($label.text).find("Nim")
  19. while start_position > -1:
  20. label.text.setColor(start_position, start_position+2, Color(0xaa99ffff'u32))
  21. start_position = ($label.text).find("Nim", start_position+2)
  22. # word underline
  23. if label.text.len() > 0:
  24. let (s, e) = label.getWordPositionUnderMouse()
  25. if s != -1:
  26. label.text.setUnderline(s, e, true)
  27. addScene(main)
  28. setMainScene("Main")
  29. windowLaunch()