Skip to content

Commit

Permalink
adding three more layout specs to cover what the handles (move, resiz…
Browse files Browse the repository at this point in the history
…e horiz, resize vert, resize both) need, and having handles all use those. Since handles are now handled as a layout, I needed most doLayout functions in subclasses to do a super() at some point to use the base class doLayout to do fix the handles properly. Check out all the new TODOs for needed improvements
  • Loading branch information
davidedc committed Aug 7, 2020
1 parent 9d376f1 commit 837b772
Show file tree
Hide file tree
Showing 30 changed files with 76 additions and 91 deletions.
1 change: 1 addition & 0 deletions src/BasementWdgt.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -189,5 +189,6 @@ class BasementWdgt extends BoxMorph
@hideUsedWdgtsToggle.doLayout (new Rectangle 0,0,w,h).translateBy new Point x, y
trackChanges.pop()

super
@layoutIsValid = true
@notifyAllChildrenRecursivelyThatParentHasReLayouted()
3 changes: 1 addition & 2 deletions src/CodePromptMorph.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ class CodePromptMorph extends Widget
@notifyAllChildrenRecursivelyThatParentHasReLayouted()
return

super

# here we are disabling all the broken
# rectangles. The reason is that all the
# submorphs of the inspector are within the
Expand Down Expand Up @@ -146,6 +144,7 @@ class CodePromptMorph extends Widget
if Automator? and Automator.state != Automator.IDLE and Automator.alignmentOfMorphIDsMechanism
world.alignIDsOfNextMorphsInSystemTests()

super
@layoutIsValid = true
@notifyAllChildrenRecursivelyThatParentHasReLayouted()

1 change: 1 addition & 0 deletions src/ColorPickerMorph.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class ColorPickerMorph extends Widget
trackChanges.pop()
@fullChanged()

super
@layoutIsValid = true
@notifyAllChildrenRecursivelyThatParentHasReLayouted()

Expand Down
1 change: 1 addition & 0 deletions src/EmptyButtonMorph.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class EmptyButtonMorph extends Widget
if @faceMorph?.parent == @
@faceMorph.rawSetBounds newBoundsForThisLayout.insetBy @padding

super
@layoutIsValid = true
@notifyAllChildrenRecursivelyThatParentHasReLayouted()

Expand Down
1 change: 1 addition & 0 deletions src/ErrorsLogViewerMorph.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ class ErrorsLogViewerMorph extends Widget
world.alignIDsOfNextMorphsInSystemTests()


super
@layoutIsValid = true
@notifyAllChildrenRecursivelyThatParentHasReLayouted()

Expand Down
84 changes: 20 additions & 64 deletions src/HandleMorph.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ class HandleMorph extends Widget
super()
@color = Color.WHITE
@noticesTransparentClick = true
size = WorldMorph.preferencesAndSettings.handleSize
@silentRawSetExtent new Point size, size
if @target
@target.add @
@updateResizerHandlePosition()

@layoutSpec_cornerInternal_proportionOfParent = 0
@layoutSpec_cornerInternal_fixedSize = WorldMorph.preferencesAndSettings.handleSize
@layoutSpec_cornerInternal_inset = @inset

@makeHandleSolidWithParentMorph nil, nil, @target

detachesWhenDragged: ->
if (@parent instanceof WorldMorph)
Expand All @@ -48,8 +49,9 @@ class HandleMorph extends Widget

updateVisibilityAndPosition: ->
@updateVisibility()
# TODO is this check and action really needed? Can't we just
# do that in the add and then never do this again?
if @parent.layoutSpec == LayoutSpec.ATTACHEDAS_FREEFLOATING
@updateResizerHandlePosition()
@moveInFrontOfSiblings()

updateVisibility: ->
Expand All @@ -62,60 +64,6 @@ class HandleMorph extends Widget
else
@hide()

