Discussion of article "Using Layouts and Containers for GUI Controls: The CGrid Class"

 

New article Using Layouts and Containers for GUI Controls: The CGrid Class has been published:

This article presents an alternative method of GUI creation based on layouts and containers, using one layout manager — the CGrid class. The CGrid class is an auxiliary control that acts as a container for other containers and controls using a grid layout.

The CGrid class is a layout manager used in the design of GUI controls for dialog windows in MetaTrader. It is one of the custom container classes that can be used in GUI design without relying on absolute positioning.

It is highly recommended to read the article about the CBox class before proceeding to the concepts discussed in this article.


3. The CGrid Class

The CGrid class creates a container for one or more GUI controls and presents them in a grid arrangement. An example layout of an instance of the CGrid class is shown in the following illustration:

CGrid Layout

Figure 1. Grid Layout

Using this class can be convenient especially if the controls to be added to the grid have identical dimensions, such as a set of buttons or edit boxes within the client area.

The example above is a grid of 4x4 cells (4 columns and 4 rows). However, we aim to develop a class that would be able to accommodate any number of rows and columns in a grid.

Author: Enrico Lambino

 

Great work as usual, Enrico.

I tried but couldn't make it, to place two CEdit fields one just by anoter without any spacing (fixed positioning) - but it seems the class only auto positions by the layout style.

Can it be done? For instance, I want a field name and the value like this:

Total Orders: 3

using two CEdit's but placing them one by the other?

 

Thanks 

 
Amir Yacoby:

Great work as usual, Enrico.

I tried but couldn't make it, to place two CEdit fields one just by anoter without any spacing (fixed positioning) - but it seems the class only auto positions by the layout style.

Can it be done? For instance, I want a field name and the value like this:

Total Orders: 3

using two CEdit's but placing them one by the other?

 

Thanks 

You're welcome.

The grid only accepts a single component per cell. If you are to place more than one control on any given cell, you should nest them inside CBox or CGrid.

Another option would be to extend CGrid(tk) or CBox so that you can directly specify which controls should use fixed positioning, and which ones should follow layout styles.

 

When compiling the "Grid Sample.mq5" I get the error:

'm_client_area' - private member access error   GridSample.mqh  78      60
'm_client_area' - private member access error   GridSample.mqh  78      91

Errors

 
Karputov Vladimir:

When compiling the "Grid Sample.mq5" I get the error:

I guess the language was updated. Before it was possible to call the superclass that way. But now, I see, it is now possible to call the functions ClientAreaWidth and ClientAreaHeight for instances of CDialog and its heirs. The code:

m_main.Create(chart,name+"main",subwin,0,0,ClientAreaWidth(),ClientAreaHeight())

would be the equivalent statement.

Reason: