Table of Contents

Widgets Menu


Button Widgets

The Elementary button widget is a simple push button. It is composed of a label icon and an icon object and has autorepeat feature.

Table of Contents

Adding a Button

//Creating a button
Evas_Object *button = elm_button_add(parent);

Adding an Icon Inside a Button

The icon can be updated with elm_object_part_content_set() function with the “icon” part name.

Evas_Object *ic;
ic = elm_icon_add(button);
elm_image_file_set(ic, "icon.png", NULL);
elm_object_part_content_set(button, "icon", ic);

Adding Text Inside a Button

The label can be modified using the elm_object_text_set() function.

elm_object_text_set(button, "Click me!");

Using Button Style

Also, defined in the default theme, the button has the following styles available:

To change the style of the button, we call the elm_object_style_set() function on our button object.

elm_object_style_set(button,"naviframe");

Using Button Callbacks

Button emits the following signals:

For all these signals the event_info parameter returned in the callback is NULL.

This is an example to register and define callback function called by the clicked signal.

evas_object_smart_callback_add(button, "clicked", _clicked_cb, data);
// Callback function for the "clicked" signal
// This callback is called when the button is clicked by the user
 
static void
_clicked_cb (void *data, Evas_Object *obj, void *event_info)
{
   printf("Button clicked\n");
}

Using Autorepeat Feature

The autorepeat feature (enabled by default) consists of calling the “repeated” signal when the user keeps the button pressed. This feature can be disabled with the elm_button_autorepeat_set() function. The autorepeat is configured with

Disable the autorepeat feature:

elm_button_autorepeat_set(button, EINA_FALSE);

Enable the autorepeat feature (enabled by default):

elm_button_autorepeat_set(button, EINA_TRUE);

Set the initial timeout to five seconds:

elm_button_autorepeat_initial_timeout_set(button, 5.0);

Set the gap between two signals to 0.5 seconds:

elm_button_autorepeat_gap_timeout_set(button, 0.5);




Widgets Menu