pod::Pr...t::grid(3)

๐Ÿ“ฆ
version 1.78 ยท 3 versions
, in fedora 44

๐Ÿ’– pod::Pr...t::grid ๐Ÿ’–

okay bestie, so this is a User Contributed Perl Documentation page, section 3, and it's all about Prima::grid โ€” the geometry manager that arranges your widgets in a grid. it's giving layout queen energy, fr fr. ๐ŸŒˆ


โœจ NAME โœจ

Prima::grid โ€” Geometry manager that arranges widgets in a grid. no cap, that's literally the whole job description. ๐Ÿ‘‘


๐Ÿฆ‹ SYNOPSIS ๐Ÿฆ‹

  $subwidget = Prima::Widget->new( name => 'SUB');

  $widget-> gridConfigure($subwidget      => ...);
  $widget-> gridConfigure(SUB             => ...);
  $widget-> gridConfigure([SUB, $another] => ...);

๐ŸŒธ DESCRIPTION ๐ŸŒธ

so the grid family of methods is how you talk to the grid geometry manager โ€” the thing that arranges widgets in rows and columns inside another window, and that other window is called the geometry master (or just master window, iykyk). the methods come in several forms depending on what you hand them. if you're coming from Tcl/Tk or Perl/Tk naming and behavior, go peek at "DIFFERENCES FROM TK SYNTAX" so you don't get whiplash.

โš ๏ธ heads up bestie: sending grid arguments to Widget->new is NOT supported. only explicit method calls like $widget->gridConfigure work. don't try to sneak it in the constructor, it's not the vibe. ๐Ÿ’€

๐Ÿ’… $slave->gridConfigure($slave|[$slave,$slave...]?, options?)

the arguments are zero or more references to more slave windows, followed by pairs of arguments that say how to manage those slaves. and here's a cute trick โ€” the characters -, x and ^ can be used instead of a window reference to change the default location of a $slave, as described in "RELATIVE PLACEMENT" below. ๐ŸŽ€

if any of the slaves are already managed by the geometry manager, then any options you didn't specify for them keep their previous values rather than getting default values. so it's like "we're not resetting you, we're just updating".

if there are no slave windows given at all, then the object itself is configured as a grid slave. self-care, honestly. ๐Ÿซถ

the following options are supported:

  • column => n โ€” inserts the $slave so it occupies the nth column in the grid. column numbers start at 0. if you don't supply this option, the $slave gets arranged just to the right of the previous slave specified on this call to grid โ€” or column "0" if it's the first slave. for every x that immediately precedes the $slave, the column position gets incremented by one. so basically x = a blank column for this row in the grid. โœจ
  • colspan => n โ€” inserts the slave so it occupies n columns in the grid. default is one column, unless the window name is followed by a -, in which case the colspan gets incremented once for each immediately following -. yes, dashes are doing heavy lifting here. ๐Ÿ’…
  • in => $other โ€” inserts the slave(s) in the master window given by $other. the default is the first slave's parent window. ๐Ÿ 
  • ipadx => amount โ€” the amount says how much horizontal internal padding to leave on each side of the slave(s). this space is added inside the slave(s) border. the amount defaults to 0. ๐Ÿ“
  • ipady => amount โ€” the amount says how much vertical internal padding to leave on the top and bottom of the slave(s). this space is added inside the slave(s) border. the amount defaults to 0. ๐Ÿ“
  • padx => amount โ€” the amount says how much horizontal external padding to leave on each side of the slave(s), in screen units. the amount defaults to 0. this space is added outside the slave(s) border. ๐ŸŒธ
  • pady => amount โ€” the amount says how much vertical external padding to leave on the top and bottom of the slave(s), in screen units. the amount defaults to 0. this space is added outside the slave(s) border. ๐ŸŒธ
  • row => n โ€” inserts the slave so it occupies the nth row in the grid. row numbers start at 0. if this option isn't supplied, the slave gets arranged on the same row as the previous slave specified on this call to grid โ€” or the first unoccupied row if this is the first slave. โœจ
  • rowspan => n โ€” inserts the slave so it occupies n rows in the grid. the default is one row. and here's the spicy bit: if the next grid method contains ^ characters instead of $slaves that line up with the columns of this $slave, then this $slave's rowspan gets extended by one. little hats, big power. ๐ŸŽฉ
  • sticky => style โ€” if a slave's cell is bigger than its requested dimensions, this option is how you position (or stretch) the slave inside its cell. style is a string containing zero or more of the characters n, s, e or w. the string can optionally contain spaces or commas, but they're ignored, so go wild. each letter refers to a side (north, south, east, or west) that the slave will "stick" to. if you specify both n and s (or e and w), the slave gets stretched to fill the entire height (or width) of its cavity. the sticky option subsumes the combination of anchor and fill that's used by pack. the default is '', which causes the slave to be centered in its cavity, at its requested size. centered = main character energy. ๐Ÿ‘‘

