iup_widget_maxmin_size.e 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. deferred class IUP_WIDGET_MAXMIN_SIZE
  2. -- Commands to handle the attributes related with max/min size.
  3. inherit
  4. IUP_WIDGET_INTERNALS
  5. insert
  6. IUP_INTERFACE
  7. feature {ANY}
  8. set_maxsize (width: INTEGER; height: INTEGER)
  9. -- Specifies the element maximum size in pixels during the layout
  10. -- process.
  11. require
  12. non_negative: width >= 0
  13. height >= 0
  14. is_valid_maxsize(width, height)
  15. local
  16. size: STRING
  17. do
  18. size := width.to_string
  19. size.append_string("x")
  20. size.append_string(height.to_string)
  21. iup_open.set_attribute(Current, "MAXSIZE", size)
  22. end
  23. get_maxsize: TUPLE[INTEGER, INTEGER]
  24. -- Return the maximum size of the element.
  25. local
  26. size: STRING
  27. do
  28. size := iup_open.get_attribute(Current, "MAXSIZE")
  29. Result := components_of_size(size)
  30. end
  31. set_minsize (width: INTEGER; height: INTEGER)
  32. -- Specifies the element minimum size in pixels during the layout process.
  33. require
  34. non_negative: width >= 0
  35. height >= 0
  36. is_valid_minsize(width, height)
  37. local
  38. size: STRING
  39. do
  40. size := width.to_string
  41. size.append_string("x")
  42. size.append_string(height.to_string)
  43. iup_open.set_attribute(Current, "MINSIZE", size)
  44. end
  45. get_minsize: TUPLE[INTEGER, INTEGER]
  46. -- Return the minimum size of the element.
  47. local
  48. size: STRING
  49. do
  50. size := iup_open.get_attribute(Current, "MINSIZE")
  51. Result := components_of_size(size)
  52. end
  53. feature {}
  54. is_valid_maxsize (w, h: INTEGER): BOOLEAN
  55. local
  56. mins: TUPLE[INTEGER, INTEGER]
  57. do
  58. mins := get_minsize
  59. if mins.item_1 <= w and then
  60. mins.item_2 <= h then
  61. Result := True
  62. else
  63. Result := False
  64. end
  65. end
  66. is_valid_minsize (w, h: INTEGER): BOOLEAN
  67. local
  68. maxs: TUPLE[INTEGER, INTEGER]
  69. do
  70. maxs := get_maxsize
  71. if maxs.item_1 >= w and then
  72. maxs.item_2 >= h then
  73. Result := True
  74. else
  75. Result := False
  76. end
  77. end
  78. end
  79. -- The MIT License (MIT)
  80. -- Copyright (c) 2016 by German A. Arias
  81. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  82. -- of this software and associated documentation files (the "Software"), to deal
  83. -- in the Software without restriction, including without limitation the rights
  84. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  85. -- copies of the Software, and to permit persons to whom the Software is
  86. -- furnished to do so, subject to the following conditions:
  87. --
  88. -- The above copyright notice and this permission notice shall be included in
  89. -- all copies or substantial portions of the Software.
  90. --
  91. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  92. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  93. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  94. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  95. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  96. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  97. -- SOFTWARE.