Difference between revisions of "on.resize"
Jump to navigation
Jump to search
(3 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
The event '''on.resize''' is fired when the user resizes the window where the lua script is. | The event '''on.resize''' is fired when the user resizes the window where the lua script is. | ||
− | It | + | It can pass two arguments (the new width and the new height) : See 2nd example. |
It's a good place to put your global window-size-related variable since this event only fires when the script's frame's size changes (see Example). | It's a good place to put your global window-size-related variable since this event only fires when the script's frame's size changes (see Example). | ||
Line 7: | Line 7: | ||
== Example == | == Example == | ||
− | Below is an example of a program that creates/updates the "theHeight" | + | Below is an example of a program that creates/updates the "theHeight" and "theWidth" global variables whenever the user resizes the widget's frame: |
<source lang="lua"> | <source lang="lua"> | ||
− | function on.resize() --Define a function for the | + | function on.resize() --Define a function for the events |
theWidth = platform.window:width() | theWidth = platform.window:width() | ||
theHeight = platform.window:height() | theHeight = platform.window:height() | ||
Line 15: | Line 15: | ||
</source> | </source> | ||
− | You can then refer to the height and the width of the widget by calling the global variables instead of the [[Category:platform.window]] methods. | + | This is a better way, though : |
+ | <source lang="lua"> | ||
+ | function on.resize(x, y) -- Yes, on.resize can pass the new width and height, so why not use it ;-) | ||
+ | theWidth = x | ||
+ | theHeight = y | ||
+ | end | ||
+ | </source> | ||
+ | |||
+ | You can then refer to the height and the width of the widget by calling the global variables instead of the [[:Category:platform.window|platform.window]] methods. | ||
[[Category:Events]] | [[Category:Events]] |
Latest revision as of 01:21, 16 January 2012
The event on.resize is fired when the user resizes the window where the lua script is.
It can pass two arguments (the new width and the new height) : See 2nd example.
It's a good place to put your global window-size-related variable since this event only fires when the script's frame's size changes (see Example).
Example
Below is an example of a program that creates/updates the "theHeight" and "theWidth" global variables whenever the user resizes the widget's frame:
function on.resize() --Define a function for the events
theWidth = platform.window:width()
theHeight = platform.window:height()
end
This is a better way, though :
function on.resize(x, y) -- Yes, on.resize can pass the new width and height, so why not use it ;-)
theWidth = x
theHeight = y
end
You can then refer to the height and the width of the widget by calling the global variables instead of the platform.window methods.