Moka-Examples.st 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. Smalltalk current createPackage: 'Moka-Examples'!
  2. MKObservable subclass: #MKClassesListBuilder
  3. instanceVariableNames: ''
  4. package: 'Moka-Examples'!
  5. !MKClassesListBuilder methodsFor: 'as yet unclassified'!
  6. build
  7. MKPaneView new
  8. height: 150;
  9. addView: ((MKScrollDecorator decorate:
  10. (MKListView
  11. model: MKClassesModel new
  12. collectionAspect: #classes
  13. selectionAspect: #selectedClass))
  14. left: 4;
  15. top: 4;
  16. bottom: 4;
  17. right: 0.5;
  18. yourself);
  19. addView: (MKPanelView new
  20. left: 0.5;
  21. top: 4;
  22. right: 4;
  23. bottom: 4;
  24. addView: (MKSourceListView
  25. model: MKClassesModel new
  26. collectionAspect: #classes
  27. selectionAspect: #selectedClass);
  28. yourself);
  29. render
  30. ! !
  31. !MKClassesListBuilder class methodsFor: 'as yet unclassified'!
  32. initialize
  33. self new build
  34. ! !
  35. MKObservable subclass: #MKClassesModel
  36. instanceVariableNames: 'classes selectedClass'
  37. package: 'Moka-Examples'!
  38. !MKClassesModel methodsFor: 'as yet unclassified'!
  39. classes
  40. ^ Smalltalk current classes
  41. !
  42. selectedClass
  43. ^ selectedClass ifNil: [ self classes first ]
  44. !
  45. selectedClass: aClass
  46. selectedClass := aClass.
  47. self changed: #selectedClass
  48. ! !
  49. Object subclass: #MKCounterBuilder
  50. instanceVariableNames: 'counter'
  51. package: 'Moka-Examples'!
  52. !MKCounterBuilder methodsFor: 'accessing'!
  53. build
  54. | pane |
  55. pane := MKPanelView new
  56. yourself.
  57. pane addView: ((MKHeadingView model: self counter aspect: #count)
  58. level: 3;
  59. top: 0;
  60. left: 8;
  61. height: 28;
  62. yourself).
  63. pane addView: ((MKButtonView model: self counter aspect: #increase)
  64. label: 'Increase';
  65. top: 50;
  66. left: 8;
  67. yourself).
  68. pane addView: ((MKButtonView model: self counter aspect: #decrease)
  69. label: 'Decrease';
  70. default: true;
  71. top: 50;
  72. left: 92;
  73. yourself).
  74. pane addView: ((MKDropdownView
  75. model: self counter
  76. collectionAspect: #options
  77. selectionAspect: #selectedOption)
  78. left: 176;
  79. top: 50;
  80. yourself).
  81. pane addView: ((MKInputView model: self counter aspect: #text)
  82. top: 100;
  83. left: 8;
  84. yourself).
  85. pane addView: ((MKInputView model: self counter aspect: #text)
  86. top: 150;
  87. left: 8;
  88. triggerChangeOnAnyKey;
  89. yourself).
  90. pane addView: ((MKTextAreaView model: self counter aspect: #text)
  91. top: 200;
  92. left: 8;
  93. yourself).
  94. pane addView: ((MKCheckboxView model: self counter aspect: #checked)
  95. top: 300;
  96. left: 8;
  97. yourself).
  98. pane addView: ((MKSwitchView model: self counter aspect: #checked)
  99. top: 350;
  100. centerX: 0;
  101. yourself).
  102. pane addView: ((MKSwitchView model: self counter aspect: #checked)
  103. top: 380;
  104. centerX: -50;
  105. yourself).
  106. pane addView: ((MKSwitchView model: self counter aspect: #checked)
  107. top: 410;
  108. centerX: 50;
  109. yourself).
  110. pane addView: ((MKSwitchView model: self counter aspect: #checked)
  111. right: 4;
  112. centerY: 0;
  113. yourself).
  114. pane addView: ((MKSwitchView model: self counter aspect: #checked)
  115. right: 4;
  116. centerY: 30;
  117. yourself).
  118. pane addView: ((MKSwitchView model: self counter aspect: #checked)
  119. right: 4;
  120. centerY: -30;
  121. yourself).
  122. pane addView: ((MKDropdownView
  123. model: self counter
  124. collectionAspect: #options
  125. selectionAspect: #selectedOption)
  126. left: 4;
  127. top: 440;
  128. yourself).
  129. (MKHorizontalSplitView
  130. firstView: (MKScrollDecorator decorate: pane)
  131. secondView: MKLayoutView new)
  132. top: 200;
  133. bottom: 0;
  134. render
  135. !
  136. counter
  137. ^ counter ifNil: [ counter := MKCounterModel new ]
  138. ! !
  139. !MKCounterBuilder class methodsFor: 'initialization'!
  140. initialize
  141. self new build
  142. ! !
  143. MKObservable subclass: #MKCounterModel
  144. instanceVariableNames: 'count text checked options selectedOption'
  145. package: 'Moka-Examples'!
  146. !MKCounterModel methodsFor: 'accessing'!
  147. options
  148. ^ #('foo' 'bar' 'baz')
  149. !
  150. selectedOption
  151. ^ selectedOption ifNil: [ selectedOption := self options last ]
  152. !
  153. selectedOption: aString
  154. selectedOption := aString.
  155. self changed: #selectedOption
  156. ! !
  157. !MKCounterModel methodsFor: 'actions'!
  158. checked
  159. ^ checked ifNil: [ false ]
  160. !
  161. checked: aBoolean
  162. checked := aBoolean.
  163. self changed: 'checked'
  164. !
  165. count
  166. ^ count asString
  167. !
  168. decrease
  169. count := count - 1.
  170. self changed: #count
  171. !
  172. increase
  173. count := count + 1.
  174. self changed: #count
  175. !
  176. text
  177. ^ text ifNil: [ '' ]
  178. !
  179. text: aString
  180. text := aString.
  181. self changed: 'text'
  182. ! !
  183. !MKCounterModel methodsFor: 'initialization'!
  184. initialize
  185. super initialize.
  186. count := 0
  187. ! !