<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Adding text to CurrentGlyphView]]></title><description><![CDATA[<p dir="auto">Hi <a class="plugin-mentions-user plugin-mentions-a" href="https://forum.robofont.com/uid/1">@frederik</a>, could you elaborate on how to use <code>CurrentGlyphWindow().addGlyphEditorSubview(yourVanillaView)</code>?</p>
<p dir="auto">I'm trying to set some text in the glyph view:</p>
<p dir="auto"><img src="/assets/uploads/files/1543196661725-screen-shot-2018-11-25-at-8.43.39-pm.png" alt="0_1543196654159_Screen Shot 2018-11-25 at 8.43.39 PM.png" class="img-responsive img-markdown" /></p>
<p dir="auto">For the image above, I used the snippet I found in the Show Coordinates extension.</p>
<p dir="auto">Thanks!</p>
]]></description><link>https://forum.robofont.com/topic/543/adding-text-to-currentglyphview</link><generator>RSS for Node</generator><lastBuildDate>Sun, 14 Jun 2026 10:58:06 GMT</lastBuildDate><atom:link href="https://forum.robofont.com/topic/543.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 26 Nov 2018 01:45:59 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Adding text to CurrentGlyphView on Mon, 26 Nov 2018 10:06:08 GMT]]></title><description><![CDATA[<p dir="auto">Hi <a class="plugin-mentions-user plugin-mentions-a" href="https://forum.robofont.com/uid/1">@frederik</a>, could you elaborate on how to use <code>CurrentGlyphWindow().addGlyphEditorSubview(yourVanillaView)</code>?</p>
<p dir="auto">I'm trying to set some text in the glyph view:</p>
<p dir="auto"><img src="/assets/uploads/files/1543196661725-screen-shot-2018-11-25-at-8.43.39-pm.png" alt="0_1543196654159_Screen Shot 2018-11-25 at 8.43.39 PM.png" class="img-responsive img-markdown" /></p>
<p dir="auto">For the image above, I used the snippet I found in the Show Coordinates extension.</p>
<p dir="auto">Thanks!</p>
]]></description><link>https://forum.robofont.com/post/1870</link><guid isPermaLink="true">https://forum.robofont.com/post/1870</guid><dc:creator><![CDATA[jesentanadi]]></dc:creator><pubDate>Mon, 26 Nov 2018 10:06:08 GMT</pubDate></item><item><title><![CDATA[Reply to Adding text to CurrentGlyphView on Mon, 26 Nov 2018 09:32:16 GMT]]></title><description><![CDATA[<p dir="auto">here’s an example of <code>addGlyphEditorSubview</code>:</p>
<p dir="auto">(I got it from <a class="plugin-mentions-user plugin-mentions-a" href="https://forum.robofont.com/uid/1">@frederik</a> some time ago, made a few small changes only)</p>
<p dir="auto"><img src="/assets/uploads/files/1543224278593-screen-shot-2018-11-26-at-07.22.30-resized.png" alt="0_1543224269517_Screen Shot 2018-11-26 at 07.22.30.png" class="img-responsive img-markdown" /></p>
<pre><code class="language-python">from vanilla import *
import mojo.drawingTools as ctx
from mojo.events import addObserver, removeObserver
from mojo.canvas import CanvasGroup
from mojo.UI import CurrentGlyphWindow

