Button - Hello, Button!

Keeping the tradition, this is a simple "Hello, World" button example. We will show how to create a button and associate and action to be performed when you click on it.

In the end, we'll be presented with something that looks like this:

The full code of the example is here and we will follow here with a rundown of it.

There is only one button on the interface which performs a basic action: close the application. This behavior is described by on_click() function, that interrupt the program invoking elm_exit().

static void
on_click(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
{
elm_exit();
}
EINA_UNUSED
#define EINA_UNUSED
Used to indicate that a function parameter is purposely unused.
Definition eina_types.h:339
elm_exit
void elm_exit(void)
Ask to exit Elementary's main loop.
Definition elm_main.c:1373
Evas_Object
Efl_Canvas_Object Evas_Object
An Evas Object handle.
Definition Evas_Common.h:185

On the main() function, we set the basic characteristics of the user interface. First we use the Elementary library to create a window and set its policies (such as close when the user click on the window close icon).

In order to turn it visible on the WM (Window Manager), we also have to associate it to a canvas through Evas library, and set its dimensions.

Then we create a background associated to the window, define its dimensions, and turn it visible on the canvas.

Finally we use Elementary to create a button and Evas to set its proprieties. Here we have not only to give the button dimensions, but also its coordinates and the action to be performed on the click event.

And we are done.