code_junkie

How to position editbox's cursor in shoes

Nov 13th, 2011
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. Shoes.app do
  2.  
  3. stack do
  4. p=para "After pressing 'search' a question will arise"
  5. box=edit_box
  6. box.text="Onenofnthenmostnstrikingndifferencesnbetweennancatnandnanlienisnthatnancatnhasnonlynnine lives."
  7. flow :margin_top=>0.1 do
  8. search=edit_line
  9.  
  10. button("search") do
  11. pos=box.text.index search.text
  12. y = box.text[0..pos].split.size-1 if pos
  13.  
  14. if not y.nil?
  15. #For example if you searched "only" then
  16. #cursor should jump/scroll to line 17.
  17. #
  18. #Anything there for cursor positioning,
  19. #like: box.cursor=[0,y]
  20. #
  21. p.text="How can I move editbox's cursor in line #{y+1}?"
  22. else
  23. alert "'#{search.text}' not found"
  24. end
  25. end
  26. end
  27. end
  28. end
  29.  
  30. rb_define_method(cEditBox, "text", CASTHOOK(shoes_edit_box_get_text), 0);
  31. rb_define_method(cEditBox, "text=", CASTHOOK(shoes_edit_box_set_text), 1);
  32. rb_define_method(cEditBox, "draw", CASTHOOK(shoes_edit_box_draw), 2);
  33. rb_define_method(cEditBox, "change", CASTHOOK(shoes_control_change), -1);
Add Comment
Please, Sign In to add comment