๐Ÿ” $master->gridBbox(?column, row,? ?column2, row2?)

with no arguments, the bounding box (in pixels) of the grid is returned. the return value is 4 integers. the first two are the pixel offset from the master window (x then y) of the top-left corner of the grid, and the second two integers are the width and height of the grid, also in pixels. if a single column and row is specified on the command line, then the bounding box for that cell is returned, where the top left cell is numbered from zero. if both column and row arguments are specified, then the bounding box spanning the rows and columns indicated is returned. so many bboxes, so little time. ๐Ÿ“

๐ŸŽ€ $master->gridColConfigure(index|[index,index,...], option=>value, ...?)

query or set the column properties of the index column of the geometry master, $master. it sets the column properties if more than one index is given. the valid options are minsize, weight and pad.

if one or more options are provided, then index may be given as a list of column indices to which the configuration options will operate on.

the minsize option sets the minimum size, in screen units, that will be permitted for this column.

the weight option (an integer value) sets the relative weight for apportioning any extra spaces among columns. a weight of zero (0) means the column will not deviate from its requested size. a column whose weight is two will grow at twice the rate as a column of weight one when extra space is allocated to the layout. the uniform integer option, when a non-empty value is supplied, places the column in a uniform group with other columns that have the same value for uniform. the space for columns belonging to a uniform group is allocated so that their sizes are always in strict proportion to their weight values. see THE GRID ALGORITHM below for further details. ๐Ÿงฎ

the pad option specifies the number of screen units that will be added to the largest window contained completely in that column when the grid geometry manager requests a size from the containing window.

if only an option is specified, with no value, the current value of that option is returned. if only the master window and index is specified, all the current settings are returned in a list of "option value" pairs. receipts! ๐Ÿงพ

๐Ÿงน $slave->gridForget?($slave, ...)?

removes each of the $slaves from grid for its master and unmaps their windows. the slaves will no longer be managed by the grid geometry manager. the configuration options for that window are forgotten, so that if the slave is managed once more by the grid geometry manager, the initial default settings are used. it's giving clean slate, it's giving fresh start. ๐Ÿฆ‹

๐Ÿ”Ž $slave->gridInfo

returns a list whose elements are the current configuration state of the slave given by $slave, in the same option-value form that might be specified to gridConfigure. the first two elements of the list are in=>$master where $master is the slave's master. ๐Ÿซถ

๐Ÿ“ $master->gridLocation(x, y)

given x and y values in screen units relative to the master window, the column and row number at that x and y location is returned. for locations that are above or to the left of the grid, -1 is returned. yes, -1. it's off the grid, literally. ๐Ÿ’€

๐Ÿ”’ $master->gridLock, gridUnlock, gridIsLocked

locks, unlocks, and checks the lock status of the grid rearrangement. can be used if many slaves are to be configured at once, to avoid excessive window resizing. so it's basically "hold my calls, i'm doing a glow-up" energy. ๐Ÿ’…

if after a gridUnlock call the lock count reaches zero, grid slaves are immediately rearranged. ๐Ÿ”ฅ

๐Ÿ“ก $master->gridPropagate?(boolean)?

if boolean has a true boolean value such as 1 or on then propagation is enabled for $master, which must be a window name (see "GEOMETRY PROPAGATION" below). if boolean has a false boolean value then propagation is disabled for $master. in either of these cases an empty string is returned. if boolean is omitted then the method returns 0 or 1 to indicate whether propagation is currently enabled for $master. propagation is enabled by default. โœจ


