Using the zoomViewToRect I managed to dig up some other info in the forums and almost got this working like I want, albeit with rather empirical values for the scaling.
I don’t entirely understand how the zoomViewToRect works, though, and why in the below code I sometimes need to trigger the scrollRectToVisible to jump to the right spot in the editor tab.
Basically, when I double click a glyph in the preview bar, I’d like to automatically jump the view to that glyph and scale it to cover most of the edit tab. I’ve got the glyph change hooked up alright, and this works, mostly. Only sometimes glyphs in the same “row” (?) seem to not trigger a rescale and recenter. Also, I reckon the scaling factors are not very clean and just seem to work well enough for me.
tab = Glyphs.fonts[0].currentTab
layer = tab.layers[tab.layersCursor]
scale = tab.scale
shrink = 1.75 # magic number to vertically scale the glyph down enough
rect = NSMakeRect(
tab.selectedLayerOrigin.x,
tab.selectedLayerOrigin.y - (layer.bounds.size.height * tab.scale / 2), # magic number to center the glyph vertically
layer.width * tab.scale * shrink,
layer.bounds.size.height * tab.scale * shrink)
view = Glyphs.fonts[0].currentTab.graphicView()
view.scrollRectToVisible_(rect)
view.zoomViewToRect_(rect)
Is there something better to use than layer.bounds.size.height for getting the glyph’s height?
Any ideas why does this not take effect when glyphs are very close to each other (like 2 or 3 glyphs apart, but off screen at enough zoom)?
Is there a Glyph-way of giving the user an option to store the scale factor and store it between restarts? I.E. setting a constant?