Dialog Resource Example

The following example from the "View Groups" application makes use of three layout types: VStackLayout, FlowLayout and HStackLayout. The vertical StackLayout is the outermost layout. The first nested layout is a FlowLayout for the dialog's IconCmd buttons. The FLOWLAYOUTID_IconButtons FlowLayout definition is in ustation.rsc . A ListBox is next in the vertical stack and has a stretch factor of 1 so it gets more space vertically as the dialog is resized larger. The next nested layout is a horizontal StackLayout that contains a Stretch item and two PushButtons. The Stretch item is given a stretch factor of 1 so it gets more space horizontally as the dialog is resized larger. The HSTACKLAYOUTID_DialogButtons HStackLayout definition is also in ustation.rsc . For standardization of margins and spacing, layouts defined in MicroStation should be used when possible.

DialogBoxRsc DIALOGID_VIEWGROUP_ViewGroups =
{
DIALOG_LIST_W, DIALOG_H,
HOOKDIALOGID_VIEWGROUP_ViewGroups, NOPARENTID,
TXT_ViewGroupDialogTitle,
{
BEGIN_FLOW_LAYOUT (FLOWLAYOUTID_IconButtons, "")
{AUTO_XYWH, IconCmd, ICONCMDID_VIEWGROUP_Create, NO_ITEMARGS},
{AUTO_XYWH, IconCmd, ICONCMDID_VIEWGROUP_Properties, NO_ITEMARGS},
{AUTO_XYWH, IconCmd, ICONCMDID_VIEWGROUP_Delete, NO_ITEMARGS},
{{ AUTO_XY, VIEWGROUP_LIST_WIDTH, 0}, ListBox, LISTID_VIEWGROUP_ViewGroups, NO_ITEMARGS},
BEGIN_HSTACK_LAYOUT(HSTACKLAYOUTID_DialogButtons, "")
{{ AUTO_XY, BUTTON_LARGEWIDTH, 0}, PushButton, PUSHBUTTONID_VIEWGROUP_Apply, NO_ITEMARGS},
{{ AUTO_XY, BUTTON_LARGEWIDTH, 0}, PushButton, PUSHBUTTONID_VIEWGROUP_Close, NO_ITEMARGS},
}
};

Tool Settings Example

The following example from the "Place Line" command is placing two rows in a GridLayout. The items on the row are surrounded by the GridRow and EndRow items. Each item is automatically assigned a sequential column number. Each row contains a ToggleButton, Label and Text field. The ToggleButton actually contains the label string. But for layout purposes, a Label item is added and specifies the "LABEL_LINKPREV" itemArg value in order to link to the previous item (the ToggleButton). Using this technique, the label string is pulled over to the Label item and the two items are "linked" for the focus model. This allows the ToggleButton to keep the label in its resource definition in case it is used outside a layout, and also allows the Label item to "link" to it and specify an independent column and size policy for layout purposes. In this case, the default "left alignment" is applied to the Label item. The "LABEL_LINKNEXT" itemArg value would pull the label string from the following item.

#define W10 10*XC
CmdItemListRsc CMD_PLACE_LINE_CONSTRAINED =
{{
BEGIN_GRID_LAYOUT(GRIDLAYOUTID_3ColsToggleLabelSetting, "")
GRID_ROW(0, "") // row 0
{{0, 0, 0, 0}, ToggleButton, TOGGLEID_Length, ON, 0, "", ""}, // column 0
{{0, 0, W10, 0}, Label, 0, ON, LABEL_LINKPREV, "", ""}, // column 1
{{0, 0, W10, 0}, Text, TEXTID_Length, ON, 0, "", ""}, // column 2
GRID_ROW(0, "") // row 1
{{0, 0, 0, 0}, ToggleButton, TOGGLEID_Angle, ON, 0, "", ""},
{{0, 0, W10, 0}, Label, 0, ON, LABEL_LINKPREV, "", ""},
{{0, 0, W10, 0}, Text, TEXTID_Angle, ON, 0, "", ""},
}};

C++ Layout Manager Example

The following example is an excerpt from the Configuration Variables dialog application. The CfgVars dialog was a fixed size in V8i. By creating and setting up the GuiLayoutHelper and adding all the dialog items to various nested layouts, we were quickly and easily able to improve the layout of the dialog and make it resizable.

virtual bool OnInit (DialogInitArgsR init) override
{
// Create the GuiLayoutHelper that will hold the top-level layout
GuiLayoutHelper *layoutHelper = GuiLayoutHelper::Create (GetDbP());
// Create a vertical Stack layout, which is the top-level layout
vStackLayout->SetContentsMargins (0);
// Get the MenuBar on the dialog and add it to the vertical Stack layout
DialogItem *diP = GetDbP()->GetItemByTypeAndId (RTYPE_MenuBar, MENUBARID_CfgVars);
if (NULL != diP)
vStackLayout->AddControl (GuiLayoutControl::Create(layoutHelper, diP,
SizePolicy(ST_Preferred, ST_Fixed)));
// Create a horizontal stack layout, which will hold a ListBox on the left
// and a ContainerPanel to the right of it.
HStackLayout *hStackLayout1 = HStackLayout::Create ();
hStackLayout1->AddSpacing (XC);
diP = GetDbP()->GetItemByTypeAndId (RTYPE_ListBox, LISTBOXID_ConfigurationTopicList);
if (NULL != diP)
hStackLayout1->AddControl (GuiLayoutControl::Create(layoutHelper, diP,
SizePolicy(ST_Fixed, ST_Preferred)));
. . .
// Add the horizontal stack layout to the top-level vertical stack layout
vStackLayout->AddLayout (hStackLayout1);
. . .
// Set the vertical stack layout as the top-level layout
layoutHelper->SetLayout (vStackLayout);
// Set the GuiLayoutHelper as the layout helper for the dialog.
// When the dialog size changes or control sizes/properties change,
// the layout manager will automatically be invoked.
GetDbP()->SetLayoutHelper (layoutHelper);
return true;
}

Copyright © 2017 Bentley Systems, Incorporated. All rights reserved.