Skip to content

Commit

Permalink
rewrite of the "drag root" finding code, and bringing back "locking" …
Browse files Browse the repository at this point in the history
…of Morphs
  • Loading branch information
davidedc committed Jan 14, 2018
1 parent 3ee1e11 commit 922ee91
Show file tree
Hide file tree
Showing 20 changed files with 232 additions and 186 deletions.
4 changes: 1 addition & 3 deletions src/CloseIconButtonMorph.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class CloseIconButtonMorph extends EmptyButtonMorph
# can't set the parent as the target directly because this morph
# might not have a parent yet.
super true, @, 'actOnClick', new Morph()
@defaultRejectDrags = true
@color_hover = new Color 255,0,0
@color_pressed = @color_hover
@appearance = new IconAppearance @, @defaultCloseIconAppearance
Expand All @@ -74,6 +75,3 @@ class CloseIconButtonMorph extends EmptyButtonMorph
actOnClick: ->
@parent?.fullDestroy()

rootForGrab: ->
return nil

24 changes: 12 additions & 12 deletions src/ColorPaletteMorph.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ class ColorPaletteMorph extends Morph

constructor: (@target = nil, sizePoint) ->
super()

# you can't grab the colorPaletteMorph because
# the drag operation currently picks a color.
# You could change that, you could pick color
# only by normal click for example.
# Or you could have either behaviour based on
# preference.
# Or you could perhaps allow it to be grabbed
# if it's disabled, say. (but we don't have this
# "disabled" concept implemented now).
@defaultRejectDrags = true

@silentRawSetExtent sizePoint or new Point 80, 50

# no changes of position or extent should be
Expand Down Expand Up @@ -45,18 +57,6 @@ class ColorPaletteMorph extends Morph
cacheEntry = [backBuffer, backBufferContext]
world.cacheForImmutableBackBuffers.set cacheKey, cacheEntry
return cacheEntry

# you can't grab the colorPaletteMorph because
# the drag operation currently picks a color.
# You could change that, you could pick color
# only by normal click for example.
# Or you could have either behaviour based on
# preference.
# Or you could perhaps allow it to be grabbed
# if it's disabled, say. (but we don't have this
# "disabled" concept implemented now).
rootForGrab: ->
return nil

mouseMove: (pos, mouseButton) ->
# effectively takes care of drag as well
Expand Down
2 changes: 0 additions & 2 deletions src/ColorPickerMorph.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,3 @@ class ColorPickerMorph extends Morph
getColor: ->
@feedback.color

rootForGrab: ->
@
19 changes: 11 additions & 8 deletions src/EmptyButtonMorph.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class EmptyButtonMorph extends Morph
# additional properties:

super()
@defaultRejectDrags = true

#@color = new Color 255, 152, 152
#@color = new Color 255, 255, 255
Expand Down Expand Up @@ -117,19 +118,21 @@ class EmptyButtonMorph extends Morph
mouseDoubleClick: ->
@triggerDoubleClick()

# you shouldn't be able to floatDragging a compound
# you shouldn't be able to drag a compound
# morphs containing a button by dragging the button
# (because you expect buttons attached to anything but the
# world to be "slippery", i.e.
# you can "skid" your drag over it in case you change
# your mind on pressing it)
# and at the same time (again if it's not on the desktop)
# you don't want it to be "floating"
# either
rootForGrab: ->
if @grabsToParentWhenDragged()
return super()
nil
# and you shouldn't be able to drag the button away either
# so the drag is entirely rejected
rejectDrags: ->
if @parent instanceof WorldMorph
return false
else
return @defaultRejectDrags



# TriggerMorph bubble help:
startCountdownForBubbleHelp: (contents) ->
Expand Down
19 changes: 17 additions & 2 deletions src/FrameMorph.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -288,16 +288,31 @@ class FrameMorph extends Morph
@parent.adjustContentsBounds()
@parent.adjustScrollBars()

grabsToParentWhenDragged: ->
detachesWhenDragged: ->
if @parent?

# otherwise you could detach a Frame contained in a
# ScrollFrameMorph which is very strange
if @parent instanceof ScrollFrameMorph
return false

return super
return super

grabsToParentWhenDragged: ->
if @parent?

# otherwise you could detach a Frame contained in a
# ScrollFrameMorph which is very strange
if @parent instanceof ScrollFrameMorph
if @parent.canScrollByDraggingBackground and @parent.anyScrollBarShowing()
return false
else
return true

