Skip to content

Commit

Permalink
Added more notifications for before/after glyph margins change (#253)
Browse files Browse the repository at this point in the history
  • Loading branch information
andyclymer authored and benkiel committed Oct 4, 2019
1 parent 87755e8 commit 4cecdb4
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions Lib/defcon/objects/glyph.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ class Glyph(BaseObject):
- Glyph.UnicodesChanged
- Glyph.WidthChanged
- Glyph.HeightChanged
- Glyph.LeftMarginWillChange
- Glyph.LeftMarginDidChange
- Glyph.RightMarginWillChange
- Glyph.RightMarginDidChange
- Glyph.TopMarginWillChange
- Glyph.TopMarginDidChange
- Glyph.BottomMarginWillChange
- Glyph.BottomMarginDidChange
- Glyph.NoteChanged
- Glyph.LibChanged
- Glyph.ImageChanged
Expand Down Expand Up @@ -288,11 +296,13 @@ def _set_leftMargin(self, value):
oldValue = xMin
diff = value - xMin
if value != oldValue:
self.postNotification(notification="Glyph.LeftMarginWillChange", data=dict(oldValue=oldValue, newValue=value))
self.move((diff, 0))
self.width += diff
self.dirty = True
self.postNotification(notification="Glyph.LeftMarginDidChange", data=dict(oldValue=oldValue, newValue=value))

leftMargin = property(_get_leftMargin, _set_leftMargin, doc="The left margin of the glyph. Setting this post *Glyph.WidthChanged* and *Glyph.Changed* notifications among others.")
leftMargin = property(_get_leftMargin, _set_leftMargin, doc="The left margin of the glyph. Setting this posts *Glyph.WidthChanged*, *Glyph.LeftMarginWillChange*, *Glyph.LeftMarginDidChange* and *Glyph.Changed* notifications among others.")

def _get_rightMargin(self):
bounds = self.bounds
Expand All @@ -308,10 +318,12 @@ def _set_rightMargin(self, value):
xMin, yMin, xMax, yMax = bounds
oldValue = self._width - xMax
if oldValue != value:
self.postNotification(notification="Glyph.RightMarginWillChange", data=dict(oldValue=oldValue, newValue=value))
self.width = xMax + value
self.dirty = True
self.postNotification(notification="Glyph.RightMarginDidChange", data=dict(oldValue=oldValue, newValue=value))

rightMargin = property(_get_rightMargin, _set_rightMargin, doc="The right margin of the glyph. Setting this posts *Glyph.WidthChanged* and *Glyph.Changed* notifications among others.")
rightMargin = property(_get_rightMargin, _set_rightMargin, doc="The right margin of the glyph. Setting this posts *Glyph.WidthChanged*, *Glyph.RightMarginWillChange*, *Glyph.RightMarginDidChange* and *Glyph.Changed* notifications among others.")

def _get_bottomMargin(self):
bounds = self.bounds
Expand All @@ -335,10 +347,12 @@ def _set_bottomMargin(self, value):
oldValue = yMin - (self.verticalOrigin - self.height)
diff = value - oldValue
if value != oldValue:
self.postNotification(notification="Glyph.BottomMarginWillChange", data=dict(oldValue=oldValue, newValue=value))
self.height += diff
self.dirty = True
self.postNotification(notification="Glyph.BottomMarginDidChange", data=dict(oldValue=oldValue, newValue=value))

bottomMargin = property(_get_bottomMargin, _set_bottomMargin, doc="The bottom margin of the glyph. Setting this post *Glyph.HeightChanged* and *Glyph.Changed* notifications among others.")
bottomMargin = property(_get_bottomMargin, _set_bottomMargin, doc="The bottom margin of the glyph. Setting this posts *Glyph.HeightChanged*, *Glyph.BottomMarginWillChange*, *Glyph.BottomMarginDidChange* and *Glyph.Changed* notifications among others.")

def _get_topMargin(self):
bounds = self.bounds
Expand All @@ -361,11 +375,13 @@ def _set_topMargin(self, value):
oldValue = self.verticalOrigin - yMax
diff = value - oldValue
if oldValue != value:
self.postNotification(notification="Glyph.TopMarginWillChange", data=dict(oldValue=oldValue, newValue=value))
self.verticalOrigin = yMax + value
self.height += diff
self.dirty = True
self.postNotification(notification="Glyph.TopMarginWillChange", data=dict(oldValue=oldValue, newValue=value))

topMargin = property(_get_topMargin, _set_topMargin, doc="The top margin of the glyph. Setting this posts *Glyph.HeightChanged*, *Glyph.VerticalOriginChanged* and *Glyph.Changed* notifications among others.")
topMargin = property(_get_topMargin, _set_topMargin, doc="The top margin of the glyph. Setting this posts *Glyph.HeightChanged*, *Glyph.VerticalOriginChanged*, *Glyph.TopMarginWillChange*, *Glyph.TopMarginDidChange* and *Glyph.Changed* notifications among others.")

# width

Expand Down

0 comments on commit 4cecdb4

Please sign in to comment.