parentHasReLayouted: ->
# right now you can resize a morph only if it's
# free-floating, however this will change in the future
# as for example things inside vertically-stretchable
# Panels can potentially change their width.
# so this handle has to go away now.
@updateVisibilityAndPosition()
if @parent.layoutSpec == LayoutSpec.ATTACHEDAS_FREEFLOATING
super

updateResizerHandlePosition: ->
if @target
# collapse some of the handles if the
# morph gets too small because they
# become unusable anyways once they
# overlap
switch @type
when "moveHandle"
if @target.width() < 2 * @width()
@hide()
return
else
@show()
when "resizeHorizontalHandle"
if @target.height() < 3 * @height()
@hide()
return
else
@show()
when "resizeVerticalHandle"
if @target.width() < 3 * @width()
@hide()
return
else
@show()

@silentUpdateResizerHandlePosition()
@changed()

silentUpdateResizerHandlePosition: ->
if @target
switch @type
when "resizeBothDimensionsHandle"
@silentFullRawMoveTo @target.bottomRight().subtract @extent().add @inset
when "moveHandle"
@silentFullRawMoveTo @target.topLeft().add @inset
when "resizeHorizontalHandle"
offsetFromMiddlePoint = new Point @extent().x + @inset.x, Math.floor(@extent().y/2)
@silentFullRawMoveTo @target.rightCenter().subtract offsetFromMiddlePoint
when "resizeVerticalHandle"
offsetFromMiddlePoint = new Point Math.floor(@extent().x/2), @extent().y + @inset.y
@silentFullRawMoveTo @target.bottomCenter().subtract offsetFromMiddlePoint



# This method only paints this very morph's "image",
# it doesn't descend the children
Expand Down Expand Up @@ -296,10 +244,18 @@ class HandleMorph extends Widget
@changed()

makeHandleSolidWithParentMorph: (ignored, ignored2, morphAttachedTo)->
@target = morphAttachedTo
@target.add @
@updateResizerHandlePosition()
@noticesTransparentClick = true
if morphAttachedTo?
@target = morphAttachedTo
switch @type
when "resizeBothDimensionsHandle"
@target.add @, nil, LayoutSpec.ATTACHEDAS_CORNER_INTERNAL_BOTTOMRIGHT
when "moveHandle"
@target.add @, nil, LayoutSpec.ATTACHEDAS_CORNER_INTERNAL_TOPLEFT
when "resizeHorizontalHandle"
@target.add @, nil, LayoutSpec.ATTACHEDAS_CORNER_INTERNAL_RIGHT
when "resizeVerticalHandle"
@target.add @, nil, LayoutSpec.ATTACHEDAS_CORNER_INTERNAL_BOTTOM
@noticesTransparentClick = true


# HandleMorph menu:
Expand Down
3 changes: 3 additions & 0 deletions src/LayoutSpec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class LayoutSpec

@ATTACHEDAS_CORNER_INTERNAL_TOPRIGHT: 100014
@ATTACHEDAS_CORNER_INTERNAL_TOPLEFT: 100015
@ATTACHEDAS_CORNER_INTERNAL_BOTTOMRIGHT: 100016
@ATTACHEDAS_CORNER_INTERNAL_RIGHT: 100017
@ATTACHEDAS_CORNER_INTERNAL_BOTTOM: 100018


# »>> this part is excluded from the fizzygum homepage build
Expand Down
3 changes: 1 addition & 2 deletions src/ScriptWdgt.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@ class ScriptWdgt extends Widget
@notifyAllChildrenRecursivelyThatParentHasReLayouted()
return

super

# here we are disabling all the broken
# rectangles. The reason is that all the
# submorphs of the inspector are within the
Expand Down Expand Up @@ -155,6 +153,7 @@ class ScriptWdgt extends Widget
if Automator? and Automator.state != Automator.IDLE and Automator.alignmentOfMorphIDsMechanism
world.alignIDsOfNextMorphsInSystemTests()

