Difference between revisions of "Sprite:setLayoutParameters"

From GiderosMobile
(added example)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
 +
 
<languages />
 
<languages />
'''<translate>Available since</translate>:''' Gideros 2018.9<br/>
+
 
'''<translate>Class</translate>:''' [[Special:MyLanguage/Sprite|Sprite]]<br/>
+
'''<translate>Available since</translate>:''' Gideros 2018.9
 +
<br/>
 +
 
 +
'''<translate>Class</translate>:''' [[Special:MyLanguage/Sprite|Sprite]]
 +
<br/>
 +
 
 
=== <translate>Description</translate> ===
 
=== <translate>Description</translate> ===
<translate><br />
+
<translate>
<br />
 
 
Gideros Layout arranges a sprite's children into cells of a grid. With this method, you tell the parent's sprite how the rows and columns of the layout grid should be sized.
 
Gideros Layout arranges a sprite's children into cells of a grid. With this method, you tell the parent's sprite how the rows and columns of the layout grid should be sized.
 +
<br/>
 +
 
If there is extra space available after applying minimum widths and heights, it is distributed according to relative weights of each row/column.
 
If there is extra space available after applying minimum widths and heights, it is distributed according to relative weights of each row/column.
 +
<br/>
 +
 
Gideros layout system is heavily based on Java GridBagLayout principle. See here for more explanation:
 
Gideros layout system is heavily based on Java GridBagLayout principle. See here for more explanation:
 
https://www.math.uni-hamburg.de/doc/java/tutorial/uiswing/layout/gridbag.html
 
https://www.math.uni-hamburg.de/doc/java/tutorial/uiswing/layout/gridbag.html
 +
<br/>
  
 
The following parameters apply:
 
The following parameters apply:
* '''columnWidths''': an array of minimum width for each column<br/>
+
* '''columnWidths''': an array of minimum width for each column
* '''rowHeights''': an array of minimum height for each row<br/>
+
* '''rowHeights''': an array of minimum height for each row
* '''columnWeights''': an array of relative weights for each column<br/>
+
* '''columnWeights''': an array of relative weights for each column
* '''rowWeights''': an array of relative weights for each row<br/>
+
* '''rowWeights''': an array of relative weights for each row
* '''insetTop''': the top margin<br/>
+
* '''insetTop''': the top margin
* '''insetLeft''': the left margin<br/>
+
* '''insetLeft''': the left margin
* '''insetBottom''': the bottom margin<br/>
+
* '''insetBottom''': the bottom margin
* '''insetRight''': the right margin<br/>
+
* '''insetRight''': the right margin
 +
<br/>
 +
 
 +
Specifying a '''nil''' table will clear layout parameters.
 +
</translate>
  
Specifying a '''nil''' table will clear layout parameters.</translate>
 
 
<source lang="lua">
 
<source lang="lua">
Sprite:setLayoutParameters(layout)
+
Sprite:setLayoutParameters(layout)
 
</source>
 
</source>
 +
 
=== <translate>Parameters</translate> ===
 
=== <translate>Parameters</translate> ===
'''layout''': (table) <translate>Table of layout parameters.</translate> <br/>
+
'''layout''': (table) <translate>Table of layout parameters.</translate>
 +
<br/>
 +
 
 +
=== <translate>Examples</translate> ===
 +
'''Example''':
 +
<br/>
 +
 
 +
<source lang="lua">
 +
-- LAYOUT CONSTRAINTS @hgy29
 +
local ticket = Bitmap.new(Texture.new("gfx/vip/ticket.png"))
 +
local text = Bitmap.new(Texture.new("gfx/vip/text.png"))
 +
 +
-- Use auto layout on ticket to center text automatically
 +
ticket:setLayoutParameters{ rowWeights = {1}, columnWeights = {1} }
 +
text:setLayoutConstraints{}
 +
 
 +
ticket:addChild(text)
 +
stage:addChild(ticket)
 +
</source>
 +
<br/>
 +
<br/>

Revision as of 09:14, 16 September 2019



Available since: Gideros 2018.9

Class: Sprite

Description

Gideros Layout arranges a sprite's children into cells of a grid. With this method, you tell the parent's sprite how the rows and columns of the layout grid should be sized.

If there is extra space available after applying minimum widths and heights, it is distributed according to relative weights of each row/column.

Gideros layout system is heavily based on Java GridBagLayout principle. See here for more explanation: https://www.math.uni-hamburg.de/doc/java/tutorial/uiswing/layout/gridbag.html

The following parameters apply:

  • columnWidths: an array of minimum width for each column
  • rowHeights: an array of minimum height for each row
  • columnWeights: an array of relative weights for each column
  • rowWeights: an array of relative weights for each row
  • insetTop: the top margin
  • insetLeft: the left margin
  • insetBottom: the bottom margin
  • insetRight: the right margin


Specifying a nil table will clear layout parameters.

Sprite:setLayoutParameters(layout)

Parameters

layout: (table) Table of layout parameters.

Examples

Example:

-- LAYOUT CONSTRAINTS @hgy29
local ticket = Bitmap.new(Texture.new("gfx/vip/ticket.png"))
local text = Bitmap.new(Texture.new("gfx/vip/text.png"))
 
-- Use auto layout on ticket to center text automatically
ticket:setLayoutParameters{ rowWeights = {1}, columnWeights = {1} }
text:setLayoutConstraints{}

ticket:addChild(text)
stage:addChild(ticket)