I manage to get two clicks when I try adding another event listener
to the D&D example. How do I combine them correctly? addEventListener: (BlPluggableEventListener new whenClickDo: [ :evt | |aSubmorph| aSubmorph := (BlRectangleView new color: Color red; extent: 20 @ 20) asMorph. aSubmorph translateBy: 50 @ 50. whiteContainer addMorph: aSubmorph]; yourself); addEventListener: BlPasteUpEventListener new. Stephan |
the problem with BlPasteUpEventListener is that it
is a complex listener that may be difficult to combine. what is the behaviour that you want to implement ? Drag@Drop into/from the pane and click management for each pane element individually ? Cheers Alain > On 15 Jul 2015, at 14:01, Stephan Eggermont <[hidden email]> wrote: > > I manage to get two clicks when I try adding another event listener > to the D&D example. How do I combine them correctly? > > addEventListener: > (BlPluggableEventListener new > whenClickDo: [ :evt | > |aSubmorph| > aSubmorph := (BlRectangleView new > color: Color red; > extent: 20 @ 20) asMorph. > aSubmorph translateBy: 50 @ 50. > whiteContainer addMorph: aSubmorph]; > yourself); > addEventListener: BlPasteUpEventListener new. > > Stephan > > |
On 15/07/15 15:51, Alain Plantec via Pharo-dev wrote:
>the problem with BlPasteUpEventListener is that it >is a complex listener that may be difficult to combine. >what is the behaviour that you want to implement ? This is an example where a click on the background should add a new submorph to the PasteUp. A right click on a submorph should open a delete menu. >Drag@Drop into/from the pane and click management >for each pane element individually ? The cards need to react to left-, right-click and double click and be draggable. The PasteUpMorph needs right-click on the background. Stephan |
Hello Stephan
Have a look at Bloc-DragPanels-AlainPlantec.9 I’ve added two event listeners. Cheers Alain > On 15 Jul 2015, at 17:26, Stephan Eggermont <[hidden email]> wrote: > > On 15/07/15 15:51, Alain Plantec via Pharo-dev wrote: > >the problem with BlPasteUpEventListener is that it > >is a complex listener that may be difficult to combine. > >what is the behaviour that you want to implement ? > > This is an example where a click on the background > should add a new submorph to the PasteUp. A right click > on a submorph should open a delete menu. > > >Drag@Drop into/from the pane and click management > >for each pane element individually ? > > The cards need to react to left-, right-click and > double click and be draggable. The PasteUpMorph > needs right-click on the background. > > Stephan > > > |
Nice, looking good. Thank you. Making good progress.
I can now drag-drop a color from one panel to another. In Morphic the layout would then be responsible for determining at which position in the submorph collection this would be added. In morphic that is done with LayoutPolicy>>indexForInserting: aMorph at: aPoint in: someMorph "Return the insertion index based on the layout strategy defined for some morph. Used for drop insertion." ^1 "front-most" which is only overridden in TableLayout. Is that a separate responsibility in Bloc or is that part of the responsibility of a LayoutStrategy (or even an EventListener)? Stephan |
|
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 |
Free forum by Nabble | Edit this page |