iup_multi_box.e 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. class IUP_MULTI_BOX
  2. -- Creates a void container for composing elements in a irregular grid. It is
  3. -- a box that arranges the elements it contains from top to bottom and from
  4. -- left to right, by distributing the elements in lines or in columns. But its
  5. -- EXPAND attribute does not behave as a regular container, instead it behaves
  6. -- as a regular element expanding into the available space.
  7. --
  8. -- The child elements are added to the control just like a vbox and hbox,
  9. -- sequentially. Then they are distributed accordingly the ORIENTATION
  10. -- attribute. When ORIENTATION=HORIZONTAL children are distributed from left to
  11. -- right on the first line until the line does not fits more elements according
  12. -- to the multibox current width, then on the second line, and so on. When
  13. -- ORIENTATION=VERTICAL children are distributed from top to bottom on the
  14. -- first column until columns does not fits more elements according to the
  15. -- multibox current height, then on the second column, and so on.
  16. --
  17. -- Because of that its elements can overlap other elements in the dialog, so
  18. -- the ideal combination is to put the IUP_MULTI_BOX inside an IUP_SCROLL_BOX.
  19. --
  20. -- IMPORTANT: the actual element distribution in the container is done only
  21. -- after the natural size of the dialog is computed because it needs the
  22. -- current with or height to determine which elements will fit in the current
  23. -- space according to the orientation. The first time the multibox natural size
  24. -- is computed it returns simply the largest width and the highest height among
  25. -- the children. The next time it will use the size previously calculated with
  26. -- the line/column breaks, to avoid obtaining an outdated layout call "refresh"
  27. -- or "map" before showing the dialog (when the layout will be updated again).
  28. --
  29. -- It does not have a native representation.
  30. --
  31. -- Notes:
  32. --
  33. -- The box can be created with no elements and be dynamic filled using "append"
  34. -- or "insert".
  35. --
  36. -- The box will NOT expand its children in any condition.
  37. --
  38. -- The number of elements in a line when ORIENTATION=HORIZONTAL can be very
  39. -- different depending on the children sizes and line/column breaks. The same
  40. -- for elements in a column when ORIENTATION=VERTICAL.
  41. inherit
  42. IUP_CONTAINER
  43. IUP_WIDGET_EXPAND
  44. IUP_WIDGET_WID
  45. IUP_WIDGET_SIZE
  46. IUP_WIDGET_RASTERSIZE
  47. IUP_WIDGET_FONT
  48. IUP_WIDGET_CLIENTSIZE
  49. IUP_WIDGET_CLIENTOFFSET
  50. IUP_WIDGET_POSITION
  51. IUP_WIDGET_MAXMIN_SIZE
  52. IUP_WIDGET_NAME
  53. IUP_WIDGET_CUSTOM_ATTRIBUTES
  54. create {ANY}
  55. multi_box_empty,
  56. multi_box
  57. feature {ANY}
  58. multi_box_empty
  59. -- Create an empty multi box.
  60. local
  61. p, a_multi_box: POINTER
  62. do
  63. a_multi_box := int_multi_box_empty (p)
  64. set_widget(a_multi_box)
  65. end
  66. multi_box (col: ARRAY[IUP_WIDGET])
  67. -- Create a new multi box containing the list of widgets.
  68. local
  69. i: INTEGER; arg: ARRAY[POINTER]; s: IUP_WIDGET; a_multi_box: POINTER
  70. do
  71. i := col.count
  72. create arg.make_filled(default_pointer, 1, i + 1)
  73. i := 0
  74. across
  75. col as ic
  76. loop
  77. i := i + 1
  78. s := ic.item
  79. arg.put(s.widget, i)
  80. end
  81. a_multi_box := int_multi_box (get_pointer(arg.to_c))
  82. set_widget(a_multi_box)
  83. end
  84. -- Commands to handle attributes.
  85. set_child_max_size (width: INTEGER; height: INTEGER)
  86. -- (non inheritable): when defined limits the size of all children to a
  87. -- given maximum size. This affects each child size.
  88. require
  89. non_negative: width >= 0
  90. height >= 0
  91. local
  92. size: STRING
  93. do
  94. size := width.out
  95. size.append_string("x")
  96. size.append_string(height.out)
  97. iup_open.set_attribute(Current, "CHILDMAXSIZE", size)
  98. end
  99. set_child_min_size (width: INTEGER; height: INTEGER)
  100. -- (non inheritable): when defined limits the space occupied by a child
  101. -- to a given minimum size. Uses the format "widthxheight". This does not
  102. -- affects the children size.
  103. require
  104. non_negative: width >= 0
  105. height >= 0
  106. local
  107. size: STRING
  108. do
  109. size := width.out
  110. size.append_string("x")
  111. size.append_string(height.out)
  112. iup_open.set_attribute(Current, "CHILDMINSPACE", size)
  113. end
  114. set_vertical_gap (gap: INTEGER)
  115. -- Defines a vertical space in pixels between elements. Default: 0.
  116. require
  117. non_negative: gap >= 0
  118. do
  119. iup_open.set_attribute(Current, "GAPVERT", gap.out)
  120. end
  121. set_vertical_char_gap (gap: INTEGER)
  122. -- Defines a vertical space between elements in the same units of the
  123. -- SIZE attribute for the height. Default: 0.
  124. require
  125. non_negative: gap >= 0
  126. do
  127. iup_open.set_attribute(Current, "CGAPVERT", gap.out)
  128. end
  129. set_horizontal_gap (gap: INTEGER)
  130. -- Defines a horizontal space in pixels between elements. Default: 0.
  131. require
  132. non_negative: gap >= 0
  133. do
  134. iup_open.set_attribute(Current, "GAPHORIZ", gap.out)
  135. end
  136. set_horizontal_char_gap (gap: INTEGER)
  137. -- Defines a horizontal space between elements in the same units of the
  138. -- SIZE attribute for the width. Default: 0.
  139. require
  140. non_negative: gap >= 0
  141. do
  142. iup_open.set_attribute(Current, "CGAPHORIZ", gap.out)
  143. end
  144. set_vertical_ngap (gap: INTEGER)
  145. -- Like "set_vertical_gap" but non inheritable.
  146. require
  147. non_negative: gap >= 0
  148. do
  149. iup_open.set_attribute(Current, "NGAPVERT", gap.out)
  150. end
  151. set_vertical_char_ngap (gap: INTEGER)
  152. -- Like "set_vertical_char_gap" but non inheritable.
  153. require
  154. non_negative: gap >= 0
  155. do
  156. iup_open.set_attribute(Current, "NCGAPVERT", gap.out)
  157. end
  158. set_horizontal_ngap (gap: INTEGER)
  159. -- Like "set_horizontal_gap" but non inheritable.
  160. require
  161. non_negative: gap >= 0
  162. do
  163. iup_open.set_attribute(Current, "NGAPHORIZ", gap.out)
  164. end
  165. set_horizontal_char_ngap (gap: INTEGER)
  166. -- Like "set_horizontal_char_gap" but non inheritable.
  167. require
  168. non_negative: gap >= 0
  169. do
  170. iup_open.set_attribute(Current, "NCGAPHORIZ", gap.out)
  171. end
  172. set_margin (width: INTEGER; height: INTEGER)
  173. -- Defines a margin in pixels, width and height are integer values
  174. -- corresponding to the horizontal and vertical margins, respectively.
  175. -- Default: "0x0" (no margin).
  176. require
  177. non_negative: width >= 0
  178. height >= 0
  179. local
  180. size: STRING
  181. do
  182. size := width.out
  183. size.append_string("x")
  184. size.append_string(height.out)
  185. iup_open.set_attribute(Current, "MARGIN", size)
  186. end
  187. set_char_margin (width: INTEGER; height: INTEGER)
  188. -- Like "set_margin" but in the same units of the SIZE attribute.
  189. require
  190. non_negative: width >= 0
  191. height >= 0
  192. local
  193. size: STRING
  194. do
  195. size := width.out
  196. size.append_string("x")
  197. size.append_string(height.out)
  198. iup_open.set_attribute(Current, "CMARGIN", size)
  199. end
  200. set_nmargin (width: INTEGER; height: INTEGER)
  201. -- Like "set_margin" but non inheritable.
  202. require
  203. non_negative: width >= 0
  204. height >= 0
  205. local
  206. size: STRING
  207. do
  208. size := width.out
  209. size.append_string("x")
  210. size.append_string(height.out)
  211. iup_open.set_attribute(Current, "NMARGIN", size)
  212. end
  213. set_nchar_margin (width: INTEGER; height: INTEGER)
  214. -- Like "set_char_margin" but non inheritable.
  215. require
  216. non_negative: width >= 0
  217. height >= 0
  218. local
  219. size: STRING
  220. do
  221. size := width.out
  222. size.append_string("x")
  223. size.append_string(height.out)
  224. iup_open.set_attribute(Current, "NCMARGIN", size)
  225. end
  226. number_of_columns: INTEGER
  227. -- Returns the number of columns when orientation is vertical. Returns
  228. -- 0 otherwise.
  229. local
  230. str: STRING
  231. do
  232. str := iup_open.get_attribute(Current, "NUMCOL")
  233. Result := str.to_integer
  234. end
  235. number_of_lines: INTEGER
  236. -- Returns the number of lines when orientation is horizontal. Returns
  237. -- 0 otherwise.
  238. local
  239. str: STRING
  240. do
  241. str := iup_open.get_attribute(Current, "NUMLIN")
  242. Result := str.to_integer
  243. end
  244. set_vertical_orientation
  245. do
  246. iup_open.set_attribute(Current, "ORIENTATION", "VERTICAL")
  247. end
  248. set_horizontal_orientation
  249. -- The default value.
  250. do
  251. iup_open.set_attribute(Current, "ORIENTATION", "HORIZONTAL")
  252. end
  253. feature {NONE}
  254. -- Internals
  255. int_multi_box_empty (arguments: POINTER): POINTER
  256. external
  257. "C inline use %"eiffel-iup.h%""
  258. alias
  259. "return IupMultiBox ($arguments);"
  260. end
  261. int_multi_box (arguments: POINTER): POINTER
  262. external
  263. "C inline use %"eiffel-iup.h%""
  264. alias
  265. "return IupMultiBoxv ($arguments);"
  266. end
  267. end -- class IUP_MULTI_BOX
  268. -- The MIT License (MIT)
  269. -- Copyright (c) 2019, 2020 by German A. Arias
  270. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  271. -- of this software and associated documentation files (the "Software"), to deal
  272. -- in the Software without restriction, including without limitation the rights
  273. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  274. -- copies of the Software, and to permit persons to whom the Software is
  275. -- furnished to do so, subject to the following conditions:
  276. --
  277. -- The above copyright notice and this permission notice shall be included in
  278. -- all copies or substantial portions of the Software.
  279. --
  280. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  281. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  282. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  283. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  284. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  285. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  286. -- SOFTWARE.