Using effective font name for text in a widget?

LiveCode Builder is a language for extending LiveCode's capabilities, creating new object types as Widgets, and libraries that access lower-level APIs in OSes, applications, and DLLs.

Moderators: LCMark, LCfraser

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 993
Joined: Sat Apr 08, 2006 3:06 pm
Location: Overland Park, Kansas
Contact:

Using effective font name for text in a widget?

Post by trevordevore » Wed Mar 11, 2015 3:08 pm

How would I go about rendering text with the effective font of a widget? I want to leave the font name blank but be able to set the text size. I tried getting the font of the canvas in OnCreate() and grab the font name that way but I just got errors.
Trevor DeVore
ScreenSteps - https://www.screensteps.com

LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder

LCMark
Livecode Staff Member
Livecode Staff Member
Posts: 1095
Joined: Thu Apr 11, 2013 11:27 am

Re: Using effective font name for text in a widget?

Post by LCMark » Wed Mar 11, 2015 3:51 pm

@trevordevore: At the moment, the answer to this question is 'with difficulty' - i.e. there isn't a way to do this.

At the moment textFont, textSize and textStyle are unreserved properties of widgets meaning you have to define them yourself but you get no inheritance.

In the short-term we could reserve them (make the engine manage them) and allow you to access the the widget's current font using 'my font'. This could go hand-in-hand with a 'OnFontChanged' event which occurs when the effective font changes.

LCfraser
Livecode Staff Member
Livecode Staff Member
Posts: 71
Joined: Thu Nov 28, 2013 11:18 am
Contact:

Re: Using effective font name for text in a widget?

Post by LCfraser » Wed Mar 11, 2015 3:53 pm

Something else worth noting is that the canvas only exists for the duration of the OnPaint event; it doesn't exist during any other events.

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 993
Joined: Sat Apr 08, 2006 3:06 pm
Location: Overland Park, Kansas
Contact:

Re: Using effective font name for text in a widget?

Post by trevordevore » Wed Mar 11, 2015 3:55 pm

@runrevmark - Personally I would prefer to have the engine reserve them and be able to access the settings. Not being able to inherit the font means extra code for looping through and setting the font on each widget.

@LCfraser - that is good to know. I wasn't aware of that.

BTW, I'm having a great time with widgets :-)
Trevor DeVore
ScreenSteps - https://www.screensteps.com

LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder

LCfraser
Livecode Staff Member
Livecode Staff Member
Posts: 71
Joined: Thu Nov 28, 2013 11:18 am
Contact:

Re: Using effective font name for text in a widget?

Post by LCfraser » Wed Mar 11, 2015 3:56 pm

@trevordevore - glad to hear it. We're looking forward to seeing what everyone has been creating.

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 993
Joined: Sat Apr 08, 2006 3:06 pm
Location: Overland Park, Kansas
Contact:

Re: Using effective font name for text in a widget?

Post by trevordevore » Wed Mar 11, 2015 4:00 pm

@LCFraser - you should come to New York tomorrow then :-)
Trevor DeVore
ScreenSteps - https://www.screensteps.com

LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder

LCMark
Livecode Staff Member
Livecode Staff Member
Posts: 1095
Joined: Thu Apr 11, 2013 11:27 am

Re: Using effective font name for text in a widget?

Post by LCMark » Wed Mar 11, 2015 4:05 pm

@trevordevore: Yes - I think that is the best approach for now... It should be possible to make 'inherited' properties general things including 'effective changed' type triggers. The idea is that eventually widget's will inherit from a common set of functionality which emulates the engine functionality but completely in LCB, rather than mixing the old engine logic and new widget logic. That is a little way off though :)

LCMark
Livecode Staff Member
Livecode Staff Member
Posts: 1095
Joined: Thu Apr 11, 2013 11:27 am

Re: Using effective font name for text in a widget?

Post by LCMark » Thu Mar 12, 2015 3:25 pm

@trevordevore: I've filed this request as : http://quality.runrev.com/show_bug.cgi?id=14898

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 993
Joined: Sat Apr 08, 2006 3:06 pm
Location: Overland Park, Kansas
Contact:

Re: Using effective font name for text in a widget?

Post by trevordevore » Thu Mar 12, 2015 3:49 pm

Thanks @runrevmark.
Trevor DeVore
ScreenSteps - https://www.screensteps.com

LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder

LCMark
Livecode Staff Member
Livecode Staff Member
Posts: 1095
Joined: Thu Apr 11, 2013 11:27 am

Re: Using effective font name for text in a widget?

Post by LCMark » Fri Mar 13, 2015 3:07 pm

@trevordevore: Here's a pull request for this feature - http://quality.runrev.com/show_bug.cgi?id=14898

It adds the 'my font' syntax which returns a Canvas.Font, derived from the textFont, textSize and textStyle properties.

The textFont, textSize and textStyle properties are now reserved by the engine.

When they change you'll get an OnParentPropertyChanged event where you can take any appropriate action (such as measuring things again and such).

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 993
Joined: Sat Apr 08, 2006 3:06 pm
Location: Overland Park, Kansas
Contact:

Re: Using effective font name for text in a widget?

Post by trevordevore » Fri Mar 13, 2015 3:08 pm

Fantastic. Thanks Mark.
Trevor DeVore
ScreenSteps - https://www.screensteps.com

LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 993
Joined: Sat Apr 08, 2006 3:06 pm
Location: Overland Park, Kansas
Contact:

Re: Using effective font name for text in a widget?

Post by trevordevore » Fri Mar 13, 2015 5:12 pm

LCMark - Is there a way to determine which property changed in OnParentPropertyChanged? I would only want to redraw all if one of the text properties was modified. Or are those the only parent props that get inherited?
Trevor DeVore
ScreenSteps - https://www.screensteps.com

LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder

LCMark
Livecode Staff Member
Livecode Staff Member
Posts: 1095
Joined: Thu Apr 11, 2013 11:27 am

Re: Using effective font name for text in a widget?

Post by LCMark » Fri Mar 13, 2015 5:19 pm

@trevordevore: At the moment there is no way to do that - the engine doesn't pass that information along to any control. The engine (I believe) also does a redraw all on any widget which has its parent property changed anyway - so even if you could find out, you would still end up being redrawn. (This isn't too much of an issue though - the engine needs to repaint any children completely if a parent prop changes which isn't text related as it might affect the background behind semi-opaque widgets if it is one of the colors).

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 993
Joined: Sat Apr 08, 2006 3:06 pm
Location: Overland Park, Kansas
Contact:

Re: Using effective font name for text in a widget?

Post by trevordevore » Fri Mar 13, 2015 5:43 pm

Ah, I didn't realize it would be redrawn automatically. All good now.
Trevor DeVore
ScreenSteps - https://www.screensteps.com

LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder

LCMark
Livecode Staff Member
Livecode Staff Member
Posts: 1095
Joined: Thu Apr 11, 2013 11:27 am

Re: Using effective font name for text in a widget?

Post by LCMark » Fri Mar 13, 2015 5:59 pm

@trevordevore: I still suggest doing a redraw all when you think you need to (in parentpropchanged) just in case the engine becomes a little more discerning in the future!

Post Reply

Return to “LiveCode Builder”