iup_multi_box.e 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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. iterator: ITERATOR[IUP_WIDGET]; i: INTEGER; arg: NATIVE_ARRAY[POINTER]; s: IUP_WIDGET; a_multi_box: POINTER
  70. do
  71. i := col.count
  72. arg := arg.calloc(i)
  73. iterator := col.new_iterator
  74. i := 0
  75. from
  76. iterator.start
  77. until
  78. iterator.is_off
  79. loop
  80. s := iterator.item
  81. arg.put(s.widget, i)
  82. iterator.next
  83. i := i + 1
  84. end
  85. a_multi_box := int_multi_box (arg.to_external)
  86. set_widget(a_multi_box)
  87. end
  88. -- Commands to handle attributes.
  89. set_child_max_size (width: INTEGER; height: INTEGER)
  90. -- (non inheritable): when defined limits the size of all children to a
  91. -- given maximum size. This affects each child size.
  92. require
  93. non_negative: width >= 0
  94. height >= 0
  95. local
  96. size: STRING
  97. do
  98. size := width.to_string
  99. size.append_string("x")
  100. size.append_string(height.to_string)
  101. iup_open.set_attribute(Current, "CHILDMAXSIZE", size)
  102. end
  103. set_child_min_size (width: INTEGER; height: INTEGER)
  104. -- (non inheritable): when defined limits the space occupied by a child
  105. -- to a given minimum size. Uses the format "widthxheight". This does not
  106. -- affects the children size.
  107. require
  108. non_negative: width >= 0
  109. height >= 0
  110. local
  111. size: STRING
  112. do
  113. size := width.to_string
  114. size.append_string("x")
  115. size.append_string(height.to_string)
  116. iup_open.set_attribute(Current, "CHILDMINSPACE", size)
  117. end
  118. set_vertical_gap (gap: INTEGER)
  119. -- Defines a vertical space in pixels between elements. Default: 0.
  120. require
  121. non_negative: gap >= 0
  122. do
  123. iup_open.set_attribute(Current, "GAPVERT", gap.to_string)
  124. end
  125. set_vertical_char_gap (gap: INTEGER)
  126. -- Defines a vertical space between elements in the same units of the
  127. -- SIZE attribute for the height. Default: 0.
  128. require
  129. non_negative: gap >= 0
  130. do
  131. iup_open.set_attribute(Current, "CGAPVERT", gap.to_string)
  132. end
  133. set_horizontal_gap (gap: INTEGER)
  134. -- Defines a horizontal space in pixels between elements. Default: 0.
  135. require
  136. non_negative: gap >= 0
  137. do
  138. iup_open.set_attribute(Current, "GAPHORIZ", gap.to_string)
  139. end
  140. set_horizontal_char_gap (gap: INTEGER)
  141. -- Defines a horizontal space between elements in the same units of the
  142. -- SIZE attribute for the width. Default: 0.
  143. require
  144. non_negative: gap >= 0
  145. do
  146. iup_open.set_attribute(Current, "CGAPHORIZ", gap.to_string)
  147. end
  148. set_vertical_ngap (gap: INTEGER)
  149. -- Like "set_vertical_gap" but non inheritable.
  150. require
  151. non_negative: gap >= 0
  152. do
  153. iup_open.set_attribute(Current, "NGAPVERT", gap.to_string)
  154. end
  155. set_vertical_char_ngap (gap: INTEGER)
  156. -- Like "set_vertical_char_gap" but non inheritable.
  157. require
  158. non_negative: gap >= 0
  159. do
  160. iup_open.set_attribute(Current, "NCGAPVERT", gap.to_string)
  161. end
  162. set_horizontal_ngap (gap: INTEGER)
  163. -- Like "set_horizontal_gap" but non inheritable.
  164. require
  165. non_negative: gap >= 0
  166. do
  167. iup_open.set_attribute(Current, "NGAPHORIZ", gap.to_string)
  168. end
  169. set_horizontal_char_ngap (gap: INTEGER)
  170. -- Like "set_horizontal_char_gap" but non inheritable.
  171. require
  172. non_negative: gap >= 0
  173. do
  174. iup_open.set_attribute(Current, "NCGAPHORIZ", gap.to_string)
  175. end
  176. set_margin (width: INTEGER; height: INTEGER)
  177. -- Defines a margin in pixels, width and height are integer values
  178. -- corresponding to the horizontal and vertical margins, respectively.
  179. -- Default: "0x0" (no margin).
  180. require
  181. non_negative: width >= 0
  182. height >= 0
  183. local
  184. size: STRING
  185. do
  186. size := width.to_string
  187. size.append_string("x")
  188. size.append_string(height.to_string)
  189. iup_open.set_attribute(Current, "MARGIN", size)
  190. end
  191. set_char_margin (width: INTEGER; height: INTEGER)
  192. -- Like "set_margin" but in the same units of the SIZE attribute.
  193. require
  194. non_negative: width >= 0
  195. height >= 0
  196. local
  197. size: STRING
  198. do
  199. size := width.to_string
  200. size.append_string("x")
  201. size.append_string(height.to_string)
  202. iup_open.set_attribute(Current, "CMARGIN", size)
  203. end
  204. set_nmargin (width: INTEGER; height: INTEGER)
  205. -- Like "set_margin" but non inheritable.
  206. require
  207. non_negative: width >= 0
  208. height >= 0
  209. local
  210. size: STRING
  211. do
  212. size := width.to_string
  213. size.append_string("x")
  214. size.append_string(height.to_string)
  215. iup_open.set_attribute(Current, "NMARGIN", size)
  216. end
  217. set_nchar_margin (width: INTEGER; height: INTEGER)
  218. -- Like "set_char_margin" but non inheritable.
  219. require
  220. non_negative: width >= 0
  221. height >= 0
  222. local
  223. size: STRING
  224. do
  225. size := width.to_string
  226. size.append_string("x")
  227. size.append_string(height.to_string)
  228. iup_open.set_attribute(Current, "NCMARGIN", size)
  229. end
  230. number_of_columns: INTEGER
  231. -- Returns the number of columns when orientation is vertical. Returns
  232. -- 0 otherwise.
  233. local
  234. str: STRING
  235. do
  236. str := iup_open.get_attribute(Current, "NUMCOL")
  237. Result := str.to_integer
  238. end
  239. number_of_lines: INTEGER
  240. -- Returns the number of lines when orientation is horizontal. Returns
  241. -- 0 otherwise.
  242. local
  243. str: STRING
  244. do
  245. str := iup_open.get_attribute(Current, "NUMLIN")
  246. Result := str.to_integer
  247. end
  248. set_vertical_orientation
  249. do
  250. iup_open.set_attribute(Current, "ORIENTATION", "VERTICAL")
  251. end
  252. set_horizontal_orientation
  253. -- The default value.
  254. do
  255. iup_open.set_attribute(Current, "ORIENTATION", "HORIZONTAL")
  256. end
  257. feature {}
  258. -- Internals
  259. int_multi_box_empty (arguments: POINTER): POINTER
  260. external "plug_in"
  261. alias "{
  262. location: "${sys}/plugins"
  263. module_name: "iup"
  264. feature_name: "IupMultiBox"
  265. }"
  266. end
  267. int_multi_box (arguments: POINTER): POINTER
  268. external "plug_in"
  269. alias "{
  270. location: "${sys}/plugins"
  271. module_name: "iup"
  272. feature_name: "IupMultiBoxv"
  273. }"
  274. end
  275. end -- class IUP_MULTI_BOX
  276. -- The MIT License (MIT)
  277. -- Copyright (c) 2019 by German A. Arias
  278. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  279. -- of this software and associated documentation files (the "Software"), to deal
  280. -- in the Software without restriction, including without limitation the rights
  281. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  282. -- copies of the Software, and to permit persons to whom the Software is
  283. -- furnished to do so, subject to the following conditions:
  284. --
  285. -- The above copyright notice and this permission notice shall be included in
  286. -- all copies or substantial portions of the Software.
  287. --
  288. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  289. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  290. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  291. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  292. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  293. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  294. -- SOFTWARE.