Skip to content
coding.jackalope edited this page Apr 29, 2019 · 20 revisions
Table of Contents

Overview

Creating windows are required to render any controls. Below is an example of creating a simple window with a title bar.

Slab.BeginWindow('MyWindow', {Title = "My First Window"})
Slab.EndWindow()

Windows take in a unique Id to identify this window from other windows. Windows with a title bar are movable by default while windows without title bars are not.

Windows by default are set to automatically grow as controls are added to the window.

Slab.BeginWindow('MyWindow', {Title = "My First Window"})
Slab.Text("Hello World")
Slab.Text("Foo Bar")
Slab.Text("This is a very long string")
Slab.EndWindow()

If resizing the window is desired, then the flag 'AutoSizeWindow' must be set to false.

Slab.BeginWindow('MyWindow', {Title = "My First Window", AutoSizeWindow = false})
Slab.Text("Hello World")
Slab.Text("Foo Bar")
Slab.Text("This is a very long string")
Slab.EndWindow()

If the contents of a window cannot fit within the bounds of the window, then scroll bars will be rendered to allow the user to scroll within the window.

Windows, by default, will have sizers for all sides active. Through the SizerFilter option, only certain sides of a window can be resized.

Slab.BeginWindow('SizerExample', {Title = "SizerExample", AutoSizeWindow = false, SizerFilter = {'W', 'E'}})
Slab.EndWindow()

Columns

Windows support the ability to divide controls into columns. This is done by passing in the number of columns requested into BeginWindow and then wrap the controls in the BeginColumn/EndColumn API calls.

Slab.BeginWindow('Columns', {Title = "Columns", Columns = 2})

Slab.BeginColumn(1)
Slab.Text("Column 1", {CenterX = true})
Slab.Separator()
Slab.Text("Hello", {CenterX = true})
Slab.EndColumn()

Slab.BeginColumn(2)
Slab.Text("Column 2", {CenterX = true})
Slab.Separator()
Slab.Text("World", {CenterX = true})
Slab.EndColumn()

Slab.EndWindow()

Columns will also begin at the current cursor position. Controls can be added before the first BeginColumn call and can be added after the last EndColumn call.

Slab.BeginWindow('Columns', {Title = "Columns", Columns = 2})

Slab.Button("Top", {ExpandW = true})

Slab.BeginColumn(1)
Slab.Text("Column 1", {CenterX = true})
Slab.Separator()
Slab.Text("Hello", {CenterX = true})
Slab.EndColumn()

Slab.BeginColumn(2)
Slab.Text("Column 2", {CenterX = true})
Slab.Separator()
Slab.Text("World", {CenterX = true})
Slab.EndColumn()

Slab.Button("Bottom", {ExpandW = true})

Slab.EndWindow()

API

Below is a list of functions associated with the Window API.

BeginWindow

This function begins the process of drawing widgets to a window. This function must be followed up with an EndWindow call to ensure proper behavior of drawing windows.

Parameter Type Description
Id String A unique string identifying this window in the project.
Options Table List of options that control how this window will behave.
Option Type Description
X Number The X position to start rendering the window at.
Y Number The Y position to start rendering the window at.
W Number The starting width of the window.
H Number The starting height of the window.
ContentW Number The starting width of the content contained within this window.
ContentH Number The starting height of the content contained within this window.
BgColor Table The background color value for this window. Will use the default style WindowBackgroundColor if this is empty.
Title String The title to display for this window. If emtpy, no title bar will be rendered and the window will not be movable.
AllowMove Boolean Controls whether the window is movable within the title bar area. The default value is true.
AllowResize Boolean Controls whether the window is resizable. The default value is true. AutoSizeWindow must be false for this to work.
AllowFocus Boolean Controls whether the window can be focused. The default value is true.
Border Number The value which controls how much empty space should be left between all sides of the window from the content. The default value is 4.0
NoOutline Boolean Controls whether an outline should not be rendered. The default value is false.
IsMenuBar Boolean Controls whether if this window is a menu bar or not. This flag should be ignored and is used by the menu bar system. The default value is false.
AutoSizeWindow Boolean Automatically updates the window size to match the content size. The default value is true.
AutoSizeWindowW Boolean Automatically update the window width to match the content size. This value is taken from AutoSizeWindow by default.
AutoSizeWindowH Boolean Automatically update the window height to match the content size. This value is taken from AutoSizeWindow by default.
AutoSizeContent Boolean The content size of the window is automatically updated with each new widget. The default value is true.
Layer String The layer to which to draw this window. This is used internally and should be ignored by the user.
ResetPosition Boolean Determines if the window should reset any delta changes to its position.
ResetSize Boolean Determines if the window should reset any delta changes to its size.
ResetContent Boolean Determines if the window should reset any delta changes to its content size.
ResetLayout Boolean Will reset the position, size, and content. Short hand for the above 3 flags.
SizerFilter Table Specifies what sizers are enabled for the window. If nothing is specified, all sizers are available. The values can be: NW, NE, SW, SE, N, S, E, W
CanObstruct Boolean Sets whether this window is considered for obstruction of other windows and their controls. The default value is true.
Rounding Number Amount of rounding to apply to the corners of the window.
Columns Number The number of columns for this window. Must be larger than 1 for columns to work properly.

EndWindow

This function must be called after a BeginWindow and associated widget calls. If the user fails to call this, an assertion will be thrown to alert the user.

GetWindowPosition

Retrieves the active window's position.

Return Description
Number, Number The X and Y position of the active window.

GetWindowSize

Retrieves the active window's size.

Return Description
Number, Number The width and height of the active window.

GetWindowContentSize

Retrieves the active window's content size.

Return Description
Number, Number The width and height of the active window content.

GetWindowActiveSize

Retrieves the active window's active size minus the borders. This could be the size of the window or the size of the current column.

Return Description
Number, Number The width and height of the window's active bounds.

BeginColumn

The start of a column. EndColumn must be called after a call to BeginColumn and all controls have been rendered.

Parameter Type Description
Index Number The index to the column to add controls to. This must be a valid column between 1 and the max column index defined by the Columns option in BeginWindow.

EndColumn

The end of a column. Must be called after a BeginColumn call.

Clone this wiki locally