class OverlayViewController(object):
    
    def __init__(self):
        ### for debugging only
        self.w = FloatingWindow((150, 50), "debug only")
        self.w.bind("close", self.windowClose)
        self.w.open()
        ### end debugging
        self.view = None
        addObserver(self, "observerGlyphWindowWillOpen", "glyphWindowWillOpen")
        addObserver(self, "observerDraw", "draw")
        addObserver(self, "observerDrawPreview", "drawPreview")
        
    def windowClose(self, sender):
        removeObserver(self, "glyphWindowWillOpen")
        removeObserver(self, "draw")
        removeObserver(self, "drawPreview")
    
    def observerGlyphWindowWillOpen(self, notification):
        self.window = notification["window"]
        # create a view with some controls
        self.view = CanvasGroup((0, -200, -0, -0), delegate=self)
        self.view.button1 = Button((-130, -40, 120, 22), "Hit Me")
        self.view.button2 = Button((-260, -40, 120, 22), "Show Controls")
        self.view.button2.getNSButton().setShowsBorderOnlyWhileMouseInside_(True)
        self.view.list = List((-260, 10, -10, -50), ["a", "b", "c", "Do SomeThing"]) 
        # add the view to the GlyphEditor
        self.window.addGlyphEditorSubview(self.view)
            
    def observerDraw(self, notification):
        if self.view:
            self.view.show(True)
        
    def observerDrawPreview(self, notification):
        # hide the view in Preview mode
        if self.view:
            self.view.show(False)

    # canvas delegate callbacks
    
    def opaque(self):
        return True
    
    def acceptsFirstResponder(self):
        return False
    
    def acceptsMouseMoved(self):
        return True
        
    def becomeFirstResponder(self):
        return False
    
    def resignFirstResponder(self):
        return False
        
    def shouldDrawBackground(self):
        return False
    
    def draw(self):
        g = self.window.getGlyph()
        if g is None:
            return

        f = g.getParent()
        x, y, w, h = self.window.getVisibleRect()        
        h = self.view.height() - y
        
        # draw a rect around the view area
        ctx.fill(None)        
        ctx.stroke(0, 1, 0)
        ctx.rect(x+5, y+5, w-10, h-10)
        ctx.stroke(None)
        
        # draw some preview glyphs
        testGlyphs = ["n", "o"]
        glyphs = []
        for c in testGlyphs:
            if c in f:
                glyphs.append(f[c])
        glyphs.append(g)

        ctx.scale(0.15)
        ctx.translate(50, 150)        
        ctx.fill(0)
        for glyph in glyphs:
            ctx.drawGlyph(glyph)
            ctx.translate(glyph.width, 0)
        

