SDK:Layout Manager Control Positioning
Jump to navigation
Jump to search
.SDK|SDK ..SDK:Types|SDK Types ..SDK:Using the SDK|Using the SDK ..VCOM:VCOM (Vectorworks Component Object Model)|VCOM Basics ..VCOM:Class Reference|VCOM Class Reference
Introduction
Generally, the Layout Manager handles the positioning of controls in the desired manner. In cases where the desired behavior is not achieved, developers can use three pixel-based adjustment functions available in both SDK and VS:
SetComponentSize<br\> GetComponentRect<br\> AdjustComponentPixelPos<br\>
Currently these functions can only be used in the event handler. Generally they are placed in the kSetupMessage event.
SetComponentSize
//------------------------------------------------------------------------------------ Boolean GS_SetComponentSize(CALLBACKPTR, long dialogID, long componentID, int nWidth, int nHeight) // // Description: // Sets the size of a Layout Manager component. // // Parameters: // dialogID - input - id of the dialog that contains the control. // componentID - input - id of the control. // nWidth - input - the item's new width in pixels. // nHeight - input - the item's new height in pixels. // // Returns: // CBBoolean - 'TRUE' if the operation was successful. // - 'FALSE' otherwise. //------------------------------------------------------------------------------------ CB_SetComponentSize(dialogID:LONGINT, componentID:LONGINT, nWidth, nHeight:INTEGER) // // Description: // Sets the size of a Layout Manager component. // // Parameters: // dialogID - input - id of the dialog that contains the control. // componentID - input - id of the control. // nWidth - input - the item's new width in pixels. // nHeight - input - the item's new height in pixels. // // Returns: // void
GetComponentRect
//------------------------------------------------------------------------------------ Boolean GS_GetComponentRect(CALLBACKPTR, long dialogID, long componentID, int& nLeft, int& nTop, int& nRight, int& nBottom) // // Description: // Retrieves the bounding rectangle of the specified Layout Manager control. // The coordinates are relative to the top-left corner of the dialog, which is at (0,0). // // Parameters: // dialogID - input - id of the dialog that contains the control. // componentID - input - id of the control. // nLeft - output- the item's left coordinate. // nTop - output- the item's top coordinate. // nRight - output- the item's right coordinate. // nBottom - output- the item's bottom coordinate. // // Returns: // CBBoolean - 'TRUE' if the operation was successful. // - 'FALSE' otherwise. //------------------------------------------------------------------------------------ CB_GetComponentRect(dialogID:LONGINT, componentID:LONGINT, VAR nLeft, VAR nTop, VAR nRight, VAR nBottom:INTEGER) // // Description: // Retrieves the bounding rectangle of the specified Layout Manager control. // The coordinates are relative to the top-left corner of the dialog, which is at (0,0). // // Parameters: // dialogID - input - id of the dialog that contains the control. // componentID - input - id of the control. // nLeft - output- the item's left coordinate. // nTop - output- the item's top coordinate. // nRight - output- the item's right coordinate. // nBottom - output- the item's bottom coordinate. // // Returns: // void
AdjustComponentPixelPos
//------------------------------------------------------------------------------------ Boolean GS_AdjustComponentPixelPos(CALLBACKPTR, long dialogID, long componentID, int nHorizontal, int nVertical) // // Description: // Adjusts the pixel position of the specified Layout Manager control. // // Parameters: // dialogID - input - id of the dialog that contains the control. // componentID - input - id of the control. // nHorizontal - input - horizontal amount to shift the control in pixels. // nVertical - input - vertical amount to shift the control in pixels. // // Returns: // CBBoolean - 'TRUE' if the operation was successful. // - 'FALSE' otherwise. //------------------------------------------------------------------------------------ CB_AdjustComponentPixelPos(dialogID:LONGINT, componentID:LONGINT, nHorizontal, nVertical:INTEGER) // // Description: // Adjusts the pixel position of the specified Layout Manager control. // // Parameters: // dialogID - input - id of the dialog that contains the control. // componentID - input - id of the control. // nHorizontal - input - horizontal amount to shift the control in pixels. // nVertical - input - vertical amount to shift the control in pixels. // // Returns: // void
Sample Code
Below is sample VS code demonstrating how GetComponentRect and AdjustComponentPixelPos can be used to position icon radio buttons.
{---------------------------------------------------------------------------------------} PROCEDURE dialog1_Main; {---------------------------------------------------------------------------------------} CONST kImageControl = 3; kIconButton1 = 5; kIconButton2 = 6; kIconButton3 = 7; kIconButton4 = 8; kIconButton5 = 20; kIconButton6 = 21; kSetComponentSizeText = 9; kGetComponentRectText = 10; kAdjustPixelPosText = 11; {kGetComponentTextWidth = 12;} kTree = 13; kClassPullDown = 14; kDesignLayerPullDown = 15; kSheetLayerPullDown = 16; kEditBox = 17; kStaticTextGroup = 18; kIconButtonWidth = 4; kPullDownWidth = 27; {---------------------------------------------------------------------------------------} VAR strPullDownIndex :STRING; strPath :STRING; nDialogID :INTEGER; bResult :BOOLEAN; nParent :INTEGER; nChild1 :INTEGER; nChild2 :INTEGER; nParent2 :INTEGER; nChild3 :INTEGER; nChild4 :INTEGER; nButtonLeft :INTEGER; nButtonTop :INTEGER; nButtonRight :INTEGER; nButtonBottom :INTEGER; nButtonStartXCoord :INTEGER; nButtonWidth :INTEGER; {---------------------------------------------------------------------------------------} PROCEDURE dialog1_Setup; BEGIN nDialogID := CreateLayout('LM Improvements', true, 'OK', 'Cancel'); CreateImageControl (nDialogID, kImageControl, 110, 72, nil); CreateIconPushButton (nDialogID, kIconButton5, 1570, kIconButtonWidth); CreateIconPushButton (nDialogID, kIconButton6, 1486, kIconButtonWidth); CreateIconPushButton (nDialogID, kIconButton1, 1485, kIconButtonWidth); CreateIconPushButton (nDialogID, kIconButton2, 1486, kIconButtonWidth); CreateIconPushButton (nDialogID, kIconButton3, 1487, kIconButtonWidth); CreateIconPushButton (nDialogID, kIconButton4, 1488, kIconButtonWidth); CreateGroupBox (nDialogID, kStaticTextGroup, 'New Pixel-Based Functions', true); CreateStaticText (nDialogID, kSetComponentSizeText, 'SetComponentSize', -1); CreateStaticText (nDialogID, kGetComponentRectText, 'GetComponentRect', -1); CreateStaticText (nDialogID, kAdjustPixelPosText, 'AdjustComponentPixelPos ', -1); CreateTreeControl (nDialogID, kTree, 27, 8); CreateClassPullDownMenu (nDialogID, kClassPullDown, kPullDownWidth); CreateDesignLayerPullDownMenu (nDialogID, kDesignLayerPullDown, kPullDownWidth); CreateSheetLayerPullDownMenu (nDialogID, kSheetLayerPullDown, kPullDownWidth); CreateEditText (nDialogID, kEditBox, 'Casework-LowerKitchenCounterTop-Marble-1', kPullDownWidth); SetFirstLayoutItem (nDialogID, kImageControl); SetBelowItem (nDialogID, kImageControl, kIconButton5, 0, 0); {SetRightItem (nDialogID, kIconButton5, kIconButton6, 0, 0);} SetBelowItem (nDialogID, kIconButton5, kIconButton1, 0, 0); SetRightItem (nDialogID, kIconButton1, kIconButton2, 0, 0); SetRightItem (nDialogID, kIconButton2, kIconButton3, 0, 0); SetRightItem (nDialogID, kIconButton3, kIconButton4, 0, 0); SetBelowItem (nDialogID, kIconButton1, kStaticTextGroup, 0, 0); SetFirstGroupItem (nDialogID, kStaticTextGroup, kSetComponentSizeText); SetBelowItem (nDialogID, kSetComponentSizeText, kGetComponentRectText, 0, 0); SetBelowItem (nDialogID, kGetComponentRectText, kAdjustPixelPosText, 0, 0); {SetBelowItem (nDialogID, kAdjustPixelPosText, kGetComponentTextWidth, 0, 4);} SetBelowItem (nDialogID, kStaticTextGroup, kTree, 0, 2); SetBelowItem (nDialogID, kTree, kClassPullDown, 0, 1); SetBelowItem (nDialogID, kClassPullDown, kDesignLayerPullDown, 0, 0); SetBelowItem (nDialogID, kDesignLayerPullDown, kSheetLayerPullDown, 0, 0); SetBelowItem (nDialogID, kSheetLayerPullDown, kEditBox, 0, 0); END; {---------------------------------------------------------------------------------------} PROCEDURE dialog1_Handler(VAR item :LONGINT; data :LONGINT); BEGIN CASE item OF SetupDialogC: BEGIN strPath := 'C:\splash.jpg'; bResult := SetImageControlPath(nDialogID, kImageControl, strPath); bResult := GetComponentRect(nDialogID, kIconButton1, nButtonLeft, nButtonTop, nButtonRight, nButtonBottom); nButtonStartXCoord := nButtonLeft; nButtonWidth := nButtonRight - nButtonLeft; bResult := GetComponentRect(nDialogID, kIconButton2, nButtonLeft, nButtonTop, nButtonRight, nButtonBottom); bResult := AdjustComponentPixelPos(nDialogID, kIconButton2, -nButtonLeft, 0); bResult := AdjustComponentPixelPos(nDialogID, kIconButton2, nButtonStartXCoord + nButtonWidth, 0); bResult := GetComponentRect(nDialogID, kIconButton3, nButtonLeft, nButtonTop, nButtonRight, nButtonBottom); bResult := AdjustComponentPixelPos(nDialogID, kIconButton3, -nButtonLeft, 0); bResult := AdjustComponentPixelPos(nDialogID, kIconButton3, nButtonStartXCoord + nButtonWidth * 2, 0); bResult := GetComponentRect(nDialogID, kIconButton4, nButtonLeft, nButtonTop, nButtonRight, nButtonBottom); bResult := AdjustComponentPixelPos(nDialogID, kIconButton4, -nButtonLeft, 0); bResult := AdjustComponentPixelPos(nDialogID, kIconButton4, nButtonStartXCoord + nButtonWidth * 3, 0); nParent := InsertTreeControlItem(nDialogID, kTree, 'D:\', -1, -1); nChild1 := InsertTreeControlItem(nDialogID, kTree, 'Building.mcd', nParent, -1); nChild2 := InsertTreeControlItem(nDialogID, kTree, 'Park.mcd', nParent, -1); nParent2 := InsertTreeControlItem(nDialogID, kTree, 'C:\', -1, -1); nChild3 := InsertTreeControlItem(nDialogID, kTree, 'MyProjects', nParent2, -1); nChild4 := InsertTreeControlItem(nDialogID, kTree, 'House.mcd', nChild3, -1); bResult := InsertProposedClassOrLayerItem(nDialogID, kSheetLayerPullDown, 'Window Spec', 0); END; kIconButton1: BEGIN bResult := SetIconPushButtonState(nDialogID, kIconButton1, true); bResult := SetIconPushButtonState(nDialogID, kIconButton2, false); bResult := SetIconPushButtonState(nDialogID, kIconButton3, false); bResult := SetIconPushButtonState(nDialogID, kIconButton4, false); END; kIconButton2: BEGIN bResult := SetIconPushButtonState(nDialogID, kIconButton1, false); bResult := SetIconPushButtonState(nDialogID, kIconButton2, true); bResult := SetIconPushButtonState(nDialogID, kIconButton3, false); bResult := SetIconPushButtonState(nDialogID, kIconButton4, false); END; kIconButton3: BEGIN bResult := SetIconPushButtonState(nDialogID, kIconButton1, false); bResult := SetIconPushButtonState(nDialogID, kIconButton2, false); bResult := SetIconPushButtonState(nDialogID, kIconButton3, true); bResult := SetIconPushButtonState(nDialogID, kIconButton4, false); END; kIconButton4: BEGIN bResult := SetIconPushButtonState(nDialogID, kIconButton1, false); bResult := SetIconPushButtonState(nDialogID, kIconButton2, false); bResult := SetIconPushButtonState(nDialogID, kIconButton3, false); bResult := SetIconPushButtonState(nDialogID, kIconButton4, true); END; END; END; BEGIN dialog1_Setup; IF RunLayoutDialog(nDialogID, dialog1_Handler) = 1 then BEGIN END; END; {---------------------------------------------------------------------------------------} RUN(dialog1_Main);