Terrapin Resources

Grids

A Logo grid is a special control that lets you arrange widgets in a grid. This makes a grid a very powerful feature, because it is not necessary to re-align controls because of changes to the display size when you store them in a grid. Note that a grid cell can only take a single widget.

A grid is a GRID widget, which you create either be dragging the grid symbol from the Toolbox’ “Controls” panel to the Graphics panel, or with the help of the NEW or DECLARE commands. Once you have created a grid, you can access its individual cells with the commands described below. Initially, each grid cell contains a STATICTEXT widget whose text you can set via its TEXT property.

By default, a GRID widget has a size of 3×3 cells. You can change the number of rows by setting the grid’s ROWS property, and you can set the value of its COLUMNS property to set the number of columns. You can also use the SETGRIDDIMS command to change the dimensions of the grid. Changing the grid’s dimensions erases the contents of the grid, and destroys any widgets that have been stored into the grid. A grid adjusts itself to the largest items of a row or column. You can use the FILLGRID command to quickly fill a grid with text content.

A grid cell has “coordinates” that range from 0 to the number of rows or columns minus one. Thus, the top left cell has the coordinates 0, 0, the next cell to the right has 1, 0, and so on. This has been modeled after Logo arrays, who have a similar way to access array elements; see the page about arrays for a detailed description of array coordinates.

Initially, a grid has cell borders; you can change the color of the borders by setting the grid’s BORDER property to a different color, or you can make it invisible by using a color with an alpha value of 0, like, for example, [0 0 0 0].

You can change the properties of the entire grid, or a row or column with the GPPROP command, which makes it easy to apply styles to, for example, a header row. Also, you can define a runlist for each grid cell that Logo executes when the cell has been clicked by setting the cell widget’s RUN property.

For more information, see the Grids chapter of the Logo manual.

FILLGRID

Sets the text values of a grid.

Syntax

Description

FILLGRID initializes the grid named in its first input with the data in the list given as its second input. If the list is non-structured, the grid is filled sequentially regardless of its dimensions. If the list is structured, the grid is filled according to the structure of the list and its dimensions.

If the input is a word, FILLGRID initializes the grid with each character of the word.

Note that FILLGRID sets the TEXT property of each grid widget. See Control Properties for an explanation of how different controls handle their TEXT property.

Example

ERASE “G DECLARE “GRID “G FILLGRID “G COLORS

GGET

Outputs the name of a widget stored in a grid cell.

Syntax

Description

GGET outputs the name of a widget stored in a grid cell. The column and row numbers are between 0 and the number of grid columns and rows minus one, respectively.

Initially, each grid cell contains a STATICTEXT widget; Logo creates the names of these widgets using the grid’s name plus the column and row numbers, separated by dots. If you, for example, create a grid GRID, the grid’s top left text cell would have the name GRID.0.0.

GGET is often used together with the GPROP and PPROP commands to get or set a cell property. If you, for example, wish to change the top left cell’s font of your grid “MYGRID, you can use the command PPROP GGET “MYGRID 0 0 “FONT [HELVETICA 14 1].

Example

ERASE “G DECLARE “GRID “G GGET “G 1 1 Result: G.1.1

GGETTEXT

Outputs the text of a grid cell.

Syntax

Description

GGETTEXT outputs the text of a grid cell. The column and row numbers are between 0 and the number of grid columns and rows minus one, respectively. If the cell is empty, GGETTEXT outputs an empty word; otherwise, it outputs the value of the cell’s TEXT property.

GGETTEXT is a shortcut for GPROP GGET grid-name row column “TEXT.

Example

ERASE “G DECLARE “GRID “G GGETTEXT “G 1 1 Result: ||

GPPROP

Alters a property of a grid, a row, a column, or a cell.

Syntax

Description

GPPROP sets a property value at multiple table cells. If used without brackets, GPPROP alters the entire table.

The optional inputs for row and column designate the row and column to set. If the row is omitted, an entire column is altered. Also, if a column value is -1, the row is altered, and if a row value is -1, the column is altered. If both values are -1, the entire grid is altered.

Examples:

To set a larger header font for the first row: (GPPROP gridname "FONT [HELVETICA 14 0] -1 0)

To set a larger header font for thefirst column: (GPPROP gridname "FONT [HELVETICA 14 0] 0)

Example

ERASE “G DECLARE “GRID “G GPPROP “G “TEXT “HELLO (GPPROP “G “FONT [HELVETICA 14 1] 0 -1) (GPPROP “G “FONT [HELVETICA 14 1] -1 0) (GPPROP “G “COLOR “RED 0 -1) (GPPROP “G “COLOR “BLUE -1 0)

GRIDDIMS

Reports the size of a grid.

Syntax

Description

GRIDDIMS reports the size of a grid as a two-element list of the numbers of rows and columns. See also SETGRIDDIMS.

Example

ERASE “G DECLARE “GRID “G GRIDDIMS “G Result: [3 3]

GSET

Stores a widget into a grid cell.

Syntax

Description

GSET stores the widgets whose name is the GSET’s last input into a grid’s cell. The column and row numbers are between 0 and the number of grid columns and rows minus one, respectively. If the cell contains a widget, the widget is destroyed.

Once a widget has been stored into a grid cell, it cannot move anymore. Any attempts to move the widgets are ignored.

Example

ERASE “G DECLARE “GRID “G GSET “G 0 1 NEW “BUTTON GSET “G 1 1 0 GSET “G 2 1 NEW “BUTTON

GSETTEXT

Stores a text into a grid cell.

Syntax

Description

GSETTEXT stores its last input into a grid’s cell as text. The column and row numbers are between 0 and the number of grid columns and rows minus one, respectively. If the text contains a control, for example, the control’s text is altered.

Example

ERASE “G DECLARE “GRID “G GSET “G 0 1 NEW “BUTTON GSETTEXT “G 0 0 “ONE GSETTEXT “G 0 1 “TWO GSETTEXT “G 0 2 “THREE

LISTGRID

Reports the values of a grid as a list.

Syntax

Description

LISTGRID reports a list of row contents. Each sub-list contains the column values of a row. LISTGRID reads each cell’s TEXT property to collect its values.

The output of LISTGRID can be used as input to FILLARRAY to quickly transfer the contents of a grid to an array or another grid.

See also GGET.

Example

ERASE “G DECLARE “GRID “G GSETTEXT “G 0 1 25 GSETTEXT “G 1 1 50 LISTGRID “G Result: [[|| 25 ||] [|| 50 ||] [|| || ||]]

SETGRIDDIMS

Sets the size of a grid.

Syntax

Description

SETGRIDDIMS sets the size of a grid. Its inputs are the number of columns and rows, which may vary between 1 and 999. SETGRIDDIMS erases the contents of the grid, and erases any widgets that have been stored into the grid.

You can also set the grid’s dimensions by settings its COLUMNS and ROWS properties.

Example

ERASE “G DECLARE “GRID “G SETGRIDDIMS “G 3 5