OverlayViewController()
</code></pre>
<p dir="auto">will be added to the docs soon…</p>
]]></description><link>https://forum.robofont.com/post/1871</link><guid isPermaLink="true">https://forum.robofont.com/post/1871</guid><dc:creator><![CDATA[gferreira]]></dc:creator><pubDate>Mon, 26 Nov 2018 09:32:16 GMT</pubDate></item><item><title><![CDATA[Reply to Adding text to CurrentGlyphView on Mon, 26 Nov 2018 12:19:08 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://forum.robofont.com/uid/22">@gferreira</a> <a class="plugin-mentions-user plugin-mentions-a" href="https://forum.robofont.com/uid/1">@frederik</a> That was really helpful, thank you!</p>
<p dir="auto">If I'm understanding this right, <code>CanvasGroup</code> is a thin layer on top of the glyph view, and we can add whatever <code>vanilla</code> elements to that <code>CanvasGroup</code>?</p>
<p dir="auto">Will play around with this. I'm not sure I understand what all of these delegate callbacks do just yet, since sometimes they're not immediately obvious:</p>
<ul>
<li>
<p dir="auto"><code>opaque()</code> — does this need to be specified if <code>shouldDrawBackground()</code> already returns <code>False</code>?</p>
</li>
<li>
<p dir="auto"><code>acceptsMouseMoved()</code></p>
</li>
<li>
<p dir="auto"><code>becomeFirstResponder()</code> &amp; <code>resignFirstResponder()</code> — do these have to be specified if <code>acceptsFirstResponder()</code> already returns <code>False</code>?</p>
</li>
</ul>
<p dir="auto"><img src="/assets/uploads/files/1543233088008-screen-shot-2018-11-26-at-6.50.00-am-resized.png" alt="0_1543233080466_Screen Shot 2018-11-26 at 6.50.00 AM.png" class="img-responsive img-markdown" /></p>
]]></description><link>https://forum.robofont.com/post/1872</link><guid isPermaLink="true">https://forum.robofont.com/post/1872</guid><dc:creator><![CDATA[jesentanadi]]></dc:creator><pubDate>Mon, 26 Nov 2018 12:19:08 GMT</pubDate></item><item><title><![CDATA[Reply to Adding text to CurrentGlyphView on Mon, 21 Jan 2019 13:09:55 GMT]]></title><description><![CDATA[<p dir="auto">It should not be a <code>CanvasGroup</code>, it could also be a <code>vanilla.Group</code>. In this example it shows how to draw something on top of a glyph view disconnected from the zoom level.</p>
<p dir="auto">The delegate callbacks are related to a <code>CanvasGroup</code>. for more info see <a href="http://robofont.com/documentation/building-tools/api/mojo/mojo-canvas/#mojo.canvas.CanvasGroup" rel="nofollow">mojo.canvas.CanvasGroup</a></p>
]]></description><link>https://forum.robofont.com/post/1873</link><guid isPermaLink="true">https://forum.robofont.com/post/1873</guid><dc:creator><![CDATA[frederik]]></dc:creator><pubDate>Mon, 21 Jan 2019 13:09:55 GMT</pubDate></item><item><title><![CDATA[Reply to Adding text to CurrentGlyphView on Mon, 26 Nov 2018 13:58:29 GMT]]></title><description><![CDATA[<p dir="auto">and if you want to remove the view from the glyph editor: <code>glyphWindow.removeGlyphEditorSubview(view)</code></p>
]]></description><link>https://forum.robofont.com/post/1874</link><guid isPermaLink="true">https://forum.robofont.com/post/1874</guid><dc:creator><![CDATA[frederik]]></dc:creator><pubDate>Mon, 26 Nov 2018 13:58:29 GMT</pubDate></item><item><title><![CDATA[Reply to Adding text to CurrentGlyphView on Mon, 26 Nov 2018 18:11:57 GMT]]></title><description><![CDATA[<p dir="auto">Ok, seems that I can just use <code>vanilla.Group</code> to set text, since I don't need to draw anything.</p>
<p dir="auto">(I asked earlier about disconnecting from the zoom level, but I assume that's what <code>magnifyWithEvent()</code> is for?)</p>
<p dir="auto">Also, will more documentation be added to the page that lists possible delegate methods?</p>
<p dir="auto">And one more thing... this is a bit of a side question, but would you ever use a separate object as a delegate?</p>
<pre><code class="language-python">from vanilla import *
from mojo.events import addObserver, removeObserver
from mojo.canvas import CanvasGroup

class OverlayViewController(object):
    def __init__(self):
        addObserver(self, "observerGlyphWindowWillOpen", "glyphWindowWillOpen")
        addObserver(self, "observerGlyphWindowWillClose", "glyphWindowWillClose")

    def observerGlyphWindowWillOpen(self, notification):
        self.window = notification["window"]
        
        delegateObj = DelegateObj()
        self.view = CanvasGroup((0, -200, -0, -0), delegate=delegateObj)
        self.view.button1 = Button((-130, -40, 120, 22), "Hit Me")

        self.view.show(True)
        self.window.addGlyphEditorSubview(self.view)
            
    def observerGlyphWindowWillClose(self, notification):
        self.window.removeGlyphEditorSubview(self.view)
        removeObserver(self, "glyphWindowWillOpen")
        removeObserver(self, "glyphWindowWillClose")

class DelegateObj:
    def acceptsFirstResponder(self):
        return False
        
    def shouldDrawBackground(self):
        return False
    
    def draw(self):
        print('eh')
        
OverlayViewController()
</code></pre>
]]></description><link>https://forum.robofont.com/post/1876</link><guid isPermaLink="true">https://forum.robofont.com/post/1876</guid><dc:creator><![CDATA[jesentanadi]]></dc:creator><pubDate>Mon, 26 Nov 2018 18:11:57 GMT</pubDate></item><item><title><![CDATA[Reply to Adding text to CurrentGlyphView on Mon, 26 Nov 2018 22:49:34 GMT]]></title><description><![CDATA[<p dir="auto">Each view added with <code>window.addGlyphEditorSubview</code> will be detached from zoom level or panning. The other option is to draw inside the glyph canvas in glyph coordinate space.</p>
<p dir="auto"><code>magnifyWithEvent</code> is an event that is called in a Canvas delegate whenever there is a pinch on a trackpad for example.</p>
]]></description><link>https://forum.robofont.com/post/1877</link><guid isPermaLink="true">https://forum.robofont.com/post/1877</guid><dc:creator><![CDATA[frederik]]></dc:creator><pubDate>Mon, 26 Nov 2018 22:49:34 GMT</pubDate></item><item><title><![CDATA[Reply to Adding text to CurrentGlyphView on Mon, 21 Jan 2019 13:07:08 GMT]]></title><description><![CDATA[<p dir="auto">Maybe this comment is unnecessary, but guys,<br />
<strong>I LOVE THIS POST</strong>, please add it to the docs, it will be easier to find</p>
]]></description><link>https://forum.robofont.com/post/1953</link><guid isPermaLink="true">https://forum.robofont.com/post/1953</guid><dc:creator><![CDATA[RafaŁ Buchner]]></dc:creator><pubDate>Mon, 21 Jan 2019 13:07:08 GMT</pubDate></item><item><title><![CDATA[Reply to Adding text to CurrentGlyphView on Mon, 21 Jan 2019 20:18:56 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://forum.robofont.com/uid/207">@RafaŁ-Buchner</a> thanks for the suggestion! <a href="http://robofont.com/documentation/building-tools/toolspace/observers/glyph-editor-subview/" rel="nofollow">here it is</a></p>
]]></description><link>https://forum.robofont.com/post/1954</link><guid isPermaLink="true">https://forum.robofont.com/post/1954</guid><dc:creator><![CDATA[gferreira]]></dc:creator><pubDate>Mon, 21 Jan 2019 20:18:56 GMT</pubDate></item><item><title><![CDATA[Reply to Adding text to CurrentGlyphView on Mon, 15 Jul 2019 15:50:13 GMT]]></title><description><![CDATA[<p dir="auto">Thanks again for this thread and the sample code. I've made a few tools based on it but have run into a problem I can't seem to solve on my own.</p>
<p dir="auto">If you open more than one glyph window, either from a second font or the same font, the tool breaks in the older windows. Is there a way to make the sample code work with multiple glyph windows open?</p>
]]></description><link>https://forum.robofont.com/post/2518</link><guid isPermaLink="true">https://forum.robofont.com/post/2518</guid><dc:creator><![CDATA[okaytype]]></dc:creator><pubDate>Mon, 15 Jul 2019 15:50:13 GMT</pubDate></item><item><title><![CDATA[Reply to Adding text to CurrentGlyphView on Mon, 15 Jul 2019 20:36:34 GMT]]></title><description><![CDATA[<p dir="auto">I see, you need to keep a dictionary where the window is the key and the view is the item.</p>
<p dir="auto">On <code>glyphWindowWillClose</code> get the window from the notification, remove the view and del the window item in the dictionary.</p>
<p dir="auto">Hope this makes sense :)</p>
]]></description><link>https://forum.robofont.com/post/2519</link><guid isPermaLink="true">https://forum.robofont.com/post/2519</guid><dc:creator><![CDATA[frederik]]></dc:creator><pubDate>Mon, 15 Jul 2019 20:36:34 GMT</pubDate></item><item><title><![CDATA[Reply to Adding text to CurrentGlyphView on Tue, 28 Apr 2020 21:51:37 GMT]]></title><description><![CDATA[<p dir="auto">Thanks, Frederik. I couldn't figure that out, but I did figure out I could subclass the vanilla elements. I think this approach will work better for what I'm doing.</p>
<pre><code class="language-python">from vanilla import *
from mojo.events import addObserver, removeObserver
from AppKit import NSApp, NSColor, NSTextAlignmentCenter, NSTextAlignmentRight, NSTextAlignmentLeft

