example7.e 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. class EXAMPLE7
  2. -- This example show how use a expander, sn sbox and a tree.
  3. -- Also show how use the class IUP_CONFIG to store user preferences.
  4. insert
  5. IUP_INTERFACE
  6. create {ANY}
  7. make
  8. feature {ANY}
  9. cfg: IUP_CONFIG
  10. make
  11. local
  12. gui: IUP
  13. i: STRING
  14. b1, b2, b3, b4, b5: IUP_BUTTON
  15. sb: IUP_SBOX
  16. bx: IUP_BACKGROUND_BOX
  17. ex: IUP_EXPANDER
  18. tr: IUP_TREE
  19. h1, h2: IUP_HBOX
  20. v: IUP_VBOX
  21. w: IUP_DIALOG
  22. ri: INTEGER
  23. do
  24. gui := iup_open
  25. gui.load_images -- Load the predefined images at IUP stock.
  26. -- Create the buttons to the expander
  27. create b1.button("")
  28. b1.set_image("IUP_FileNew")
  29. create b2.button("")
  30. b2.set_image("IUP_FileOpen")
  31. create b3.button("")
  32. b3.set_image("IUP_FileSave")
  33. create h1.hbox({ARRAY[IUP_WIDGET] 1, << b1, b2, b3 >>})
  34. create bx.background_box(h1)
  35. create ex.expander(bx)
  36. ex.set_title("Buttons")
  37. ex.set_collapsed
  38. -- Create the buttons
  39. create b4.button("Button inside Sbox")
  40. b4.set_expand("YES")
  41. create b5.button("Other button")
  42. b5.set_expand("YES")
  43. -- The sbox
  44. create sb.sbox(b4)
  45. -- Put sb and b2 inside an horizontal box.
  46. create h2.hbox({ARRAY[IUP_WIDGET] 1, << sb, b5 >>})
  47. h2.set_gap(10)
  48. h2.set_margin(10, 10)
  49. -- Create the tree
  50. create tr.tree
  51. -- Put all inside a vertical box
  52. create v.vbox({ARRAY[IUP_WIDGET] 1, << ex, h2, tr >>})
  53. -- Load config file
  54. create cfg.config
  55. cfg.set_app_name("example7")
  56. ri := cfg.load
  57. -- Create the window.
  58. create w.dialog(v)
  59. w.set_title("Example 7")
  60. w.set_cb_close(agent close(?))
  61. if ri.is_equal(0) then
  62. cfg.show_dialog(w, "main")
  63. else
  64. i := w.show
  65. end
  66. -- Add items to the tree (should be do after map)
  67. tr.set_title_at("Figures", 0)
  68. tr.add_leaf_at("other", 0)
  69. tr.add_branch_at("triangle", 1)
  70. tr.add_leaf_at("equilateral", 2)
  71. tr.add_leaf_at("isoceles", 3)
  72. tr.add_leaf_at("scalenus", 4)
  73. tr.insert_branch_at("parallelogram", 2)
  74. tr.add_leaf_at("square", 6)
  75. tr.add_leaf_at("diamond", 7)
  76. tr.insert_branch_at("2D", 6)
  77. tr.insert_branch_at("3D", 9)
  78. gui.main_loop
  79. gui.close
  80. end
  81. close (dlg: IUP_DIALOG): STRING
  82. local
  83. i: INTEGER
  84. do
  85. cfg.save_dialog(dlg, "main")
  86. i := cfg.save
  87. -- We should destroy the config object.
  88. cfg.destroy
  89. Result := "IUP_DEFAULT"
  90. end
  91. end -- class EXAMPLE7