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

Developer

resources

Using tab widget

The tab widget renders each tab using a single wrapped widget that the tab widget creates and manages itself, internally.

By default, this rendering widget is an image static widget which provides the ability for an application to display a label and an optional icon on each tab. Displaying icons is useful when several tabs are present, or if the extent of the constraining container is such that the label text won't fit, but an image will suffice to communicate the tab's contents.

The data to be displayed on the label of each tab is, by default, stored in a vector model and it is up to the application using the tab widget to initialize the data in the model to contain the information to be displayed on each tab label.

Applications typically wrap the tab widget around a content widget that becomes the destination for the content specific to each tab. While the tab widget does not manage the content to be displayed within each tab, it is responsible for displaying the labels or icons on each tab.

To create a tab widget, an application would do the following:

  1. Create an instance of the decorator by calling ISHELL_CreateInstance() with a ClassID of the decorator, AEECLSID_CTabWidget, to retrieve a reference counted instance of the tab widget.
       ERR_TRY( ISHELL_CreateInstance(me->piShell, AEECLSID_CTabWidget,
                (void**)&me->piwTabWidget) );
    
       ERR_TRY( IWidget_SetBGColor(me->piwTabWidget, RGB_TABWIDGETBG) );
    
  2. Create the content widget that will be used to render the content of each tab.
       ERR_TRY( ISHELL_CreateInstance(me->piShell, AEECLSID_CCardContainer,
                (void**)&me->picCardContainer) );
       ERR_TRY( ICARDCONTAINER_QueryInterface(me->picCardContainer,
                AEEIID_Widget, (void**)&me->piwCardContainer) );
  3. To associate a child widget with the decorator, applications should call IDecorator_SetWidget(). This wraps the tab widget around the content widget. For example:
       IDecorator_SetWidget((IDecorator*)(void*)me->piwTabWidget,
             me->piwCardContainer);
  4. Set the extent for the tab widget:
       IWidget_GetExtent(me->piwTabWidget, &we);
       we.width = TABWIDGET_WIDTH;
       IWidget_SetExtent(me->piwTabWidget, &we);
  5. Create a vector model for the tab widget, set the model on the tab widget, and set the callback function for releasing memory for the model, as follows:
       ERR_TRY( ISHELL_CreateInstance(me->piShell, AEECLSID_CVectorModel,
                (void**)&pivm) );
       ERR_TRY( IWidget_SetModel(me->piwTabWidget,
                IVectorModel_to_IModel(pivm)) );
       (void)IVectorModel_SetPfnFree(pivm, (PFNNOTIFY)ImageStaticInfo_Delete);
  6. Add images to the vector model, and set properties for the tab, as follows:
       //night tab
       pii = ISHELL_LoadImage(me->piShell, "./images/assets/house_thumb.png");
       if (pii == NULL) {
          nErr = EFAILED;
          ERR_THROW(EFAILED);
       }
       ERR_TRY( ImageStaticInfo_New(&pisi, pii, L"Things") );
       ERR_TRY( IVectorModel_Add(pivm, pisi) );
       ERR_TRY( SceneApp_CreateObjectListWidget(me,
                me->picCardContainer) );
       RELEASEIF(pii);
    
       //day tab
       pii = ISHELL_LoadImage(me->piShell,
             "./images/assets/characters/surfer_thumb.png");
       if (pii == NULL) {
          nErr = EFAILED;
          ERR_THROW(EFAILED);
       }
       ERR_TRY( ImageStaticInfo_New(&pisi, pii, L"People & Animals") );
       ERR_TRY( IVectorModel_Add(pivm, pisi) );
       ERR_TRY( SceneApp_CreatePeopleAnimalListWidget(me,
                me->picCardContainer) );
    
       ERR_TRY( IWidget_SetFlags(me->piwTabWidget,
                TABWF_WRAP | TABWF_SHOWBORDER) );
    
       ERR_TRY( IWidget_SetPadding(me->piwTabWidget, 0) );
       ERR_TRY( IWidget_SetActiveBorderWidth(me->piwTabWidget, 2) );
       ERR_TRY( IWidget_SetInactiveBorderWidth(me->piwTabWidget, 1) );
       ERR_TRY( IWidget_SetBorderWidth(me->piwCardContainer, 0) );
    
       ERR_TRY( IWidget_SetProperty(me->piwTabWidget, PROP_TABHEIGHT,
                TABWIDGET_TABHEIGHT) );
    
  7. Insert the decorator in a container that up the hierarchy leads to the root container, to make sure that the container is displayed on the screen.
       WidgetProp wp;
       wp.prop     = nProp;
       wp.bVisible = bVisible;
    
       ERR_TRY(IPropContainer_Insert(me, piwTabWidget, WIDGET_ZNORMAL, &wp));