Difference between revisions of "Sprite:setLayoutConstraints"
(added the start of an example + fixed some typo) |
|||
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 | + | <translate> |
− | + | This function specify the child placement rules within the grid defined on its parent by [[Special:MyLanguage/Sprite:setLayoutParameters|Sprite:setLayoutParameters]]. | |
− | This function specify the child placement rules within the grid defined on its parent by [[Special:MyLanguage/Sprite:setLayoutParameters|Sprite:setLayoutParameters]].<br /> | + | <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 constraint table can contain the following fields: | The constraint table can contain the following fields: | ||
− | * '''gridx''': The 0-based index of the column the child must be placed into | + | * '''gridx''': The 0-based index of the column the child must be placed into |
− | * '''gridy''': The 0-based index of the row the child must be placed into | + | * '''gridy''': The 0-based index of the row the child must be placed into |
− | * '''gridwidth''': The number of column this child will take | + | * '''gridwidth''': The number of column this child will take |
− | * '''gridheight''': The number of row this child will take | + | * '''gridheight''': The number of row this child will take |
− | * '''weightx''': The horizontal weight of the child. Used to distribute extra space among children | + | * '''weightx''': The horizontal weight of the child. Used to distribute extra space among children |
− | * '''weighty''': The vertical weight of the child. Used to distribute extra space among children | + | * '''weighty''': The vertical weight of the child. Used to distribute extra space among children |
* '''anchor''': Defines where the child should be placed inside its grid space. | * '''anchor''': Defines where the child should be placed inside its grid space. | ||
Can be [[Special:MyLanguage/Sprite.LAYOUT_ANCHOR_NORTHWEST|Sprite.LAYOUT_ANCHOR_NORTHWEST]], [[Special:MyLanguage/Sprite.LAYOUT_ANCHOR_NORTH|Sprite.LAYOUT_ANCHOR_NORTH]], [[Special:MyLanguage/Sprite.LAYOUT_ANCHOR_NORTHEAST|Sprite.LAYOUT_ANCHOR_NORTHEAST]], | Can be [[Special:MyLanguage/Sprite.LAYOUT_ANCHOR_NORTHWEST|Sprite.LAYOUT_ANCHOR_NORTHWEST]], [[Special:MyLanguage/Sprite.LAYOUT_ANCHOR_NORTH|Sprite.LAYOUT_ANCHOR_NORTH]], [[Special:MyLanguage/Sprite.LAYOUT_ANCHOR_NORTHEAST|Sprite.LAYOUT_ANCHOR_NORTHEAST]], | ||
[[Special:MyLanguage/Sprite.LAYOUT_ANCHOR_WEST|Sprite.LAYOUT_ANCHOR_WEST]], [[Special:MyLanguage/Sprite.LAYOUT_ANCHOR_CENTER|Sprite.LAYOUT_ANCHOR_CENTER]], [[Special:MyLanguage/Sprite.LAYOUT_ANCHOR_EAST|Sprite.LAYOUT_ANCHOR_EAST]], | [[Special:MyLanguage/Sprite.LAYOUT_ANCHOR_WEST|Sprite.LAYOUT_ANCHOR_WEST]], [[Special:MyLanguage/Sprite.LAYOUT_ANCHOR_CENTER|Sprite.LAYOUT_ANCHOR_CENTER]], [[Special:MyLanguage/Sprite.LAYOUT_ANCHOR_EAST|Sprite.LAYOUT_ANCHOR_EAST]], | ||
− | [[Special:MyLanguage/Sprite.LAYOUT_ANCHOR_SOUTHWEST|Sprite.LAYOUT_ANCHOR_SOUTHWEST]], [[Special:MyLanguage/Sprite.LAYOUT_ANCHOR_SOUTH|Sprite.LAYOUT_ANCHOR_SOUTH]] or [[Special:MyLanguage/Sprite.LAYOUT_ANCHOR_SOUTHEAST|Sprite.LAYOUT_ANCHOR_SOUTHEAST]] | + | [[Special:MyLanguage/Sprite.LAYOUT_ANCHOR_SOUTHWEST|Sprite.LAYOUT_ANCHOR_SOUTHWEST]], [[Special:MyLanguage/Sprite.LAYOUT_ANCHOR_SOUTH|Sprite.LAYOUT_ANCHOR_SOUTH]] or [[Special:MyLanguage/Sprite.LAYOUT_ANCHOR_SOUTHEAST|Sprite.LAYOUT_ANCHOR_SOUTHEAST]] |
− | * '''fill''': In which directions the child should be expanded to fit the grid space. Can be [[Special:MyLanguage/Sprite.LAYOUT_FILL_NONE|Sprite.LAYOUT_FILL_NONE]], [[Special:MyLanguage/Sprite.LAYOUT_FILL_HORIZONTAL|Sprite.LAYOUT_FILL_HORIZONTAL]], [[Special:MyLanguage/Sprite.LAYOUT_FILL_VERTICAL|Sprite.LAYOUT_FILL_VERTICAL]] or [[Special:MyLanguage/Sprite.LAYOUT_FILL_BOTH|Sprite.LAYOUT_FILL_BOTH]] | + | * '''fill''': In which directions the child should be expanded to fit the grid space. |
− | * '''ipadx''': Internal horizontal padding | + | Can be [[Special:MyLanguage/Sprite.LAYOUT_FILL_NONE|Sprite.LAYOUT_FILL_NONE]], [[Special:MyLanguage/Sprite.LAYOUT_FILL_HORIZONTAL|Sprite.LAYOUT_FILL_HORIZONTAL]], [[Special:MyLanguage/Sprite.LAYOUT_FILL_VERTICAL|Sprite.LAYOUT_FILL_VERTICAL]] or [[Special:MyLanguage/Sprite.LAYOUT_FILL_BOTH|Sprite.LAYOUT_FILL_BOTH]] |
− | * '''ipady''': Internal vertical padding | + | * '''ipadx''': Internal horizontal padding |
− | * '''minWidth''': Minimum width | + | * '''ipady''': Internal vertical padding |
− | * '''minHeight''': Minimum height | + | * '''minWidth''': Minimum width |
− | * '''prefWidth''': Preferred width | + | * '''minHeight''': Minimum height |
− | * '''prefHeight''': Preferred height | + | * '''prefWidth''': Preferred width |
− | * '''insetTop''': the top margin | + | * '''prefHeight''': Preferred height |
− | * '''insetLeft''': the left margin | + | * '''insetTop''': the top margin |
− | * '''insetBottom''': the bottom margin | + | * '''insetLeft''': the left margin |
− | * '''insetRight''': the right margin<br/> | + | * '''insetBottom''': the bottom margin |
+ | * '''insetRight''': the right margin | ||
+ | <br/> | ||
Specifying a '''nil''' table will clear layout constraints. | Specifying a '''nil''' table will clear layout constraints. | ||
− | When a [[Special:MyLanguage/Sprite|Sprite]] is resized by the layout system, | + | <br/> |
+ | When a [[Special:MyLanguage/Sprite|Sprite]] is resized by the layout system, an ''Event.LAYOUT_RESIZED'' is triggered. | ||
+ | </translate> | ||
+ | |||
+ | |||
<source lang="lua"> | <source lang="lua"> | ||
− | + | Sprite:setLayoutConstraints(constraints) | |
</source> | </source> | ||
+ | |||
=== <translate>Parameters</translate> === | === <translate>Parameters</translate> === | ||
− | '''constraints''': (table) <translate>Table of layout constraints.</translate> <br/> | + | '''constraints''': (table) <translate>Table of layout constraints.</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:31, 16 September 2019
Available since: Gideros 2018.9
Class: Sprite
Description
This function specify the child placement rules within the grid defined on its parent by Sprite:setLayoutParameters.
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 constraint table can contain the following fields:
- gridx: The 0-based index of the column the child must be placed into
- gridy: The 0-based index of the row the child must be placed into
- gridwidth: The number of column this child will take
- gridheight: The number of row this child will take
- weightx: The horizontal weight of the child. Used to distribute extra space among children
- weighty: The vertical weight of the child. Used to distribute extra space among children
- anchor: Defines where the child should be placed inside its grid space.
Can be Sprite.LAYOUT_ANCHOR_NORTHWEST, Sprite.LAYOUT_ANCHOR_NORTH, Sprite.LAYOUT_ANCHOR_NORTHEAST, Sprite.LAYOUT_ANCHOR_WEST, Sprite.LAYOUT_ANCHOR_CENTER, Sprite.LAYOUT_ANCHOR_EAST, Sprite.LAYOUT_ANCHOR_SOUTHWEST, Sprite.LAYOUT_ANCHOR_SOUTH or Sprite.LAYOUT_ANCHOR_SOUTHEAST
- fill: In which directions the child should be expanded to fit the grid space.
Can be Sprite.LAYOUT_FILL_NONE, Sprite.LAYOUT_FILL_HORIZONTAL, Sprite.LAYOUT_FILL_VERTICAL or Sprite.LAYOUT_FILL_BOTH
- ipadx: Internal horizontal padding
- ipady: Internal vertical padding
- minWidth: Minimum width
- minHeight: Minimum height
- prefWidth: Preferred width
- prefHeight: Preferred height
- insetTop: the top margin
- insetLeft: the left margin
- insetBottom: the bottom margin
- insetRight: the right margin
Specifying a nil table will clear layout constraints.
When a Sprite is resized by the layout system, an Event.LAYOUT_RESIZED is triggered.
Sprite:setLayoutConstraints(constraints)
Parameters
constraints: (table) Table of layout constraints.
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)