Re: [Pharo-dev] How to combine event listeners in Bloc?
On 16-07-15 11:41, Alain Plantec via Pharo-dev wrote:
i think it is better as specific feature of the pane event listener
It feels a bit like feature envy. Too much poking around. BlWellPanelFlowEventListener>>PaneldropAccepted: anEvent |wellPanelFlow droppedMorph localPosition found| wellPanelFlow := anEvent handler. droppedMorph := anEvent contents asDragWell. localPosition := wellPanelFlow globalPointToLocal: anEvent position. wellPanelFlow hasSubmorphs ifFalse: [ wellPanelFlow addMorph: droppedMorph ]. found := wellPanelFlow morphsAt: localPosition. found ifNotNil: [ "We found at least one. The deepest is first, that's the one we want" found := found first. found bounds center x < localPosition x ifTrue: [ "to the right of its center, so after it?" wellPanelFlow addMorph: droppedMorph after: found ] ifFalse: [ wellPanelFlow addMorph: droppedMorph inFrontOf: found ] ] ifNil: [ found := self precedingMorphIn: wellPanelFlow submorphs at: localPosition. found ifNil: [ wellPanelFlow addMorphFront: droppedMorph ] ifNotNil: [ wellPanelFlow addMorph: droppedMorph after: found ] ] BlWellPanelFlowEventListener>>precedingMorphIn: aCollection at: localPosition |precedingMorph| precedingMorph := nil. aCollection do: [ :aMorph | aMorph bounds bottom < localPosition y ifTrue: [ "wrong row" precedingMorph := aMorph ] ifFalse: [ aMorph bounds right < localPosition x ifTrue: [ precedingMorph := aMorph] ifFalse: [ ^aMorph ]] ]. ^precedingMorph
Hmm, this is not too bad. But it still is dependent on the layout. BlCardLayout>>dropAccepted: anEvent |wellPanelFlow droppedMorph localPosition | wellPanelFlow := anEvent handler. droppedMorph := anEvent contents asDragWell. localPosition := wellPanelFlow globalPointToLocal: anEvent position. wellPanelFlow hasSubmorphs ifFalse: [ wellPanelFlow addMorph: droppedMorph ]. wellPanelFlow addMorph: droppedMorph asElementNumber: (self indexForInserting: localPosition inList: wellPanelFlow submorphs) BlCardLayout>>indexForInserting: aPoint inList: morphList | cmp1 cmp2 cmp3 | cmp1 := [:rect | aPoint x < rect right]. cmp2 := [:rect | aPoint y < rect bottom]. cmp3 := [:rect | aPoint y < rect top]. morphList keysAndValuesDo: [:index :m | | box | box := m fullBounds translateBy: m position. "Check for inserting before current row" (cmp3 value: box) ifTrue: [^index]. "Check for inserting before current cell" ((cmp1 value: box) and: [cmp2 value: box]) ifTrue: [^index]]. ^morphList size + 1
participants (1)
-
Stephan Eggermont