What's the usage of items when creating box, tab, or group

47 Views Asked by At

When I create the containers, such as tab, box or group, one of the argument is container_items. At first, I always created container_items. And I think I must use container_items.DLGAddElement() to add element. But I found I can achieve the same result by using container.DLGAddElement().

Also, for some widget, like radio button, it also has container_items argument.

Could anyone give me some information when will we use the contain_items?

DLGCreateTab( TagGroup &tab_items, string label )
DLGCreateBox( String title, TagGroup &items )
DLGCreateGroup( TagGroup &items )
DLGCreateRadioList( TagGroup &items )
1

There are 1 best solutions below

3
BmyGuest On BEST ANSWER

(Nearly) all DLG... commands are essentially utility methods that build a tagGroup, where the tagGroup describes what the dialog will be like. For debugging or learning purpose it is often helpful to show this tagGroup. If different commands yield the same tagGroup, they indeed are identical in function.

To display a TagGroup, you can use

TagGroupOpenBrowserWindow(tagGroup myTags, string Name, bool isFileBased)

with mytags being the TagGroup to be displayed (the one you create with DLGCreateDialog) and

with Name just being the title of the shown dialog and

with isFileBased indicating whether or not the tags (if changed) should be saved once the dialog is closed.


number addToContainer = 1

string infoStr = "Items added to " + (addToContainer?"Container":"ContainerItems")

taggroup dlg, dlgItems
dlg = DLGCreateDialog("Test",dlgItems)

taggroup box, boxItems
box = DLGCreateBox("Box 1",boxItems)

if ( addToContainer )
{
    box.DLGAddElement(DLGCreateLabel(infoStr))
    dlg.DLGAddElement(box)
}
else
{
    boxItems.DLGAddElement(DLGCreateLabel(infoStr))
    dlgItems.DLGAddElement(box)
}

dlg.TagGroupOpenBrowserWindow(infoStr,0)

Alloc(UIFrame).Init(dlg).Display(infoStr)

gives youResults:

As you can see, both methods give you the same dialog and (nearly) the same tag structure, but adding to the container instead of the container items tags adds an "invalid" flag. I would guess, adding to the items is the "correct" way, but when adding to the container itself, the underlying code 'fixes' it for your. Quite likely some convenience behavior added at later state.


Example regarding comment on tabs:

taggroup dlg,dlgitems
dlg=DLGCreateDialog("Dialog",dlgitems)

taggroup box,boxitems
box=DLGCreateBox("Box",boxitems)
box.DLGAddElement(DLGCreateLabel("Just some boxy stuff"))

dlgitems.DLGAddElement(box)

taggroup tablist1,tabitems1
tablist1=DLGCreateTabList(tabItems1)

taggroup tab1 = tabitems1.DLGAddTab("Tab1")
tab1.DLGAddElement(DLGCreateLabel("Page #1"))

taggroup tab2 = tabitems1.DLGAddTab("Tab2")
tab2.DLGAddElement(DLGCreateLabel("Page #2"))
dlgitems.DLGAddElement(tablist1)


taggroup tablist2,tabitems2
tablist2=DLGCreateTabList(tabItems2)

taggroup tab3 = tabitems2.DLGAddTab("Tab3")
tab3.DLGAddElement(DLGCreateLabel("Page #3"))

taggroup tab4 = tabitems2.DLGAddTab("Tab4")
tab4.DLGAddElement(DLGCreateLabel("Page #4"))
dlgitems.DLGAddElement(tablist2)


dlg.TagGroupOpenBrowserWindow("Tab",0)
Alloc(UIFrame).Init(dlg).pose()