super
@layoutIsValid = true
@notifyAllChildrenRecursivelyThatParentHasReLayouted()

3 changes: 1 addition & 2 deletions src/SimpleLinkWdgt.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ class SimpleLinkWdgt extends Widget
@notifyAllChildrenRecursivelyThatParentHasReLayouted()
return

super

# here we are disabling all the broken
# rectangles. The reason is that all the
# submorphs of the inspector are within the
Expand Down Expand Up @@ -102,6 +100,7 @@ class SimpleLinkWdgt extends Widget
if Automator? and Automator.state != Automator.IDLE and Automator.alignmentOfMorphIDsMechanism
world.alignIDsOfNextMorphsInSystemTests()

super
@layoutIsValid = true
@notifyAllChildrenRecursivelyThatParentHasReLayouted()

1 change: 1 addition & 0 deletions src/SpeechBubbleWdgt.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class SpeechBubbleWdgt extends Widget
trackChanges.pop()
@fullChanged()

super
@layoutIsValid = true
@notifyAllChildrenRecursivelyThatParentHasReLayouted()

Expand Down
1 change: 1 addition & 0 deletions src/StretchableCanvasWdgt.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ class StretchableCanvasWdgt extends CanvasMorph
trackChanges.pop()
@fullChanged()

super
@layoutIsValid = true
@notifyAllChildrenRecursivelyThatParentHasReLayouted()

Expand Down
1 change: 1 addition & 0 deletions src/StretchablePanelWdgt.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class StretchablePanelWdgt extends PanelWdgt
trackChanges.pop()
@fullChanged()

super
@layoutIsValid = true
@notifyAllChildrenRecursivelyThatParentHasReLayouted()

Expand Down
1 change: 1 addition & 0 deletions src/StretchableWidgetContainerWdgt.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ class StretchableWidgetContainerWdgt extends Widget
trackChanges.pop()
@fullChanged()

super
@layoutIsValid = true
@notifyAllChildrenRecursivelyThatParentHasReLayouted()

Expand Down
1 change: 1 addition & 0 deletions src/WidgetHolderWithCaptionWdgt.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class WidgetHolderWithCaptionWdgt extends Widget
trackChanges.pop()
@fullChanged()

super
@layoutIsValid = true
@notifyAllChildrenRecursivelyThatParentHasReLayouted()

Expand Down
10 changes: 9 additions & 1 deletion src/WindowWdgt.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,10 @@ class WindowWdgt extends SimpleVerticalStackPanelWdgt
super
@layoutSpecDetails.canSetHeightFreely = false

# should this just be the doLayout function? Why do we need this extra one?
adjustContentsBounds: ->
# avoid recursively re-entering this function
# TODO nasty check this one, can we make this go away?
if @_adjustingContentsBounds then return else @_adjustingContentsBounds = true

closeIconSize = 16
Expand Down Expand Up @@ -526,6 +528,12 @@ class WindowWdgt extends SimpleVerticalStackPanelWdgt
buttonBounds = buttonBounds.setBoundsWidthAndHeight closeIconSize, closeIconSize
@internalExternalSwitchButton.doLayout buttonBounds

@resizer?.silentUpdateResizerHandlePosition()
# TODO there is *already* a way to make handles do the right thing, and that is
# to have this sort of code in a doLayout function, and calling super in there,
# where the base Windget.doLayout takes care of everything that has a
# corner or edge internal layout, like handles. This should work the same way i.e.
# this code should not be here.
if @resizer?.parent == @
@resizer.silentFullRawMoveTo new Point @right() - WorldMorph.preferencesAndSettings.handleSize - @padding, @bottom() - WorldMorph.preferencesAndSettings.handleSize - @padding

@_adjustingContentsBounds = false
3 changes: 1 addition & 2 deletions src/apps/SimpleDocumentWdgt.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,6 @@ class SimpleDocumentWdgt extends Widget
@notifyAllChildrenRecursivelyThatParentHasReLayouted()
return

