/tutorial/vision/basic_examples/basic_events.e

http://github.com/tybor/Liberty · Specman e · 69 lines · 47 code · 8 blank · 14 comment · 1 complexity · 8c8d83dbef2836cc38e3d1da54114fc0 MD5 · raw file

  1. class BASIC_EVENTS
  2. -- This example show:
  3. -- how to add widgets into the window,
  4. -- how to use COLUMN_LAYOUT and it's border and spacing,
  5. -- how to register procedure to be called for each user action.
  6. inherit
  7. GRAPHIC
  8. -- Give access to constants (vision, colors...)
  9. creation {ANY}
  10. make
  11. feature {}
  12. toplevel_window: TOPLEVEL_WINDOW
  13. column_layout: COLUMN_LAYOUT
  14. make is
  15. local
  16. label: LABEL; horizontal_line: HORIZONTAL_LINE; button: BUTTON
  17. do
  18. create column_layout
  19. create toplevel_window.make(column_layout)
  20. -- minimal space between the border and objects inside
  21. column_layout.set_border(5)
  22. -- minimal space between each object inside
  23. column_layout.set_spacing(5)
  24. toplevel_window.set_title("Hello World")
  25. toplevel_window.set_background_color(white_color)
  26. toplevel_window.map
  27. -- put the window on the screen; may be done later
  28. -- register procedure to call on user requests on 'toplevel_window'
  29. toplevel_window.when_wheel_up(agent border(1))
  30. toplevel_window.when_wheel_down(agent border(-1))
  31. create label.make(U"Hello World ! Please, use the wheel.")
  32. toplevel_window.when_left_down(agent label.set_text(U"Hello World !"))
  33. toplevel_window.when_right_down(agent label.set_text(U"Use the wheel"))
  34. -- windows are containers, you add widgets into them
  35. toplevel_window.child_attach(label)
  36. create horizontal_line
  37. toplevel_window.child_attach(horizontal_line)
  38. create button.with_label(toplevel_window, U"Exit")
  39. -- register procedure to call on user requests on 'quit'
  40. button.when_left_clicked(agent vision.loop_stack.break)
  41. button.when_right_down(agent background(black_color))
  42. button.when_right_up(agent background(white_color))
  43. -- start the event loop. The event loop executes registred
  44. -- behavior for user actions.
  45. -- It will stop when break is called (vision.loop_stack.break).
  46. vision.start
  47. io.put_string("The end%N")
  48. end
  49. feature {}
  50. background (c: COLOR) is
  51. do
  52. toplevel_window.set_background_color(c)
  53. toplevel_window.refresh
  54. end
  55. border (i: INTEGER) is
  56. do
  57. if column_layout.border + i >= 0 then
  58. column_layout.set_border(column_layout.border + i)
  59. end
  60. end
  61. end -- class BASIC_EVENTS