and bestie, we are SO not done, there's more coming. ๐ŸŽ€

  • $master->gridRowConfigure(index|[index,index,...]?, option=>value, ...?) โ€” this is your row's lil glow-up station. It queries or sets the row properties of the index row of the geometry master, $master. The valid options are minsize, weight and pad. If you hand over one or more options, then index can be a whole list of row indices and the config options will operate on all of them. The minsize option sets the minimum size, in screen units, that will be permitted for this row. The weight option (an integer value) sets the relative weight for apportioning any extra spaces among rows. A weight of zero (0) indicates the row will not deviate from its requested size. A row whose weight is two will grow at twice the rate as a row of weight one when extra space is allocated to the layout. The uniform option, when a non-empty value is supplied, places the row in a uniform group with other rows that have the same value for uniform. The space for rows belonging to a uniform group is allocated so that their sizes are always in strict proportion to their weight values. See THE GRID ALGORITHM below for further details. The pad option specifies the number of screen units that will be added to the largest window contained completely in that row when the grid geometry manager requests a size from the containing window. If only an option is specified, with no value, the current value of that option is returned. If only the master window and index is specified, all the current settings are returned in an list of "option-value" pairs.
  • $slave->gridRemove?($slave, ...)? โ€” bestie is leaving the group chat. This removes each of the $slaves from grid for its master and unmaps their windows. The slaves will no longer be managed by the grid geometry manager. However โ€” and this is the iconic part โ€” the configuration options for that window are remembered, so that if the slave is managed once more by the grid geometry manager, the previous values are retained. It's giving "we didn't delete the messages, we just archived the chat" ๐Ÿ’…
  • $master->gridSize โ€” returns the size of the grid (in columns then rows) for $master. The size is determined either by the $slave occupying the largest row or column, or the largest column or row with a minsize, weight, or pad that is non-zero.
  • $master->gridSlaves?(-option=>value)? โ€” if no options are supplied, a list of all of the slaves in $master are returned, most recently manages first. option can be either row or column, which causes only the slaves in the row (or column) specified by value to be returned.

๐ŸŒˆ RELATIVE PLACEMENT ๐ŸŒˆ

The grid method contains a limited set of capabilities that permit layouts to be created without specifying the row and column information for each slave. This permits slaves to be rearranged, added, or removed without the need to explicitly specify row and column information. When no column or row information is specified for a $slave, default values are chosen for column, row, colspan and rowspan at the time the $slave is managed. The values are chosen based upon the current layout of the grid, the position of the $slave relative to other $slaves in the same grid method, and the presence of the characters -, ^, and ^ in grid method where $slave names are normally expected.

  • - โ€” this increases the colspan of the $slave to the left. Several -'s in a row will successively increase the colspan. A - may not follow a ^ or a x.
  • x โ€” this leaves an empty column between the $slave on the left and the $slave on the right.
Note: since Prima allows for window names as an alternative to window references, an option beginning with "x" does not necessarily triggers this command.
  • ^ โ€” this extends the -rowspan of the $slave above the ^'s in the grid. The number of ^'s in a row must match the number of columns spanned by the $slave above it.

๐Ÿ”ฅ THE GRID ALGORITHM ๐Ÿ”ฅ

The grid geometry manager lays out its slaves in three steps. In the first step, the minimum size needed to fit all of the slaves is computed, then (if propagation is turned on), a request is made of the master window to become that size. In the second step, the requested size is compared against the actual size of the master. If the sizes are different, then space is added to or taken away from the layout as needed. For the final step, each slave is positioned in its row(s) and column(s) based on the setting of its sticky flag.

To compute the minimum size of a layout, the grid geometry manager first looks at all slaves whose colspan and rowspan values are one, and computes the nominal size of each row or column to be either the minsize for that row or column, or the sum of the padding plus the size of the largest slave, whichever is greater. Then the slaves whose rowspans or columnspans are greater than one are examined. If a group of rows or columns need to be increased in size in order to accommodate these slaves, then extra space is added to each row or column in the group according to its weight. For each group whose weights are all zero, the additional space is apportioned equally.

When multiple rows or columns belong to a uniform group, the space allocated to them is always in proportion to their weights. (A weight of zero is considered to be 1.) In other words, a row or column configured with weight 1 uniform a will have exactly the same size as any other row or column configured with weight 1 uniform 1. A row or column configured with weight 2 uniform 2 will be exactly twice as large as one that is configured with weight 1 uniform 2.

