Ensemble Graphics Toolkit: Widget Positioning

Introduction

In the previous topic, 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 topic, 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 the topic:

You have installed and prepared the Eclipse IDE for C/C++ Developers as explained in the topic:


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 topic, you will use EgtProject and its settings you entered in the training topic: Ensemble Graphics Toolkit -- First Application using Eclipse IDE

1

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_ide_launcher.png

Eclipse will launch the previous workspace you configured.

eclipse_previous_workspace.png

2

If you have the basic.cpp file from Ensemble Graphics Toolkit -- First Application using Eclipse IDE open:

a

Right click in the basic.cpp window and select Resource Configurations > Exclude from Build…

The Exclude from build window will open:

eclipse_exclude_from_build.png

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

4

Right click on EgtProject and select New > Source File.

The New Source File window will open:

eclipse_new_source_file.png

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 the 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 topic. 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

Add 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.

5

In the left-hand pane, select EgtProject Debug (under C/C++ Remote Application).

run_configurations_widgets.png

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.

9

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.

widgets_display_1.png

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.

5

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).

widgets_display_2.png

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 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:

extra_credit_1.png

Observe the widget (button) X and Y coordinates are printed on the terminal console.

Click here for solution.


Summary

In this training topic, 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 topics to help you gain more knowledge and skills:

© 2020 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.