debug = True

class OverlayViewController(object):

    def __init__(self):

        windowname = 'debug window ui test'
        if debug == True:
            self.w = Window((500, 50), windowname)
            self.w.bind("close", self.windowClose)
            for window in [w for w in NSApp().orderedWindows() if w.isVisible()]:
                if window.title() == windowname:
                    window.close()
            self.w.open()
        self.view = None
        addObserver(self, 'addToGlyphView', 'glyphWindowWillOpen')

    def windowClose(self, sender):
        print('removing observer')
        removeObserver(self, "glyphWindowWillOpen")

    def addToGlyphView(self, notification):

        self.window = notification["window"]

        x, y, w, h = xywh = (0, 0, -0, 22) 
        this = self.testGV = Group(xywh)

        this.text1 = SubClassedEditText(xywh, '-', window=self.window, sizeStyle='mini', continuous=False)

        self.window.addGlyphEditorSubview(this)


class SubClassedEditText(EditText): 

    def __init__(self, *args, **kwargs):
        self.window = kwargs['window']
        del kwargs['window']
        super(SubClassedEditText, self).__init__(*args, **kwargs)

        this = self.getNSTextField()
        this.setBezeled_(False)
        this.setBackgroundColor_(NSColor.redColor())
        this.setAlignment_(NSTextAlignmentCenter)

        addObserver(self, "currentGlyphChanged", "currentGlyphChanged")
    
    def currentGlyphChanged(self, info):
        try:
            g = self.window.getGlyph()
            if g is None: return
            f = g.getParent()
            self.set(f.info.styleName + ' '  + g.name)
        except:
            pass

    def _breakCycles(self):
        super(SubClassedEditText, self)._breakCycles()
        removeObserver(self, "currentGlyphChanged")
    
OverlayViewController()
</code></pre>
]]></description><link>https://forum.robofont.com/post/2525</link><guid isPermaLink="true">https://forum.robofont.com/post/2525</guid><dc:creator><![CDATA[okaytype]]></dc:creator><pubDate>Tue, 28 Apr 2020 21:51:37 GMT</pubDate></item></channel></rss>