Skip to content

Instantly share code, notes, and snippets.

@connordavenport
Last active April 20, 2021 14:45
Show Gist options
  • Save connordavenport/e2fc66f0b5f1d2149785c8ed6170e385 to your computer and use it in GitHub Desktop.
Save connordavenport/e2fc66f0b5f1d2149785c8ed6170e385 to your computer and use it in GitHub Desktop.
An observer script to sync background layers with foreground layer
from mojo.events import addObserver, removeObserver
class syncLayerWidths:
def __init__(self):
self.font = None
self.glyph = None
addObserver(self, "glyphChanged", "currentGlyphChanged")
# --------- from Tal's RoboHud ---------------
def beginObservingGlyph(self):
if self.glyph is not None:
self.glyph.addObserver(self, "widthChanged", "Glyph.WidthChanged")
def stopObservingGlyph(self):
self.glyph = CurrentGlyph()
if self.glyph is not None:
self.font = self.glyph.font
self.glyph.removeObserver(self, "Glyph.Changed")
# --------------------------------------------
def glyphChanged(self,info):
self.stopObservingGlyph()
self.beginObservingGlyph()
def widthChanged(self,point):
if self.glyph:
for layerGlyph in self.glyph.layers:
layerGlyph.width = self.glyph.width
syncLayerWidths()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment