Shellminator V3.0.1
Simple Terminal
|
In the previous examples, we explored basic GUI elements. Now, let's take things a step further and see how we can display multiple GUI elements on a single screen.
Our approach is very similar to the layout systems used in Tkinter, Matlab, and Matplotlib. The idea is simple: we divide the screen into a grid with both horizontal and vertical sections. Then, we place elements into specific grid positions. Optionally, we can also define how many grid cells wide and tall each element should be.
Let’s start with a simple grid!
In this example, we'll create a grid with 3 rows and 3 columns:
Each grid follows a structured indexing system. To keep things familiar, we follow the same logic as many popular APIs:
Here’s an illustration to help visualize how grid indexing works:
Indexing starts from 0, meaning the first row is 0
, the second row is 1
, and so on. The same applies to columns. Since we’re working with a 3x3 grid, the highest index value for both rows and columns is 2 (because indexing starts from 0).
To add elements to the grid, we use the addWidget
method. Let’s see how it works:
By default, each element takes up one cell in width and height. But what if we want an element to span multiple cells?
To make an element wider or taller, we still use the addWidget
method, but we pass two additional parameters:
Finally, to start the GUI, we use the beginScreen
method as usual. But this time, we pass our grid as the screen object to be drawn: