iup_normalizer.e 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. class IUP_NORMALIZER
  2. -- Creates a void container that does not affect the dialog layout. It acts by
  3. -- normalizing all the controls in a list so their natural size becomes the
  4. -- biggest natural size amongst them. All natural widths will be set to the
  5. -- biggest width, and all natural heights will be set to the biggest height.
  6. -- The controls of the list must be inside a valid container in the
  7. -- dialog.
  8. --
  9. -- It is NOT necessary to add the normalizer to a dialog hierarchy. Every time
  10. -- "set_normalize" is set, a normalization occurs. If the normalizer is
  11. -- added to a dialog hierarchy, then whenever the Natural size is calculated a
  12. -- normalization occurs, so you should add it to the hierarchy before the
  13. -- elements you want to normalize or its normalization will be not used.
  14. --
  15. -- The elements do NOT need to be children of the same parent, do NOT need to
  16. -- be mapped, and do NOT need to be in a complete hierarchy of a dialog.
  17. --
  18. -- The elements are NOT children of the normalizer. To add or remove elements
  19. -- use the add_control and delete_control attributes.
  20. --
  21. -- Notice that the set_normalizar_group (at controls) attribute can simplify a
  22. -- lot of the process of creating a normalizer, so you do not need to list
  23. -- several elements from different parts of the dialog.
  24. --
  25. -- Has the same effect as the set_normalize_size attribute of the IUP_VBOX and
  26. -- IUP_HBOX controls, but it can be used for elements with different parents,
  27. -- it changes the User size of the elements.
  28. inherit
  29. IUP_WIDGET
  30. create {ANY}
  31. normalizer_empty,
  32. normalizer
  33. feature {ANY}
  34. normalizer_empty
  35. local
  36. a_normalizer, p: POINTER
  37. do
  38. a_normalizer := int_normalizer (p)
  39. set_widget(a_normalizer)
  40. end
  41. normalizer (list: ARRAY[IUP_WIDGET])
  42. local
  43. i: INTEGER;
  44. arg: ARRAY[POINTER]; s: IUP_WIDGET; a_normalizer: POINTER
  45. do
  46. i := list.count
  47. create arg.make_filled(default_pointer, 1, i + 1)
  48. i := 0
  49. across
  50. list as ic
  51. loop
  52. i := i + 1
  53. s := ic.item
  54. arg.put(s.widget, i)
  55. end
  56. a_normalizer := int_normalizerv (get_pointer(arg.to_c))
  57. set_widget(a_normalizer)
  58. end
  59. -- Attributes
  60. set_normalize (value: STRING)
  61. -- (non inheritable): normalization direction. Can be HORIZONTAL,
  62. -- VERTICAL or BOTH. Default: HORIZONTAL
  63. require
  64. is_valid_normalize(value)
  65. do
  66. iup_open.set_attribute(Current, "NORMALIZE", value)
  67. end
  68. set_normalize_horizontal
  69. do
  70. set_normalize("HORIZONTAL")
  71. end
  72. set_normalize_vertical
  73. do
  74. set_normalize("VERTICAL")
  75. end
  76. set_normalize_both
  77. do
  78. set_normalize("BOTH")
  79. end
  80. -- Operations
  81. add_control (name: STRING)
  82. -- (non inheritable, write-only): Adds a control to the normalizer. The
  83. -- value passed must be the name of an element. Use set_widget_name
  84. -- to associate an element to a name.
  85. do
  86. iup_open.set_attribute(Current, "ADDCONTROL", name)
  87. end
  88. add_control_widget (wgt: IUP_WIDGET)
  89. -- (non inheritable, write-only): Adds a control to the normalizer.
  90. do
  91. iup_open.set_attribute_widget(Current, "ADDCONTROL_HANDLE", wgt)
  92. end
  93. delete_control (name: STRING)
  94. -- (non inheritable, write-only): Removes a control from the normalizer.
  95. -- The value passed must be the name of an element. Use
  96. -- set_widget_name to associate an element to a name.
  97. do
  98. iup_open.set_attribute(Current, "DELCONTROL", name)
  99. end
  100. delete_control_widget (wgt: IUP_WIDGET)
  101. -- (non inheritable, write-only): Removes a control from the normalizer.
  102. do
  103. iup_open.set_attribute_widget(Current, "DELCONTROL_HANDLE", wgt)
  104. end
  105. -- Validations
  106. is_valid_normalize (value: STRING): BOOLEAN
  107. do
  108. if value.is_equal("HORIZONTAL") or
  109. value.is_equal("VERTICAL") or
  110. value.is_equal("BOTH") then
  111. Result := True
  112. else
  113. Result := False
  114. end
  115. end
  116. feature {NONE}
  117. -- Internal
  118. int_normalizer (arguments: POINTER): POINTER
  119. external
  120. "C inline use %"eiffel-iup.h%""
  121. alias
  122. "return IupNormalizer ($arguments);"
  123. end
  124. int_normalizerv (arguments: POINTER): POINTER
  125. external
  126. "C inline use %"eiffel-iup.h%""
  127. alias
  128. "return IupNormalizerv ($arguments);"
  129. end
  130. end
  131. -- The MIT License (MIT)
  132. -- Copyright (c) 2016, 2019, 2020 by German A. Arias
  133. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  134. -- of this software and associated documentation files (the "Software"), to deal
  135. -- in the Software without restriction, including without limitation the rights
  136. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  137. -- copies of the Software, and to permit persons to whom the Software is
  138. -- furnished to do so, subject to the following conditions:
  139. --
  140. -- The above copyright notice and this permission notice shall be included in
  141. -- all copies or substantial portions of the Software.
  142. --
  143. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  144. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  145. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  146. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  147. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  148. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  149. -- SOFTWARE.