button_example_01.c

- Main Page
- Related Pages
- Modules
- Data Structures
- Files
- Examples

button_example_01.c
/*
* gcc -o button_example_01 button_example_01.c `pkg-config --cflags --libs elementary`
*/
#include <Elementary.h>
typedef struct
{
Evas_Object *mid;
Evas_Object *icon_still;
struct
{
Evas_Object *up;
Evas_Object *down;
Evas_Object *left;
Evas_Object *right;
} cursors;
} App_Data;
static void
_btn_cursors_release_cb(void *data, Evas_Object *btn EINA_UNUSED,
void *ev EINA_UNUSED)
{
App_Data *app = data;
elm_object_part_content_set(app->mid, "icon", app->icon_still);
app->icon_still = NULL;
}
static void
_btn_cursors_move_cb(void *data, Evas_Object *btn, void *ev EINA_UNUSED)
{
App_Data *app = data;
double ax, ay;
if (!app->icon_still)
{
Evas_Object *icon;
app->icon_still = elm_object_content_unset(app->mid);
evas_object_hide(app->icon_still);
icon = elm_icon_add(app->mid);
elm_icon_standard_set(icon, "chat");
elm_object_part_content_set(app->mid, "icon", icon);
}
evas_object_size_hint_align_get(app->mid, &ax, &ay);
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_object_size_hint_align_set(app->mid, ax, ay);
}
static void
_btn_options_cb(void *data, Evas_Object *btn, void *ev EINA_UNUSED)
{
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))
{
elm_button_autorepeat_initial_timeout_set(app->cursors.up, t);
elm_button_autorepeat_initial_timeout_set(app->cursors.down, t);
elm_button_autorepeat_initial_timeout_set(app->cursors.left, t);
elm_button_autorepeat_initial_timeout_set(app->cursors.right, t);
}
else if (!strncmp(lbl, "Gap", 3))
{
elm_button_autorepeat_gap_timeout_set(app->cursors.up, t);
elm_button_autorepeat_gap_timeout_set(app->cursors.down, t);
elm_button_autorepeat_gap_timeout_set(app->cursors.left, t);
elm_button_autorepeat_gap_timeout_set(app->cursors.right, t);
}
}
EAPI_MAIN int
elm_main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
{
Evas_Object *win, *box, *box2, *btn, *icon;
static App_Data data;
elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
win = elm_win_util_standard_add("Button example", "Button example");
elm_win_autodel_set(win, EINA_TRUE);
box = elm_box_add(win);
evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
elm_win_resize_object_add(win, box);
evas_object_show(box);
box2 = elm_box_add(win);
elm_box_horizontal_set(box2, EINA_TRUE);
evas_object_size_hint_weight_set(box2, EVAS_HINT_EXPAND, 0.0);
elm_box_pack_end(box, box2);
evas_object_show(box2);
btn = elm_button_add(win);
elm_object_text_set(btn, "Initial: 0.0");
elm_box_pack_end(box2, btn);
evas_object_show(btn);
evas_object_smart_callback_add(btn, "clicked", _btn_options_cb, &data);
btn = elm_button_add(win);
elm_object_text_set(btn, "Initial: 1.0");
elm_box_pack_end(box2, btn);
evas_object_show(btn);
evas_object_smart_callback_add(btn, "clicked", _btn_options_cb, &data);
btn = elm_button_add(win);
elm_object_text_set(btn, "Initial: 5.0");
elm_box_pack_end(box2, btn);
evas_object_show(btn);
evas_object_smart_callback_add(btn, "clicked", _btn_options_cb, &data);
box2 = elm_box_add(win);
elm_box_horizontal_set(box2, EINA_TRUE);
evas_object_size_hint_weight_set(box2, EVAS_HINT_EXPAND, 0.0);
elm_box_pack_end(box, box2);
evas_object_show(box2);
btn = elm_button_add(win);
elm_object_text_set(btn, "Gap: 0.1");
elm_box_pack_end(box2, btn);
evas_object_show(btn);
evas_object_smart_callback_add(btn, "clicked", _btn_options_cb, &data);
btn = elm_button_add(win);
elm_object_text_set(btn, "Gap: 0.5");
elm_box_pack_end(box2, btn);
evas_object_show(btn);
evas_object_smart_callback_add(btn, "clicked", _btn_options_cb, &data);
btn = elm_button_add(win);
elm_object_text_set(btn, "Gap: 1.0");
elm_box_pack_end(box2, btn);
evas_object_show(btn);
evas_object_smart_callback_add(btn, "clicked", _btn_options_cb, &data);
btn = elm_button_add(win);
elm_button_autorepeat_set(btn, EINA_TRUE);
elm_button_autorepeat_initial_timeout_set(btn, 1.0);
elm_button_autorepeat_gap_timeout_set(btn, 0.5);
evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, 0.0);
evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, 0.0);
elm_box_pack_end(box, btn);
evas_object_show(btn);
evas_object_smart_callback_add(btn, "repeated", _btn_cursors_move_cb, &data);
evas_object_smart_callback_add(btn, "unpressed", _btn_cursors_release_cb,
&data);
icon = elm_icon_add(win);
elm_icon_standard_set(icon, "arrow_up");
elm_object_part_content_set(btn, "icon", icon);
data.cursors.up = btn;
box2 = elm_box_add(win);
elm_box_horizontal_set(box2, EINA_TRUE);
evas_object_size_hint_weight_set(box2, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(box2, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_box_pack_end(box, box2);
evas_object_show(box2);
btn = elm_button_add(win);
elm_button_autorepeat_set(btn, EINA_TRUE);
elm_button_autorepeat_initial_timeout_set(btn, 1.0);
elm_button_autorepeat_gap_timeout_set(btn, 0.5);
evas_object_size_hint_weight_set(btn, 0.0, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(btn, 0.0, EVAS_HINT_FILL);
elm_box_pack_end(box2, btn);
evas_object_show(btn);
evas_object_smart_callback_add(btn, "repeated", _btn_cursors_move_cb, &data);
evas_object_smart_callback_add(btn, "unpressed", _btn_cursors_release_cb,
&data);
icon = elm_icon_add(win);
elm_icon_standard_set(icon, "arrow_left");
elm_object_part_content_set(btn, "icon", icon);
data.cursors.left = btn;
btn = elm_button_add(win);
evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
elm_box_pack_end(box2, btn);
evas_object_show(btn);
icon = elm_icon_add(win);
elm_icon_standard_set(icon, "close");
elm_object_part_content_set(btn, "icon", icon);
data.mid = btn;
btn = elm_button_add(win);
elm_button_autorepeat_set(btn, EINA_TRUE);
elm_button_autorepeat_initial_timeout_set(btn, 1.0);
elm_button_autorepeat_gap_timeout_set(btn, 0.5);
evas_object_size_hint_weight_set(btn, 0.0, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(btn, 0.0, EVAS_HINT_FILL);
elm_box_pack_end(box2, btn);
evas_object_show(btn);
evas_object_smart_callback_add(btn, "repeated", _btn_cursors_move_cb, &data);
evas_object_smart_callback_add(btn, "unpressed", _btn_cursors_release_cb,
&data);
icon = elm_icon_add(win);
elm_icon_standard_set(icon, "arrow_right");
elm_object_part_content_set(btn, "icon", icon);
data.cursors.right = btn;
btn = elm_button_add(win);
elm_button_autorepeat_set(btn, EINA_TRUE);
elm_button_autorepeat_initial_timeout_set(btn, 1.0);
elm_button_autorepeat_gap_timeout_set(btn, 0.5);
evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, 0.0);
evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, 0.0);
elm_box_pack_end(box, btn);
evas_object_show(btn);
evas_object_smart_callback_add(btn, "repeated", _btn_cursors_move_cb, &data);
evas_object_smart_callback_add(btn, "unpressed", _btn_cursors_release_cb,
&data);
icon = elm_icon_add(win);
elm_icon_standard_set(icon, "arrow_down");
elm_object_part_content_set(btn, "icon", icon);
data.cursors.down = btn;
evas_object_resize(win, 300, 320);
evas_object_show(win);
elm_run();
return 0;
}
ELM_MAIN()
EVAS_HINT_EXPAND
#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
EVAS_HINT_FILL
#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
EINA_TRUE
#define EINA_TRUE
boolean value TRUE (numerical value 1)
Definition: eina_types.h:539
EINA_UNUSED
#define EINA_UNUSED
Used to indicate that a function parameter is purposely unused.
Definition: eina_types.h:339
elm_box_horizontal_set
void elm_box_horizontal_set(Elm_Box *obj, Eina_Bool horizontal)
Set the horizontal orientation.
Definition: elm_box_eo.legacy.c:27
elm_box_add
Evas_Object * elm_box_add(Evas_Object *parent)
Add a new box to the parent.
Definition: elm_box.c:363
elm_box_pack_end
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
elm_button_autorepeat_set
void elm_button_autorepeat_set(Evas_Object *obj, Eina_Bool on)
Turn on/off the autorepeat event generated when the button is kept pressed.
Definition: efl_ui_button.c:364
elm_button_autorepeat_initial_timeout_set
void elm_button_autorepeat_initial_timeout_set(Evas_Object *obj, double t)
The initial timeout before the autorepeat event is generated.
Definition: efl_ui_button.c:340
elm_button_add
Evas_Object * elm_button_add(Evas_Object *parent)
Add a new button to the parent's canvas.
Definition: efl_ui_button.c:459
elm_button_autorepeat_gap_timeout_set
void elm_button_autorepeat_gap_timeout_set(Evas_Object *obj, double t)
The interval between each generated autorepeat event.
Definition: efl_ui_button.c:352
elm_object_part_content_set
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
ELM_MAIN
#define ELM_MAIN()
macro to be used after the elm_main() function
Definition: elm_general.h:556
elm_policy_set
Eina_Bool elm_policy_set(unsigned int policy, int value)
Set a new policy's value (for a given policy group/identifier).
Definition: elm_main.c:1380
elm_run
void elm_run(void)
Run Elementary's main loop.
Definition: elm_main.c:1357
ELM_POLICY_QUIT_LAST_WINDOW_CLOSED
@ ELM_POLICY_QUIT_LAST_WINDOW_CLOSED
quit when the application's last window is closed
Definition: elm_general.h:248
ELM_POLICY_QUIT
@ ELM_POLICY_QUIT
under which circumstances the application should quit automatically.
Definition: elm_general.h:227
elm_icon_standard_set
Eina_Bool elm_icon_standard_set(Evas_Object *obj, const char *name)
Set the icon by icon standards names.
Definition: elm_icon.c:885
elm_icon_add
Evas_Object * elm_icon_add(Evas_Object *parent)
Add a new icon object to the parent.
Definition: elm_icon.c:613
elm_win_util_standard_add
Evas_Object * elm_win_util_standard_add(const char *name, const char *title)
Adds a window object with standard setup.
Definition: efl_ui_win.c:9582
elm_win_resize_object_add
void elm_win_resize_object_add(Eo *obj, Evas_Object *subobj)
Add subobj as a resize object of window obj.
Definition: efl_ui_win.c:8997
elm_win_autodel_set
void elm_win_autodel_set(Eo *obj, Eina_Bool autodel)
Set the window's autodel state.
Definition: efl_ui_win.c:6194
evas_object_show
EVAS_API void evas_object_show(Evas_Object *eo_obj)
Makes the given Evas object visible.
Definition: evas_object_main.c:1814
evas_object_hide
EVAS_API void evas_object_hide(Evas_Object *eo_obj)
Makes the given Evas object invisible.
Definition: evas_object_main.c:1823
evas_object_size_hint_align_get
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_object_size_hint_weight_set
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
Evas_Object
Efl_Canvas_Object Evas_Object
An Evas Object handle.
Definition: Evas_Common.h:185
evas_object_size_hint_align_set
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
evas_object_resize
EVAS_API void evas_object_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
Changes the size of the given Evas object.
Definition: evas_object_main.c:1236
evas_object_smart_callback_add
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