super

# here we are disabling all the broken
# rectangles. The reason is that all the
# submorphs of the inspector are within the
Expand Down Expand Up @@ -175,6 +173,7 @@ class SimpleDocumentWdgt extends Widget
if Automator? and Automator.state != Automator.IDLE and Automator.alignmentOfMorphIDsMechanism
world.alignIDsOfNextMorphsInSystemTests()

super
@layoutIsValid = true
@notifyAllChildrenRecursivelyThatParentHasReLayouted()

Expand Down
4 changes: 3 additions & 1 deletion src/basic-widgets/ScrollPanelWdgt.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,9 @@ class ScrollPanelWdgt extends PanelWdgt
# This would also apply to resizing handles - so we need to
# correct for that case
add: (aWdgt, position = nil, layoutSpec = LayoutSpec.ATTACHEDAS_FREEFLOATING, beingDropped, unused, positionOnScreen) ->
if aWdgt instanceof ModifiedTextTriangleAnnotationWdgt
# TODO this check below should probably just be testing if layoutSpec
# is a corner or edge internal layout
if aWdgt instanceof ModifiedTextTriangleAnnotationWdgt or aWdgt instanceof HandleMorph
super
else
@contents.add aWdgt, position, layoutSpec, beingDropped, nil, positionOnScreen
Expand Down
20 changes: 16 additions & 4 deletions src/basic-widgets/Widget.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4243,17 +4243,29 @@ class Widget extends TreeNode
else
@rawSetExtent newBoundsForThisLayout.extent()

if @layoutSpec == LayoutSpec.ATTACHEDAS_CORNER_INTERNAL_TOPLEFT or @layoutSpec == LayoutSpec.ATTACHEDAS_CORNER_INTERNAL_TOPRIGHT
if @layoutSpec == LayoutSpec.ATTACHEDAS_CORNER_INTERNAL_TOPLEFT or @layoutSpec == LayoutSpec.ATTACHEDAS_CORNER_INTERNAL_TOPRIGHT or @layoutSpec == LayoutSpec.ATTACHEDAS_CORNER_INTERNAL_BOTTOMRIGHT or @layoutSpec == LayoutSpec.ATTACHEDAS_CORNER_INTERNAL_RIGHT or @layoutSpec == LayoutSpec.ATTACHEDAS_CORNER_INTERNAL_BOTTOM
if @parent
xDim = @parent.width()
yDim = @parent.height()
minDim = Math.min(xDim, yDim) * @layoutSpec_cornerInternal_proportionOfParent + @layoutSpec_cornerInternal_fixedSize

@silentRawSetExtent new Point minDim, minDim

# TODO this hack is because I couldn't initialise this properly
# where I should, due to load dependency problems
if !@layoutSpec_cornerInternal_inset?
@layoutSpec_cornerInternal_inset = new Point 0, 0

if @layoutSpec == LayoutSpec.ATTACHEDAS_CORNER_INTERNAL_TOPLEFT
@silentFullRawMoveTo new Point @parent.left(), @parent.top()
@fullRawMoveTo new Point @parent.left() + @layoutSpec_cornerInternal_inset.x, @parent.top() + @layoutSpec_cornerInternal_inset.y
else if @layoutSpec == LayoutSpec.ATTACHEDAS_CORNER_INTERNAL_TOPRIGHT
@silentFullRawMoveTo new Point @parent.right() - minDim, @parent.top()
@fullRawMoveTo new Point @parent.right() - minDim - @layoutSpec_cornerInternal_inset.x, @parent.top() + @layoutSpec_cornerInternal_inset.y
else if @layoutSpec == LayoutSpec.ATTACHEDAS_CORNER_INTERNAL_BOTTOMRIGHT
@fullRawMoveTo new Point @parent.right() - minDim - @layoutSpec_cornerInternal_inset.x, @parent.bottom() - minDim - @layoutSpec_cornerInternal_inset.y
else if @layoutSpec == LayoutSpec.ATTACHEDAS_CORNER_INTERNAL_RIGHT
@fullRawMoveTo new Point @parent.right() - minDim - @layoutSpec_cornerInternal_inset.x, Math.floor(@parent.top() + (@parent.extent().y - minDim)/2)
else if @layoutSpec == LayoutSpec.ATTACHEDAS_CORNER_INTERNAL_BOTTOM
@fullRawMoveTo new Point Math.floor(@parent.left() + (@parent.extent().x - minDim)/2), @parent.bottom() - minDim - @layoutSpec_cornerInternal_inset.y

