/tutorial/vision/layout/fixed_widgets.e

http://github.com/tybor/Liberty · Specman e · 116 lines · 91 code · 15 blank · 10 comment · 0 complexity · ae2a4160c6f5946c1e9191cd97a4a178 MD5 · raw file

  1. class FIXED_WIDGETS
  2. --
  3. -- This example show how standards layouts (row/column) handle fixed size widgets.
  4. --
  5. -- See also WIDGET for more information on size.
  6. --
  7. inherit
  8. GRAPHIC
  9. creation {ANY}
  10. make
  11. feature {}
  12. toplevel_window: TOPLEVEL_WINDOW
  13. layouts: ARRAY[ROW_LAYOUT]
  14. make is
  15. local
  16. container: CONTAINER; one, two, three: UNICODE_STRING
  17. do
  18. one := U"Button ONE"
  19. two := U"Button TWO"
  20. three := U"Button THREE"
  21. create toplevel_window
  22. -- The default layout is column.
  23. toplevel_window.set_title("Buttons example")
  24. toplevel_window.set_background_color(white_color)
  25. toplevel_window.map
  26. create layouts.make(1, 0)
  27. -- First line: 3 buttons, automatically spaced
  28. container := new_container
  29. new_button(container, one)
  30. new_button(container, two)
  31. new_button(container, three)
  32. -- Second line: 1 space before the 3 buttons
  33. container := new_container
  34. layouts.last.insert_button_space
  35. new_button(container, one)
  36. new_button(container, two)
  37. new_button(container, three)
  38. -- Third line: 2 spaces (at the begining and at the end)
  39. container := new_container
  40. layouts.last.insert_button_space
  41. new_button(container, one)
  42. new_button(container, two)
  43. new_button(container, three)
  44. layouts.last.insert_button_space
  45. -- Fourth line: 1 space to separate buttons in 2 groups
  46. container := new_container
  47. new_button(container, one)
  48. layouts.last.insert_button_space
  49. new_button(container, two)
  50. new_button(container, three)
  51. toplevel_window.when_left_down(agent increase_border)
  52. toplevel_window.when_right_down(agent increase_spacing)
  53. toplevel_window.when_middle_down(agent vision.loop_stack.break)
  54. vision.start
  55. io.put_string("The end%N")
  56. end
  57. new_container: CONTAINER is
  58. local
  59. layout: ROW_LAYOUT
  60. do
  61. create layout
  62. layouts.add_last(layout)
  63. create Result.make_layout(toplevel_window, layout)
  64. Result.set_x_expand(True)
  65. Result.set_y_expand(True)
  66. end
  67. increase_border is
  68. local
  69. i: INTEGER
  70. do
  71. from
  72. i := layouts.lower
  73. until
  74. i > layouts.upper
  75. loop
  76. layouts.item(i).set_border(layouts.item(i).border + 1)
  77. i := i + 1
  78. end
  79. end
  80. increase_spacing is
  81. local
  82. i: INTEGER
  83. do
  84. from
  85. i := layouts.lower
  86. until
  87. i > layouts.upper
  88. loop
  89. layouts.item(i).set_spacing(layouts.item(i).spacing + 1)
  90. i := i + 1
  91. end
  92. end
  93. new_button (container: CONTAINER; text: UNICODE_STRING) is
  94. local
  95. button: BUTTON
  96. do
  97. create button.with_label(container, text)
  98. button.when_left_clicked(agent io.put_string(once "Left click on %"" + text.to_utf8 + once "%"%N"))
  99. button.when_right_clicked(agent vision.loop_stack.break)
  100. end
  101. end -- class FIXED_WIDGETS