return super

# doesn't have a parent
return false

reactToGrabOf: ->
if @parent?
Expand Down
13 changes: 5 additions & 8 deletions src/HandMorph.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ class HandMorph extends Morph
@destroyTemporaryHandlesAndLayoutAdjustersIfHandHasNotActionedThem morph
@stopEditingIfActionIsElsewhere morph

@morphToGrab = morph.rootForGrab()
@morphToGrab = morph.findRootForGrab()
if button is 2 or ctrlKey
@mouseButton = "right"
actualClick = "mouseDownRight"
Expand Down Expand Up @@ -851,25 +851,22 @@ class HandMorph extends Morph

determineGrabs: (pos, topMorph, mouseOverNew) ->
if (!@nonFloatDraggingSomething()) and (!@floatDraggingSomething()) and (@mouseButton is "left")
morph = topMorph.rootForGrab()
debugger
morph = topMorph.findRootForGrab()
topMorph.mouseMove pos if topMorph.mouseMove

# if a morph is marked for grabbing, just grab it
# if a morph is marked for grabbing, grab it
if @morphToGrab
if @morphToGrab.isTemplate
[skipDragging, displacementDueToGrabDragThreshold] = @checkDraggingTreshold()
if skipDragging then return

morph = @morphToGrab.fullCopy()
morph.isTemplate = false
# this flag is not used anymore but not sure
# if anything should replace this.
# keeping it as a comment as a breadcrumb
# morph.grabsToParentWhenDragged = true
@grab morph, displacementDueToGrabDragThreshold
@grabOrigin = @morphToGrab.situation()

else if @morphToGrab.grabsToParentWhenDragged()
else if @morphToGrab.detachesWhenDragged()
[skipDragging, displacementDueToGrabDragThreshold] = @checkDraggingTreshold()
if skipDragging then return

Expand Down
28 changes: 14 additions & 14 deletions src/HandleMorph.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class HandleMorph extends Morph
else
@inset = new Point minimumPadding, minimumPadding
super()
@isLockingToPanels = false
@color = new Color 255, 255, 255
@noticesTransparentClick = true
size = WorldMorph.preferencesAndSettings.handleSize
Expand All @@ -35,19 +36,22 @@ class HandleMorph extends Morph
@target.add @
@updateResizerHandlePosition()

detachesWhenDragged: ->
if (@parent instanceof WorldMorph)
return true
else
return false

# HandleMorphs are one of the few morphs that
# by default don't stick to their parents.
# Also SliderButtonMorphs tend do the same (if
# they are attached to a SliderMorph)
# The "move" HandleMorph COULD grab to its
# parent, in fact it would be easier, however for
# uniformity we don't do that
grabsToParentWhenDragged: ->
if @parent?

# an instance of ScrollFrameMorph is also an instance of FrameMorph
# so gotta do this check first ahead of next paragraph.
#if @parentThatIsA(ScrollFrameMorph)?
# return false

if @parent instanceof WorldMorph
return true
return false


parentHasReLayouted: ->
# right now you can resize a morph only if it's
# free-floating, however this will change in the future
Expand Down Expand Up @@ -273,10 +277,6 @@ class HandleMorph extends Morph
@target.setHeight newHeight


# HandleMorph floatDragging and dropping:
rootForGrab: ->
@

# HandleMorph events:
mouseEnter: ->
console.log "<<<<<< handle mousenter"
Expand Down
2 changes: 1 addition & 1 deletion src/ListMorph.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class ListMorph extends ScrollFrameMorph
if @listContents
@listContents = @listContents.destroy()
@listContents = new MenuMorph @, true, @, false, false, nil, nil
@listContents.isLocked = true
@listContents.isLockingToPanels = true
@elements = ["(empty)"] if !@elements.length
trackChanges.push false
@elements.forEach (element) =>
Expand Down
1 change: 1 addition & 0 deletions src/MenuMorph.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class MenuMorph extends Morph
if @killThisMenuIfClickOutsideDescendants
@onClickOutsideMeOrAnyOfMyChildren "destroy"
super()
@isLockingToPanels = false
@appearance = new MenuAppearance @

# the morphOpeningTheMenu is only useful to get the "parent" menu.
Expand Down
Loading

0 comments on commit 922ee91

Please sign in to comment.