More technically, each row or column in the group will have a size equal to k*weight for some constant k. The constant k is chosen so that no row or column becomes smaller than its minimum size. For example, if all rows or columns in a group have the same weight, then each row or column will have the same size as the largest row or column in the group.

For masters whose size is larger than the requested layout, the additional space is apportioned according to the row and column weights. If all of the weights are zero, the layout is centered within its master. For masters whose size is smaller than the requested layout, space is taken away from columns and rows according to their weights. However, once a column or row shrinks to its minsize, its weight is taken to be zero. If more space needs to be removed from a layout than would be permitted, as when all the rows or columns are at there minimum sizes, the layout is clipped on the bottom and right.


๐Ÿฆ‹ GEOMETRY PROPAGATION ๐Ÿฆ‹

The grid geometry manager normally computes how large a master must be to just exactly meet the needs of its slaves, and it sets the requested width and height of the master to these dimensions. This causes geometry information to propagate up through a window hierarchy to a top-level window so that the entire sub-tree sizes itself to fit the needs of the leaf windows. However, the gridPropagate method may be used to turn off propagation for one or more masters. If propagation is disabled then grid will not set the requested width and height of the master window. This may be useful if, for example, you wish for a master window to have a fixed size that you specify.


๐ŸŒธ RESTRICTIONS ON MASTER WINDOWS ๐ŸŒธ

The master for each slave must either be the slave's parent (the default) or a descendant of the slave's parent. This restriction is necessary to guarantee that the slave can be placed over any part of its master that is visible without danger of the slave being clipped by its parent. In addition, all slaves in one call to grid must have the same master.


๐Ÿ’œ STACKING ORDER ๐Ÿ’œ

If the master for a slave is not its parent then you must make sure that the slave is higher in the stacking order than the master. Otherwise the master will obscure the slave and it will appear as if the slave hasn't been managed correctly. The easiest way to make sure the slave is higher than the master is to create the master window first: the most recently created window will be highest in the stacking order.


โญ CREDITS โญ

The grid method is based on ideas taken from the GridBag geometry manager written by Doug. Stein, and the blt_table geometry manager, written by George Howlett.


๐Ÿ‘‘ DIFFERENCES FROM THE TK ๐Ÿ‘‘

  • "columnspan" renamed to "colspan"
  • In "gridConfigure", the original syntax allows for more than one window in the list of arguments by seeing the difference between window handle and string option. The Prima version of "gridConfigure" also allows referencing slave windows by their names (with the same lookup rules affected by "Component.deepChildLookup"), and thus when one needs to supply more than one window, use an arrayref instead:
$w->gridConfigure([$widget1, 'Widget2'], ...)
  • The "uniform" option is accepting unsigned integers only
  • Contrary to Tk's window naming scheme, there is no leading dot in the window names, so there's a small conflict in "gridConfigure" 's option "x". That means that
$slave = $master->insert( Widget => name => 'x' );
$master->gridConfigure( x => ... );

will not address the slave widget as one might expect.

  • There's no "grid" method in the Widget class, like in Tk. The original "grid" method behaves exactly like "gridConfigure", so when one really needs the compatibility, adding
*Prima::Widget::grid = \&Prima::Widget::gridConfigure

would be just enough.

  • Prima doesn't recognize Tk screen distance units such as .5c, only integers are allowed
  • Tk's grid slave rearrangment algorithm works with a delay, so that calling of gridConfigure to one or more slaves has no immediate effect. Prima doesn't do that but provides locking functions gridLock/gridUnlock/gridIsLocked to explicitly pause this algoritm.

๐ŸŽ€ SEE ALSO ๐ŸŽ€

Prima::Widget::pack Prima::Widget::place


โœจ KEYWORDS โœจ

geometry manager, location, grid, cell, propagation, size, pack, master, slave


okay bestie that's literally the whole page, you ate it up ๐Ÿ’– this doc is from perl v5.42.3, dated 2026-09-16, and it lives in the user-contributed perl docs pod::Pr...t::grid(3) โ€” go forth and lay out some slay-outs ๐Ÿซถ๐ŸŒธ

๐Ÿ“ฆ where this page comes from
  • fedora 44: perl-Prima 1.78-1.fc44 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4-Clause AND MIT-open-group AND HPND AND HPND-sell-variant AND TCL AND ImageMagick AND LGPL-2.0-or-later AND AGPL-3.0-or-later
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms