Introduction
In the previous training, Ensemble Graphics Toolkit - First Application using Eclipse IDE, you used the Eclipse IDE for C/C++ Developers to build a *.cpp program to display the button widget on the target’s WVGA Display. A widget is a User Interface (UI) component with a basic set of properties. In this training, you will build a *.cpp program to set the property of positioning the button widget anywhere in the window of the WVGA display you desire.
Steps:
Prerequisites
You have prepared the Host PC with all the development software tools and Ensemble Graphics Toolkit source code as explained in:
You have installed and prepared the Eclipse IDE for C/C++ Developers as explained in:
Create a New Source File
In this section, you will be creating a new *.cpp source file that you will build in later sections demonstrating the positioning of the button widget.
In this training, you will use EgtProject and its settings you entered in the training: Ensemble Graphics Toolkit -- First Application using Eclipse IDE
2
If you have the basic.cpp file from Ensemble Graphics Toolkit -- First Application using Eclipse IDE open:
b
Select Debug and Release and click on the OK button.
basic.cpp will be excluded from the build.
3
Right click on EgtProject and select Clean Project.
5
Enter widgets.cpp into the Source file: text box. Click on the Finish push button.
A new source file tab widgets.cpp is created within EgtProject.
6
Enter the following source code to the widgets.cpp window pane:
This is the very same source code you entered into the basic.cpp window in the Ensemble Graphics Toolkit -- First Application using Eclipse IDE training. You will be modifying it in the next section.
7
Save your program by selecting File > Save.
You have completed adding a new source file to EgtProject.
Change Widget Alignment
In this section, you will modify the widgets.cpp source code to demonstrate the button.align function.
1
Modify the widgets.cpp source code by:
a
Commenting out center(button), and
b
Adding the button.align( ) function as shown below:
2
Save your program by selecting File > Save. You may also save by typing CTRL+S.
3
To build the project, click on the Build icon.
The Console window (bottom pane) will display the build progress.
4
To set run properties, hover over EgtProject, right click, and select Run As > Run Configurations… from the menu.
6
In the Run Configurations window, enter the following in the Remote Absolute File Path for C/C++ Application: text box:
/root/widgets
You may see the previous program /root/basic here. Replace with /root/widgets.
This is the location the widgets.cpp executable will be loaded and run on the target.
7
Click on the Apply button.
8
Click on the Run button.
10
To stop the program, press the Stop button (upper left hand, just below the menu bar).
Before you start another session, be sure to stop the current session.
Widget::align(const AlignFlags & a)
This will align the widget with respect to the box of the parent frame, TopWindow in this case. Here are some AlignFlag supported:
none | No alignment |
center_horizontal | Center alignment is a weak alignment both horizontal and vertical. To break one of those dimensions to another alignment, specify it in addition to center. If both are broken, center has no effect. |
center_vertical | Center vertical alignment |
center | Center horizontal and vertical alignment |
left | Horizontal alignment |
right | Horizontal alignment |
top | Vertical alignment |
bottom | Vertical alignment |
expand_horizontal | Expand only horizontally |
expand_vertical | Expand only vertically |
expand | Expand vertically and horizontally |
Move Widget to a Point(x,y)
In this section, you will modify the widgets.cpp source code to demonstrate the widget member function move( ) to change the position of the widget.
1
Modify the widgets.cpp source code by:
a
Comment out the button.align( ) function, and
b
Type the following button.move( ) function as shown below:
2
Save your program by selecting File > Save. You may also save by typing "CTRL+S".
3
To build the project, click on the Build icon.
The Console window (bottom pane) will display the build progress.
4
Click on the Run button.
6
Observe the widget (button) X and Y coordinates are printed on the terminal console:
/root/widgets; exit
X:300 Y:300
7
To stop the program, press the Stop button (upper left hand, just below the menu bar).
Widget::move(const Point & point)
This will change the X and Y coordinate of the widget relative to the parent and move it to the specified position.
Class PointType
From ~/egt/docs/html/annotated.html, click on the PointType class. All the functions and the constructor associated with the PointType class is documented here. It specifies simple x and y coordinate.
Point is the helper type for a default point. In this example, we pass the Point(x,y) as Widget::move function parameters to move widget to that point.
Widget::x() and Widget::y()
From ~/egt/docs/html/annotated.html, click on the Widget class. X and Y widget member functions allow users to get the X and Y coordinate of the widget origin.
Widget::x(DefaultDim x) and Widget::y(DefaultDim y)
From ~/egt/docs/html/annotated.html, click on the Widget class. These widget member functions allow users to set the X and Y coordinate of the widget relative to its parent using DefaultDim=int; It is the default dimension type used for geometry.
Exercise 1
Use the EGT documentation and change the widget width:
- Increase the width to twice the widget’s old width.
- Set the widget height to 70.
The screen should look like this:
Observe the widget (button) X and Y coordinates are printed on the terminal console.
Refer to "Ensemble Graphics Toolkit: Exercise Solution 1" for the solution.
Summary
In this training, you explored two methods to position the button widget in the window of the WVGA Display.
What’s Next?
There’s plenty more to learn. Here are some additional Ensemble Graphics Toolkit training resources to help you gain more knowledge and skills: