Resources | developer.brewmp.com Resources | developer.brewmp.com

Developer

resources

Grid container

The grid container is used to arrange widgets in rows and columns. Each column and row has configurable properties that can be set to change the appearance of grid container. This is done by setting the values of the GridDescriptors.

Grid container functions

IGridContainer provides the IGridContainer_GetGridDescriptors() and IGridContainer_SetGridDescriptors() functions to get and set grid descriptors, and the IGridContainer_SetVisibility() and IGridContainer_GetVisibility() functions to set and get visibility of the container, respectively.

Using grid container

The iFlag field in a GridDescriptor specifies the cell type. The cell type determines the layout in either the x or y direction, depending on whether the GridDescriptor is for a row or a column. The possible cell types are:

  • CELL_FIXED: fixed height and width.
  • CELL_PROPORTIONAL - proportional height and width.
  • CELL_KEEP_EXTENT - row will use the largest widget's height and width.
  • CELL_SIZE_TO_FIT - widget's preferred extent.

The following shows an example of creating a grid container.

  1. Create an array of GridDescriptors that describe the properties of each row and column. Each GridDescriptor would be set to the following values:

    uint16 nRows = (uint16) ARRAYSIZE(aGridRows);
    uint16 nCols = (uint16) ARRAYSIZE(aGridCols);
    // Update grid size based on screen size
    int gridCellSize = MIN(58, MIN(me->rcClient.dx, me->rcClient.dy) / 3);
    aGridRows[0].iValue = aGridRows[1].iValue = aGridRows[2].iValue = 
                                                     (uint16)gridCellSize;
    aGridCols[0].iValue = aGridCols[1].iValue = aGridCols[2].iValue = 
                                                     (uint16)gridCellSize;
    
    

  2. Call ISHELL_CreateInstance with the ClassID AEECLSID_CGridContainer.
    ERR_TRY( ISHELL_CreateInstance(me->piShell, AEECLSID_CGridContainer,
                (void**) &picGrid) );
  3. Call IGridContainer_QueryInterface() to retrieve the IWidget pointer.
    ERR_TRY( IGridContainer_QueryInterface(picGrid, AEEIID_IWidget, (void**) 
                   &me->piwGridC) );
  4. Call IGridContainer_SetGridDescriptors(). The parameters aGridRows and aGridCols are arrays containing initialized GridDescriptors to describe each row and column.
    ERR_TRY( IGridContainer_SetGridDescriptors(picGrid,
                                       CAST(GridDescriptor*,aGridRows), &nRows,
                                       CAST(GridDescriptor*,aGridCols), &nCols) );
  5. Insert the grid container into the root container so it draws to the screen, using IRootContainer_Insert().
    ERR_TRY(IRootContainer_Insert(me->piwRoot, piwGrid, WIDGET_ZNORMAL, 
                                                                 &widPos) );				  
  6. Using the widget interface of the grid container, set the extent to the desired size you want the container to be.
    IWidget_SetExtentEx(me->piwGridC, me->rcClient.dx, me->rcClient.dy);
  7. Insert widgets.
    (void) IRootContainer_Insert(me->picRoot, me->piwGridC, WIDGET_ZNORMAL, &wpos);
    

The grid container keeps track of which widget inside the container has focus. By default the upper leftmost widget has focus. An application can set the focus to a different widget by calling IWidget_MoveFocus(). This example sets the focus to the last widget:

(void) IWidget_MoveFocus(me->piwRoot, me->piwGridC);