<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.inspired-lua.org/index.php?action=history&amp;feed=atom&amp;title=platform.withGC</id>
	<title>platform.withGC - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.inspired-lua.org/index.php?action=history&amp;feed=atom&amp;title=platform.withGC"/>
	<link rel="alternate" type="text/html" href="https://wiki.inspired-lua.org/index.php?title=platform.withGC&amp;action=history"/>
	<updated>2026-05-19T07:39:11Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.33.0</generator>
	<entry>
		<id>https://wiki.inspired-lua.org/index.php?title=platform.withGC&amp;diff=726&amp;oldid=prev</id>
		<title>Adriweb: Created page with &quot;platform.'''withGC''' is a function that is part of the platform library.  Executes ''function(args)'' within a dummy graphics context and returns all retu...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.inspired-lua.org/index.php?title=platform.withGC&amp;diff=726&amp;oldid=prev"/>
		<updated>2012-06-06T20:53:19Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;platform.&amp;#039;&amp;#039;&amp;#039;withGC&amp;#039;&amp;#039;&amp;#039; is a function that is part of the &lt;a href=&quot;/Category:platform&quot; title=&quot;Category:platform&quot;&gt;platform&lt;/a&gt; library.  Executes &amp;#039;&amp;#039;function(args)&amp;#039;&amp;#039; within a dummy graphics context and returns all retu...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;platform.'''withGC''' is a function that is part of the [[:Category:platform|platform]] library.&lt;br /&gt;
&lt;br /&gt;
Executes ''function(args)'' within a dummy graphics context and returns all return values from ''function()''. &amp;lt;br /&amp;gt;&lt;br /&gt;
It is typically used to measure pixel lengths and heights of strings when a normal graphics context is not available. This may be the case when creating new text elements when the script app is initialized. A graphics context is available only during paint events, and that may be too late to create and size the containers for text fields. &amp;lt;br /&amp;gt;&lt;br /&gt;
This graphics context should not be used to draw graphics since it is not associated with a window. ￼￼￼￼￼￼&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Since|3.2}}&lt;br /&gt;
&lt;br /&gt;
== Syntax  ==&lt;br /&gt;
platform.'''withGC'''(func, funcArgs...) &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Parameter !! Type !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;u&amp;gt;&amp;lt;center&amp;gt;func&amp;lt;/center&amp;gt;&amp;lt;/u&amp;gt; || function || name of function to call&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;u&amp;gt;&amp;lt;center&amp;gt;funcArgs&amp;lt;/center&amp;gt;&amp;lt;/u&amp;gt; || (any) || The arguments of the function ''func''&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
Here is an example of using withGC() to get the pixel length and height of a string :&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;function setFont(family, style, size, gc)&lt;br /&gt;
    return gc:setFont(family, style, size) -- Sets the font to use&lt;br /&gt;
end&lt;br /&gt;
function getHeightWidth(str, gc)&lt;br /&gt;
    width = gc:getStringWidth(str) -- Gets the pixel length of str&lt;br /&gt;
    height = gc:getStringHeight(str) -- Gets the pixel height of str&lt;br /&gt;
    return height, width&lt;br /&gt;
end&lt;br /&gt;
platform.withGC(setFont, 'serif', 'b', 12)&lt;br /&gt;
height, width = platform.withGC(getHeightWidth, 'Hello World')&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Note: You could combine the two functions above into a single one in order to avoid calling withGC() twice, but that is not required since the dummy graphics context remembers its state. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== See also  ==&lt;br /&gt;
*[[on.paint]](gc)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:platform]]&lt;/div&gt;</summary>
		<author><name>Adriweb</name></author>
		
	</entry>
</feed>