A button is simple, you click on it and something happens. That said, we'll go through an example to show in detail the button API less commonly used.
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.
#include <Elementary.h>
typedef struct
{
struct
{
} cursors;
} App_Data;
Efl_Canvas_Object Evas_Object
An Evas Object handle.
Definition: Evas_Common.h:185
We have several buttons to set different times for the autorepeat timeouts of the buttons that use it and a few more that we keep track of in our data struct. The mid button doesn't do much, just moves around according to what other buttons the user presses. Then four more buttons to move the central one, and we're also keeping track of the icon set in the middle button, since when this one moves, we change the icon, and when movement is finished (by releasing one of the four arrow buttons), we set back the normal icon.
static void
{
App_Data *app = data;
app->icon_still = NULL;
}
#define EINA_UNUSED
Used to indicate that a function parameter is purposely unused.
Definition: eina_types.h:339
void elm_object_part_content_set(Evas_Object *obj, const char *part, Evas_Object *content)
Set the content on part of a given container widget.
Definition: elm_main.c:1562
Keeping any of those four buttons pressed will trigger their autorepeat callback, where we move the button doing some size hint magic. To understand how that works better, refer to the Elm_Box documentation. Also, the first time the function is called, we change the icon in the middle button, using elm_object_content_unset() first to keep the reference to the previous one, so we don't need to recreate it when we are done moving it.
static void
{
App_Data *app = data;
double ax, ay;
if (!app->icon_still)
{
app->icon_still = elm_object_content_unset(app->mid);
}
Eina_Bool elm_icon_standard_set(Evas_Object *obj, const char *name)
Set the icon by icon standards names.
Definition: elm_icon.c:885
Evas_Object * elm_icon_add(Evas_Object *parent)
Add a new icon object to the parent.
Definition: elm_icon.c:613
EVAS_API void evas_object_hide(Evas_Object *eo_obj)
Makes the given Evas object invisible.
Definition: evas_object_main.c:1823
if (btn == app->cursors.up)
{
ay -= 0.05;
if (ay < 0.0)
ay = 0.0;
}
else if (btn == app->cursors.down)
{
ay += 0.05;
if (ay > 1.0)
ay = 1.0;
}
else if (btn == app->cursors.left)
{
ax -= 0.05;
if (ax < 0.0)
ax = 0.0;
}
else if (btn == app->cursors.right)
{
ax += 0.05;
if (ax > 1.0)
ax = 1.0;
}
EVAS_API void evas_object_size_hint_align_get(const Evas_Object *obj, double *x, double *y)
Retrieves the hints for on object's alignment.
Definition: evas_object_main.c:2656
EVAS_API void evas_object_size_hint_align_set(Evas_Object *obj, double x, double y)
Sets the hints for an object's alignment.
Definition: evas_object_main.c:2650
}
One more callback for the option buttons, that just sets the timeouts for the different autorepeat options.
static void
{
char *ptr;
double t;
App_Data *app = data;
const char *lbl = elm_object_text_get(btn);
ptr = strchr(lbl, ':');
ptr += 2;
t = strtod(ptr, NULL);
if (!strncmp(lbl, "Initial", 7))
{
}
else if (!strncmp(lbl, "Gap", 3))
{
}
}
And the main function, which does some setting up of the buttons in boxes to make things work. Here we'll go through some snippets only.
For the option buttons, it's just the button with its label and callback.
elm_object_text_set(btn, "Initial: 0.0");
void elm_box_pack_end(Elm_Box *obj, Efl_Canvas_Object *subobj)
Add an object at the end of the pack list.
Definition: elm_box_eo.legacy.c:57
EVAS_API void evas_object_show(Evas_Object *eo_obj)
Makes the given Evas object visible.
Definition: evas_object_main.c:1814
EVAS_API void evas_object_smart_callback_add(Evas_Object *eo_obj, const char *event, Evas_Smart_Cb func, const void *data)
Add (register) a callback function to the smart event specified by event on the smart object obj.
Definition: evas_object_smart.c:1040
For the ones that move the central button, we have no labels. There are icons instead, and the autorepeat option is toggled.
&data);
data.cursors.up = btn;
#define EVAS_HINT_EXPAND
Use with evas_object_size_hint_weight_set(), evas_object_size_hint_weight_get(), evas_object_size_hin...
Definition: Evas_Common.h:297
#define EVAS_HINT_FILL
Use with evas_object_size_hint_align_set(), evas_object_size_hint_align_get(), evas_object_size_hint_...
Definition: Evas_Common.h:298
#define EINA_TRUE
boolean value TRUE (numerical value 1)
Definition: eina_types.h:539
EVAS_API void evas_object_size_hint_weight_set(Evas_Object *obj, double x, double y)
Sets the hints for an object's weight.
Definition: evas_object_main.c:2638
And just to show the mid button, which doesn't have anything special.
And we are done.