Libraries.Interface.Layouts.GridLayout Documentation

The GridLayout class is used to lay out controls in a grid pattern. The grid assumes that all columns have the same width and all rows have the same height. If the layout is applied to a Control, it will create a number of rows and columns based on the value of the Control's Get

Example Code

use Libraries.Game.Game
use Libraries.Interface.Controls.Icon
use Libraries.Game.Graphics.Color
use Libraries.Interface.Layouts.GridLayout

class Main is Game

action Main
    StartGame()
end

action CreateGame
    GridLayout layout
    // Set our layout to have 3 rows and 3 columns by default.
    layout:SetDefaultGridWidth(3)
    layout:SetDefaultGridHeight(3)
    SetLayout(layout)

    // We use the intensity value to change how dark/bright each rectangle is. 
    number intensity = 0

    integer row = 0
    repeat while row < 3
        integer column = 0
        repeat while column < 3
            Icon icon
            // The icons should fill the whole width and height of their cell in the grid.
            icon:SetPercentageWidth(1.0)
            icon:SetPercentageHeight(1.0)

            // Load a colored rectangle into the grid.
            Color color
            color:SetColor(intensity, intensity, intensity, 1)
            icon:LoadFilledRectangle(10, 10, color)

            // Indicate where the icon is located in the grid coordinates.
            icon:SetGridX(column)
            icon:SetGridY(row)

            Add(icon)

            // Adjust the intensity to make the next icon brighter than the last.
            intensity = intensity + 0.1
            column = column + 1
        end
        row = row + 1
    end
end
end

Inherits from: Libraries.Language.Object, Libraries.Interface.Layouts.Layout

Actions Documentation

Compare(Libraries.Language.Object object)

This action compares two object hash codes and returns an integer. The result is larger if this hash code is larger than the object passed as a parameter, smaller, or equal. In this case, -1 means smaller, 0 means equal, and 1 means larger. This action was changed in Quorum 7 to return an integer, instead of a CompareResult object, because the previous implementation was causing efficiency issues.

Parameters

Return

integer: The Compare result, Smaller, Equal, or Larger.

Example

Object o
Object t
integer result = o:Compare(t) //1 (larger), 0 (equal), or -1 (smaller)

Equals(Libraries.Language.Object object)

This action determines if two objects are equal based on their hash code values.

Parameters

Return

boolean: True if the hash codes are equal and false if they are not equal.

Example

use Libraries.Language.Object
use Libraries.Language.Types.Text
Object o
Text t
boolean result = o:Equals(t)

GetDefaultGridHeight()

Figure out how many columns this Cell is stretched across, and how wide that region is. This calculation isn't optimized for the current use case (i.e. that columns have consistent width), but will continue to work if columns are allowed non-consistent width in the future.

Return

integer:

GetDefaultGridWidth()

Finally, position the element within the grid.

Return

integer:

GetHashCode()

This action gets the hash code for an object.

Return

integer: The integer hash code of the object.

Example

Object o
integer hash = o:GetHashCode()

Layout(Libraries.Interface.Controls.Control container, Libraries.Containers.Array<Libraries.Interface.Item2D> items, number containerWidth, number containerHeight)

How many cells tall the grid should be, by default. This value is only used if the GridLayout isn't attached to a Control with a valid container grid height. If that value is available, it will be used instead.

Parameters

SetDefaultGridHeight(integer defaultGridHeight)

For now, assume standard layout for the container. More complicated cases are checked for above, and cases like FILL or MAINTAIN_ASPECT_RATIO are only used to size the container in ways that parent layouts will have to handle before this layout gets it.

Parameters

  • integer defaultGridHeight

SetDefaultGridWidth(integer defaultGridWidth)

Figure out how many columns this Cell is stretched across, and how wide that region is. This calculation isn't optimized for the current use case (i.e. that columns have consistent width), but will continue to work if columns are allowed non-consistent width in the future.

Parameters

  • integer defaultGridWidth