# »>> this part is excluded from the fizzygum homepage build
else if @countOfChildrenInHorizontalStackLayout() != 0
Expand Down Expand Up @@ -4362,7 +4374,7 @@ class Widget extends TreeNode

# if I just did my layout, also do the layout
# of all children that have position/size depending on mine
allCornerLayoutedChildren = @children.filter (m) -> m.layoutSpec == LayoutSpec.ATTACHEDAS_CORNER_INTERNAL_TOPLEFT or m.layoutSpec == LayoutSpec.ATTACHEDAS_CORNER_INTERNAL_TOPRIGHT
allCornerLayoutedChildren = @children.filter (m) -> m.layoutSpec == LayoutSpec.ATTACHEDAS_CORNER_INTERNAL_TOPLEFT or m.layoutSpec == LayoutSpec.ATTACHEDAS_CORNER_INTERNAL_TOPRIGHT or m.layoutSpec == LayoutSpec.ATTACHEDAS_CORNER_INTERNAL_BOTTOMRIGHT or m.layoutSpec == LayoutSpec.ATTACHEDAS_CORNER_INTERNAL_RIGHT or m.layoutSpec == LayoutSpec.ATTACHEDAS_CORNER_INTERNAL_BOTTOM
for w in allCornerLayoutedChildren
w.doLayout()

Expand Down
3 changes: 1 addition & 2 deletions src/fizzytiles/FridgeMagnetsMorph.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@ class FridgeMagnetsMorph extends Widget
@notifyAllChildrenRecursivelyThatParentHasReLayouted()
return

super

# here we are disabling all the broken
# rectangles. The reason is that all the
# submorphs of the inspector are within the
Expand Down Expand Up @@ -194,6 +192,7 @@ class FridgeMagnetsMorph extends Widget
Automator.alignmentOfMorphIDsMechanism
world.alignIDsOfNextMorphsInSystemTests()

super
@layoutIsValid = true
@notifyAllChildrenRecursivelyThatParentHasReLayouted()

Expand Down
1 change: 1 addition & 0 deletions src/graphs-plots-charts/AxisWdgt.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ class AxisWdgt extends Widget
trackChanges.pop()
@fullChanged()

super
@layoutIsValid = true
@notifyAllChildrenRecursivelyThatParentHasReLayouted()

Expand Down
1 change: 1 addition & 0 deletions src/graphs-plots-charts/PlotWithAxesWdgt.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class PlotWithAxesWdgt extends Widget
trackChanges.pop()
@fullChanged()

super
@layoutIsValid = true
@notifyAllChildrenRecursivelyThatParentHasReLayouted()

Expand Down
1 change: 1 addition & 0 deletions src/icons/GenericObjectIconWdgt.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class GenericObjectIconWdgt extends Widget
trackChanges.pop()
@fullChanged()

super
@layoutIsValid = true
@notifyAllChildrenRecursivelyThatParentHasReLayouted()

Expand Down
1 change: 1 addition & 0 deletions src/icons/GenericShortcutIconWdgt.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class GenericShortcutIconWdgt extends Widget
trackChanges.pop()
@fullChanged()

super
@layoutIsValid = true
@notifyAllChildrenRecursivelyThatParentHasReLayouted()

Expand Down
Loading

0 comments on commit 837b772

Please sign in to comment.