Tickit...GridBox(3pm)
β¨ Tickit::Widget::GridBox β¨
okay bestie, welcome to the Tickit::Widget::GridBox page from the User Contributed Perl Documentation β the one and only grid-laying-out legend π
πΈ NAME πΈ
Tickit::Widget::GridBox β lay out a set of child widgets in a grid π¦
β¨ SYNOPSIS β¨
no cap, this is literally all it takes:
use Tickit;
use Tickit::Widget::GridBox;
use Tickit::Widget::Static;
my $gridbox = Tickit::Widget::GridBox->new(
style => {
col_spacing => 2,
row_spacing => 1,
}
)
->append_row(
[ Tickit::Widget::Static->new( text => "top left" ),
Tickit::Widget::Static->new( text => "top right" ) ],
)
->append_row(
[ Tickit::Widget::Static->new( text => "bottom left" ),
Tickit::Widget::Static->new( text => "bottom right" ) ],
);
Tickit->new( root => $gridbox )->run;
chaining rows like it's nothing?? we love to see it π
π DESCRIPTION π
So this container widget? It holds a whole set of child widgets, and it distributes them in a regular grid shape β rows and columns, nice and neat, like a little spreadsheet but make it β¨aestheticβ¨. That's the whole vibe.
π STYLE π
The default style pen is used as the widget pen. (iykyk π«Ά)
Here are the style keys it actually uses:
col_spacing => INTβ the number of columns of spacing between columns πΈrow_spacing => INTβ the number of rows of spacing between rows πΈ
π§ CONSTRUCTOR π§
new
$gridbox = Tickit::Widget::GridBox->new( %args );
Constructs a brand new Tickit::Widget::GridBox object. Fresh out the box, main character energy π
π METHODS π
rowcount, colcount
$count = $gridbox->rowcount;
$count = $gridbox->colcount;
Returns the number of rows, or the number of columns, in the grid. Simple as. π
add
$gridbox->add( $row, $col, $child, %opts );
Sets the child widget to display in the given grid cell. And here's the cute part β cells do not need to be explicitly constructed, because the grid will automatically expand to the size it needs. β¨ Growth mindset fr fr.
You can also use this method to replace an existing child at that cell location. And if you wanna remove a cell entirely? Use the remove method, bestie.
The following options are recognised:
col_expand => INTrow_expand => INT
Values for the expand setting for this column or row of the table. The largest expand setting for any cell in a given column or row sets the value used to distribute space to that column or row. Basically the loudest one in the room wins π
remove
$gridbox->remove( $row, $col );
Removes the child widget on display in the given cell. Heads up: this may shrink the grid if that was the last child widget in the given row or column. Cells be shrinking, it's giving β¨declutterβ¨
get
$child = $gridbox->get( $row, $col );
Returns the child widget at the given cell in the grid. But if the row or column index are beyond the bounds of the grid, or if there's no widget in that cell, you get undef back. π no widget, no problem.
get_row, get_col
@children = $gridbox->get_row( $row );
@children = $gridbox->get_col( $col );
A convenient shortcut to call get on an entire row or entire column of the grid. Obsessed with efficiency π«Ά
insert_row
$gridbox->insert_row( $before_row, [ @children ] );
Inserts a new row into the grid by moving all the existing rows after it lower down. Any child widgets in the referenced array will be set on the cells of the new row, at a column corresponding to its index in the array. A child of undef will be skipped over β not me ghosting that cell π
Each element of the list should either be a widget object reference directly, or an unblessed hash reference containing additional options. (See "split_widget_opts" in Tickit::Widget.)
insert_col
$gridbox->insert_col( $before_col, [ @children ] );
Inserts a new column into the grid by moving the existing columns after it to the right. Any child widgets in the referenced array will be set on the cells of the new column, at a row corresponding to its index in the array. A child of undef will be skipped over. Same ghosting rules, no drama π
Each child is specified as for insert_row.
append_row
$gridbox->append_row( [ @children ] );
Shortcut to inserting a new row after the end of the current grid. The "just tack it on the end" icon π
append_col
$gridbox->append_col( [ @children ] );
Shortcut to inserting a new column after the end of the current grid. Same energy, sideways β¨
These four methods return the container widget instance itself, making them suitable to use as a chaining mutator; e.g.
my $container = Tickit::Widget::GridBox->new( ... )
->append_row( [ Tickit::Widget::Static->new( ... ),
Tickit::Widget::Static->new( ... ) ] )
->append_row( ... );
the way that just keeps goingβ¦ slay π
delete_row
$gridbox->delete_row( $row );
Deletes a row of the grid by moving the existing rows after it higher up. Moving on up, periodt π
delete_col
$gridbox->delete_col( $col );
Deletes a column of the grid by moving the existing columns after it to the left. Scoot over bestie π¦
π TODO π
Things that are, like, not done yet but we're manifesting them:
- Add
move_{row,col}methods for re-ordering existing rows or columns - Make
{insert,append,delete,move}operations more efficient by deferring thechildren_changedcall until they are done.
lowkey excited for these ngl π₯
π AUTHOR π
Paul Evans <leonerd@leonerd.org.uk>
and that's the whole page, bestie!! π this was perl v5.40.0, dated 2024-09-16, and it's the Tickit...GridBox(3pm) page β mwah, go build a grid, you got this π«Άβ¨π
π¦ where this page comes from
- ubuntu resolute: libtickit-widgets-perl 0.42-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libtickit-widgets-perl 0.42-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms