@@ -33,6 +33,7 @@ BlDragAndDropExamples >> letterFor: aCharacter [
33
33
{ #category : #examples }
34
34
BlDragAndDropExamples >> lettersSorter [
35
35
< gtExample>
36
+ < return: #BlElement >
36
37
| letters vowels consonants |
37
38
letters := self lettersSorterContainer.
38
39
vowels := self lettersSorterRoundedContainerWithBorder.
@@ -170,95 +171,97 @@ BlDragAndDropExamples >> tagOrdererSlidingTagFor: aString [
170
171
{ #category : #accessing }
171
172
BlDragAndDropExamples >> tagsOrderer [
172
173
< gtExample>
174
+ < return: #BlElement >
173
175
| aContainer |
174
-
175
176
aContainer := BlElement new .
176
177
aContainer layout: (BlLinearLayout horizontal cellSpacing: 5 ).
177
- aContainer constraintsDo: [ :c |
178
- c horizontal matchParent.
179
- c vertical fitContent ].
180
-
181
- aContainer addEventHandler: (BlDropHandler new
182
- acceptOnlyFromThisElement;
183
- whenDragOverDo: [ :anItemsDraggedOverEvent |
184
- | container locationElement position childPosition |
185
-
186
- container := anItemsDraggedOverEvent currentTarget.
187
- locationElement := container
188
- childWithId: #' drop-area--drop-location'
189
- ifFound: [ :anElement | anElement ]
190
- ifNone: [
191
- | anElement |
192
-
193
- anElement := BlElement new
194
- background: Color orange;
195
- width: 2 ;
196
- constraintsDo: [ :c |
197
- c ignoreByLayout.
198
- c vertical matchParent ].
178
+ aContainer
179
+ constraintsDo: [ :c |
180
+ c horizontal matchParent.
181
+ c vertical fitContent ].
199
182
200
- container addChild: anElement as: #' drop-area--drop-location' .
201
- anElement ].
183
+ aContainer
184
+ addEventHandler: (BlDropHandler new
185
+ acceptOnlyFromThisElement;
186
+ whenDragOverDo: [ :anItemsDraggedOverEvent |
187
+ | container locationElement position childPosition |
188
+ container := anItemsDraggedOverEvent currentTarget.
189
+ locationElement := container
190
+ childWithId: #' drop-area--drop-location'
191
+ ifFound: [ :anElement | anElement ]
192
+ ifNone: [ | anElement |
193
+ anElement := BlElement new
194
+ background: Color orange;
195
+ width: 2 ;
196
+ constraintsDo: [ :c |
197
+ c ignoreByLayout.
198
+ c vertical matchParent ].
202
199
203
- position := anItemsDraggedOverEvent position x.
204
- childPosition := container children accountedByLayout
205
- detect: [ :eachChild | position < eachChild bounds inParent center x ]
206
- ifFound: [ :eachChild | eachChild bounds inParent left - 10 ]
207
- ifNone: [ container children accountedByLayout last bounds inParent right + 10 ].
200
+ container addChild: anElement as: #' drop-area--drop-location' .
201
+ anElement ].
208
202
209
- locationElement relocate: childPosition @ 0 ];
203
+ position := anItemsDraggedOverEvent position x.
204
+ childPosition := container children accountedByLayout
205
+ detect: [ :eachChild | position < eachChild bounds inParent center x ]
206
+ ifFound: [ :eachChild | eachChild bounds inParent left - 10 ]
207
+ ifNone: [ container children accountedByLayout last bounds inParent right
208
+ + 10 ].
210
209
211
- whenDragLeftDo: [ :anItemsLeftEvent | anItemsLeftEvent currentTarget removeChildNamed: #' drop-area--drop-location' ];
212
- whenHorizontalDroppedDo: [ :anItemsDroppedEvent :anIndex |
213
- (anItemsDroppedEvent items reverseDo: [ :eachDragItem |
214
- anItemsDroppedEvent currentTarget addChild: eachDragItem sourceElement at: anIndex + 1 ]) ]).
210
+ locationElement relocate: childPosition @ 0 ];
211
+ whenDragLeftDo: [ :anItemsLeftEvent | anItemsLeftEvent currentTarget removeChildNamed: #' drop-area--drop-location' ];
212
+ whenHorizontalDroppedDo: [ :anItemsDroppedEvent :anIndex |
213
+ anItemsDroppedEvent items
214
+ reverseDo: [ :eachDragItem |
215
+ anItemsDroppedEvent currentTarget
216
+ addChild: eachDragItem sourceElement
217
+ at: anIndex + 1 ] ]).
215
218
216
- aContainer addChildren: ({
217
- ' One' .
218
- ' Two' .
219
- ' Three' .
220
- ' Four' .
221
- } collect: [ :eachName | self tagOrdererDraggableTagFor: eachName ]).
219
+ aContainer
220
+ addChildren: ({' One' .
221
+ ' Two' .
222
+ ' Three' .
223
+ ' Four' } collect: [ :eachName | self tagOrdererDraggableTagFor: eachName ]).
222
224
223
225
^ aContainer
224
226
]
225
227
226
228
{ #category : #accessing }
227
229
BlDragAndDropExamples >> tagsSlidingOrderer [
228
230
< gtExample>
231
+ < return: #BlElement >
229
232
| aContainer |
230
-
231
233
aContainer := BlElement new .
232
234
aContainer layout: (BlLinearLayout horizontal cellSpacing: 5 ).
233
- aContainer constraintsDo: [ :c |
234
- c horizontal matchParent.
235
- c vertical fitContent ].
236
-
237
- aContainer addEventHandler: (BlDropHandler new
238
- acceptOnlyFromThisElement;
239
- whenHorizontalSlideOverDo: [];
240
- whenDroppedDo: [ :anItemsDroppedEvent |
241
- | container position childBefore |
235
+ aContainer
236
+ constraintsDo: [ :c |
237
+ c horizontal matchParent.
238
+ c vertical fitContent ].
242
239
243
- container := anItemsDroppedEvent currentTarget.
244
- position := anItemsDroppedEvent position x.
245
- childBefore := container children accountedByLayout
246
- detect: [ :eachChild | position < (eachChild bounds inParent center x - 5 ) ]
247
- ifFound: [ :eachChild | eachChild ]
248
- ifNone: [ nil ].
240
+ aContainer
241
+ addEventHandler: (BlDropHandler new
242
+ acceptOnlyFromThisElement;
243
+ whenHorizontalSlideOverDo: [ ];
244
+ whenDroppedDo: [ :anItemsDroppedEvent |
245
+ | container position childBefore |
246
+ container := anItemsDroppedEvent currentTarget.
247
+ position := anItemsDroppedEvent position x.
248
+ childBefore := container children accountedByLayout
249
+ detect: [ :eachChild | position < (eachChild bounds inParent center x - 5 ) ]
250
+ ifFound: [ :eachChild | eachChild ]
251
+ ifNone: [ nil ].
249
252
250
- (anItemsDroppedEvent items collect: [ :eachDragItem | eachDragItem sourceElement ])
251
- do: [ :each |
252
- childBefore
253
- ifNil: [ container addChild: each ]
254
- ifNotNil: [ container addChild: each before: childBefore ] ] ]).
253
+ (anItemsDroppedEvent items
254
+ collect: [ :eachDragItem | eachDragItem sourceElement ])
255
+ do: [ :each |
256
+ childBefore
257
+ ifNil: [ container addChild: each ]
258
+ ifNotNil: [ container addChild: each before: childBefore ] ] ]).
255
259
256
- aContainer addChildren: ({
257
- ' One' .
258
- ' Two' .
259
- ' Three' .
260
- ' Four' .
261
- } collect: [ :eachName | self tagOrdererSlidingTagFor: eachName ]).
260
+ aContainer
261
+ addChildren: ({' One' .
262
+ ' Two' .
263
+ ' Three' .
264
+ ' Four' } collect: [ :eachName | self tagOrdererSlidingTagFor: eachName ]).
262
265
263
266
^ aContainer
264
267
]
0 commit comments