Difference between revisions of "Creating a widget"

From uGFX Wiki
Jump to: navigation, search
(Object structure)
Line 7: Line 7:
  
 
=== Object structure ===
 
=== Object structure ===
The C language is not object oriented - yet it's possible to write object oriented software without any problems. The philosophy is to create a struct which is ''the object'' and to pass that struct as the first parameter to any function that has to have access to the object.
+
The C language is not object oriented - yet it's possible to write object oriented software without any problems. The philosophy is to create a struct which is ''the object'' and to pass that struct as the first parameter to any function that has to have access to the object. A widget is an object and hence it needs a struct that defines the object. The only thing that makes the widget object struct become a ''widget'' struct is that the very first field is a <code>GWidgetObject</code>:
 +
<syntax lang="c">
 +
typedef struct StatusbarObject_t {
 +
    GWidgetObject w;  // Base Class
 +
} StatusbarObject;
 +
</syntax>

Revision as of 16:47, 10 April 2016

It's possible to implement custom widgets. A custom widget can be declared and implemented outside of the µGFX library. This means that it can be part of the actual project and that it's not necessary to do any modification of the µGFX library itself.

Note: If you just want to change the look of an existing widget, please have a look at WidgetStyles and custom rendering functions.

Architecture

A widget consists of two main parts: The object structure and the VMT.

Object structure

The C language is not object oriented - yet it's possible to write object oriented software without any problems. The philosophy is to create a struct which is the object and to pass that struct as the first parameter to any function that has to have access to the object. A widget is an object and hence it needs a struct that defines the object. The only thing that makes the widget object struct become a widget struct is that the very first field is a GWidgetObject: <syntax lang="c"> typedef struct StatusbarObject_t {

   GWidgetObject w;  // Base Class

} StatusbarObject; </syntax>