1
0

Helios-Layout.st 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. Smalltalk current createPackage: 'Helios-Layout' properties: #{}!
  2. Widget subclass: #HLContainer
  3. instanceVariableNames: 'splitter'
  4. package: 'Helios-Layout'!
  5. !HLContainer methodsFor: 'accessing'!
  6. splitter
  7. ^ splitter
  8. !
  9. splitter: aSplitter
  10. splitter := aSplitter
  11. ! !
  12. !HLContainer methodsFor: 'rendering'!
  13. renderOn: html
  14. html div
  15. id: 'container';
  16. with: self splitter.
  17. (window jQuery: window) bind: 'resize' do: [ self splitter resize ]
  18. ! !
  19. !HLContainer class methodsFor: 'instance creation'!
  20. with: aSplitter
  21. ^ self new
  22. splitter: aSplitter;
  23. yourself
  24. ! !
  25. Widget subclass: #HLSplitter
  26. instanceVariableNames: 'firstWidget secondWidget firstPane secondPane splitter'
  27. package: 'Helios-Layout'!
  28. !HLSplitter methodsFor: 'accessing'!
  29. cssClass
  30. ^ 'splitter'
  31. !
  32. firstWidget
  33. ^ firstWidget
  34. !
  35. firstWidget: aWidget
  36. firstWidget := aWidget
  37. !
  38. secondWidget
  39. ^ secondWidget
  40. !
  41. secondWidget: aWidget
  42. secondWidget := aWidget
  43. ! !
  44. !HLSplitter methodsFor: 'rendering'!
  45. panesCssClass
  46. ^ 'panes'
  47. !
  48. renderOn: html
  49. html div class: self panesCssClass; with: [
  50. firstPane := html div class: 'pane'; with: self firstWidget.
  51. splitter := html div class: self cssClass.
  52. secondPane := html div class: 'pane'; with: self secondWidget ].
  53. self
  54. setupSplitter;
  55. resize
  56. !
  57. resize
  58. self firstWidget isHeliosSplitter ifTrue: [ self firstWidget resize ].
  59. self secondWidget isHeliosSplitter ifTrue: [ self secondWidget resize ]
  60. !
  61. setupSplitter
  62. ! !
  63. !HLSplitter methodsFor: 'testing'!
  64. isHeliosSplitter
  65. ^ true
  66. ! !
  67. !HLSplitter class methodsFor: 'instance creation'!
  68. with: aWidget with: anotherWidget
  69. ^ self new
  70. firstWidget: aWidget;
  71. secondWidget: anotherWidget;
  72. yourself
  73. ! !
  74. HLSplitter subclass: #HLHorizontalSplitter
  75. instanceVariableNames: ''
  76. package: 'Helios-Layout'!
  77. !HLHorizontalSplitter methodsFor: 'accessing'!
  78. cssClass
  79. ^ super cssClass, ' horizontal'
  80. !
  81. panesCssClass
  82. ^ super panesCssClass, ' horizontal'
  83. ! !
  84. !HLHorizontalSplitter methodsFor: 'actions'!
  85. resize
  86. self resize: splitter asJQuery offset top
  87. !
  88. resize: anInteger
  89. | container position |
  90. container := firstPane asJQuery parent.
  91. position := anInteger - container offset top.
  92. firstPane asJQuery height: ((position min: container height - 100) max: 100).
  93. secondPane asJQuery height: (((container height - position) min: container height - 100) max: 100) - 6.
  94. super resize
  95. !
  96. startResizing: aSplitter
  97. aSplitter width: splitter asJQuery width
  98. ! !
  99. !HLHorizontalSplitter methodsFor: 'rendering'!
  100. setupSplitter
  101. splitter asJQuery draggable: #{
  102. 'axis' -> 'y'.
  103. 'containment' -> splitter asJQuery parent.
  104. 'helper' -> 'clone'.
  105. 'start' -> [ :e :ui | self startResizing: ui helper ].
  106. 'drag' -> [ :e :ui | self resize: ui offset top ] }
  107. ! !
  108. HLSplitter subclass: #HLVerticalSplitter
  109. instanceVariableNames: ''
  110. package: 'Helios-Layout'!
  111. !HLVerticalSplitter methodsFor: 'accessing'!
  112. cssClass
  113. ^ super cssClass, ' vertical'
  114. !
  115. panesCssClass
  116. ^ super panesCssClass, ' vertical'
  117. ! !
  118. !HLVerticalSplitter methodsFor: 'actions'!
  119. resize
  120. self resize: splitter asJQuery offset left
  121. !
  122. resize: anInteger
  123. | container position |
  124. container := firstPane asJQuery parent.
  125. position := anInteger - container offset left.
  126. firstPane asJQuery width: ((position min: container width - 100) max: 100).
  127. secondPane asJQuery width: (((container width - position) min: container width - 100) max: 100) - 6.
  128. super resize
  129. !
  130. startResizing: aSplitter
  131. aSplitter height: splitter asJQuery height
  132. ! !
  133. !HLVerticalSplitter methodsFor: 'rendering'!
  134. setupSplitter
  135. splitter asJQuery draggable: #{
  136. 'axis' -> 'x'.
  137. 'containment' -> splitter asJQuery parent.
  138. 'helper' -> 'clone'.
  139. 'start' -> [ :e :ui | self startResizing: ui helper ].
  140. 'drag' -> [ :e :ui | self resize: ui offset left ] }
  141. ! !
  142. !Object methodsFor: '*Helios-Layout'!
  143. isHeliosSplitter
  144. ^ false
  145. ! !