i have pet chickens, i make drawings, and i write software of questionable usefulness. that's pretty much the extent of my personality. ask me about array programming, decker, or anything, really.


floconsugar
@floconsugar asked:

Hey IJ, I was playing around with the "magnetic poetry" slide of the Draggable example deck. I went in Widgets mode to switch the font of the field in which I type the words, but the magnets still come out with the default font (I figured it couldn't be that easy but I tried anyway haha). Is there a way to change the magnet's font?
I'm merely being curious, but I thought I could ask anyway, in case this could be useful for other people too :)

For context, the Magnetic Poetry card is here.

The script of the "Make Magnet" button looks like this:

on click do
 s:deck.fonts.body.textsize[word.text]
 c:card.add["canvas"]
 c.draggable:1
 c.size:10+s
 c.pos:(card.size-c.size)/2
 c.text[word.text 5,5]
end

It's creating a new Canvas widget, sized to suit the text, making it draggable, centering it within the magnetic poetry area, and then drawing the word on that canvas. The font is hardcoded, but it wouldn't be too hard to change it to another hardcoded value, or perhaps to respect the font configured on the field word. Either approach would require one changed line and one added line. Can you work it out? (Solution below the fold!)


on click do
 s:word.font.textsize[word.text]
 c:card.add["canvas"]
 c.draggable:1
 c.size:10+s
 c.pos:(card.size-c.size)/2
 c.font:word.font
 c.text[word.text 5,5]
end

The change to the line that computes s is fairly obvious: we need to measure the text using our intended source font. The other detail we need to handle is setting the .font property of our Canvas so that the .text[] method uses it when drawing the word.


You must log in to comment.