Ensemble Graphics Toolkit: Widget Positioning
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.
Prerequisites
You have prepared the Host PC with all the development software tools and Ensemble Graphics Toolkit source code as explained on the "Ensemble Graphics Toolkit: Preparing the Host PC and Target" page.
You have installed and prepared the Eclipse IDE for C/C++ Developers as explained on the "Ensemble Graphics Toolkit: First Application Using Eclipse IDE" page.
Steps
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 the settings you entered from the "Ensemble Graphics Toolkit: First Application Using Eclipse IDE" page.
Start the Eclipse IDE.
Eclipse will ask you to select a directory for your workspace. Accept the default directory and click on the Launch button.
Eclipse will launch the previous workspace you configured.
If you have the basic.cpp file from the "Ensemble Graphics Toolkit: First Application Using Eclipse IDE" page, proceed with the following:
The Exclude from build window will open:
The basic.cpp file will be excluded from the build.
Right-click on EgtProject and select New > Source File.
The New Source File window will open:
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.
Enter the following source code to the widgets.cpp window pane:
#include <iostream>
using namespace std;
using namespace egt;
int main(int argc, const char ** argv)
{
Application app;
TopWindow window;
Button button(window, "Press Me");
center(button);
window.show();
return app.run();
}
Change Widget Alignment
In this section, you will modify the widgets.cpp source code to demonstrate the button.align function.
Modify the widgets.cpp source code by:
#include <iostream>
using namespace std;
using namespace egt;
int main(int argc, const char ** argv)
{
Application app;
TopWindow window;
Button button(window, "Press Me");
// center(button);
button.align(AlignFlag::center | AlignFlag::left);
window.show();
return app.run();
}
To build the project, click on the Build icon.
The Console window (bottom pane) will display the build progress.
In the left-hand pane, select EgtProject Debug (under C/C++ Remote Application).
In the Run Configurations window, enter the following in the Remote Absolute File Path for C/C++ Application: text box:
/root/widgets
This is the location the widgets.cpp executable will be loaded and run on the target.
Observe the WVGA Display on the target:
The widgets.cpp executable is running remotely on the target.
Observe the Press me button is aligned in the center (top to bottom) and to the left of the display window.
To stop the program, press the Stop button (upper left-hand, just below the menu bar).
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.
Modify the widgets.cpp source code by:
#include <iostream>
using namespace std;
using namespace egt;
int main(int argc, const char ** argv)
{
Application app;
TopWindow window;
Button button(window, "Press Me");
// center(button);
// button.align(AlignFlag::center | AlignFlag::left);
button.move(Point(300,300));
cout << "X:" << button.x() << " Y:" << button.y() << endl;
window.show();
return app.run();
}
To build the project, click on the Build icon.
The Console window (bottom pane) will display the build progress.
Observe the WVGA Display on the target:
The widgets.cpp executable is running remotely on the target.
Observe the Press me button is aligned in the center (left to right) and a little below center (top to bottom).
Observe the widget (button) X and Y coordinates are printed on the terminal console:
/root/widgets; exit
X:300 Y:300
To stop the program, press the Stop button (upper left hand, just below the menu bar).
Summary
In this training, you explored two methods to position the button widget in the window of the WVGA Display.
Learn More
There’s plenty more to learn. Here are some additional Ensemble Graphics Toolkit training resources to help you gain more knowledge and skills: