\section{button\-\_\-example\-\_\-01.\-c}

\begin{DoxyCodeInclude}
\textcolor{comment}{/*}
\textcolor{comment}{ * gcc -o button\_example\_01 button\_example\_01.c `pkg-config --cflags --libs elementary`}
\textcolor{comment}{ */}
\textcolor{preprocessor}{#include <Elementary.h>}

\textcolor{keyword}{typedef} \textcolor{keyword}{struct}
\{
   Evas\_Object *mid;
   Evas\_Object *icon\_still;
   \textcolor{keyword}{struct}
     \{
        Evas\_Object *up;
        Evas\_Object *down;
        Evas\_Object *left;
        Evas\_Object *right;
     \} cursors;
\} App\_Data;

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_btn\_cursors\_release\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *btn, \textcolor{keywordtype}{void} *ev)
\{
   App\_Data *app = data;
   elm_object_part_content_set(app->mid, \textcolor{stringliteral}{"icon"}, app->icon\_still);
   app->icon\_still = NULL;
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_btn\_cursors\_move\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *btn, \textcolor{keywordtype}{void} *ev)
\{
   App\_Data *app = data;
   \textcolor{keywordtype}{double} ax, ay;

   \textcolor{keywordflow}{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, \textcolor{stringliteral}{"chat"});
        elm_object_part_content_set(app->mid, \textcolor{stringliteral}{"icon"}, icon);
     \}

   evas\_object\_size\_hint\_align\_get(app->mid, &ax, &ay);
   \textcolor{keywordflow}{if} (btn == app->cursors.up)
     \{
        ay -= 0.05;
        \textcolor{keywordflow}{if} (ay < 0.0)
          ay = 0.0;
     \}
   \textcolor{keywordflow}{else} \textcolor{keywordflow}{if} (btn == app->cursors.down)
     \{
        ay += 0.05;
        \textcolor{keywordflow}{if} (ay > 1.0)
          ay = 1.0;
     \}
   \textcolor{keywordflow}{else} \textcolor{keywordflow}{if} (btn == app->cursors.left)
     \{
        ax -= 0.05;
        \textcolor{keywordflow}{if} (ax < 0.0)
          ax = 0.0;
     \}
   \textcolor{keywordflow}{else} \textcolor{keywordflow}{if} (btn == app->cursors.right)
     \{
        ax += 0.05;
        \textcolor{keywordflow}{if} (ax > 1.0)
          ax = 1.0;
     \}
   evas\_object\_size\_hint\_align\_set(app->mid, ax, ay);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_btn\_options\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *btn, \textcolor{keywordtype}{void} *ev)
\{
   \textcolor{keywordtype}{char} *ptr;
   \textcolor{keywordtype}{double} t;
   App\_Data *app = data;
   \textcolor{keyword}{const} \textcolor{keywordtype}{char} *lbl = elm\_object\_text\_get(btn);

   ptr = strchr(lbl, \textcolor{charliteral}{':'});
   ptr += 2;
   t = strtod(ptr, NULL);

   \textcolor{keywordflow}{if} (!strncmp(lbl, \textcolor{stringliteral}{"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);
     \}
   \textcolor{keywordflow}{else} \textcolor{keywordflow}{if} (!strncmp(lbl, \textcolor{stringliteral}{"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 \textcolor{keywordtype}{int}
elm\_main(\textcolor{keywordtype}{int} argc, \textcolor{keywordtype}{char} *argv[])
\{
   Evas\_Object *win, *box, *box2, *btn, *icon;
   \textcolor{keyword}{static} App\_Data data;

   elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);

   win = elm_win_util_standard_add(\textcolor{stringliteral}{"Button example"}, \textcolor{stringliteral}{"Button example"});
   elm_win_autodel_set(win, EINA\_TRUE);
   evas\_object\_resize(win, 300, 320);
   evas\_object\_show(win);

   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, \textcolor{stringliteral}{"Initial: 0.0"});
   elm_box_pack_end(box2, btn);
   evas\_object\_show(btn);
   evas\_object\_smart\_callback\_add(btn, \textcolor{stringliteral}{"clicked"}, \_btn\_options\_cb, &data);

   btn = elm_button_add(win);
   elm\_object\_text\_set(btn, \textcolor{stringliteral}{"Initial: 1.0"});
   elm_box_pack_end(box2, btn);
   evas\_object\_show(btn);
   evas\_object\_smart\_callback\_add(btn, \textcolor{stringliteral}{"clicked"}, \_btn\_options\_cb, &data);

   btn = elm_button_add(win);
   elm\_object\_text\_set(btn, \textcolor{stringliteral}{"Initial: 5.0"});
   elm_box_pack_end(box2, btn);
   evas\_object\_show(btn);
   evas\_object\_smart\_callback\_add(btn, \textcolor{stringliteral}{"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, \textcolor{stringliteral}{"Gap: 0.1"});
   elm_box_pack_end(box2, btn);
   evas\_object\_show(btn);
   evas\_object\_smart\_callback\_add(btn, \textcolor{stringliteral}{"clicked"}, \_btn\_options\_cb, &data);

   btn = elm_button_add(win);
   elm\_object\_text\_set(btn, \textcolor{stringliteral}{"Gap: 0.5"});
   elm_box_pack_end(box2, btn);
   evas\_object\_show(btn);
   evas\_object\_smart\_callback\_add(btn, \textcolor{stringliteral}{"clicked"}, \_btn\_options\_cb, &data);

   btn = elm_button_add(win);
   elm\_object\_text\_set(btn, \textcolor{stringliteral}{"Gap: 1.0"});
   elm_box_pack_end(box2, btn);
   evas\_object\_show(btn);
   evas\_object\_smart\_callback\_add(btn, \textcolor{stringliteral}{"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, \textcolor{stringliteral}{"repeated"}, \_btn\_cursors\_move\_cb, &data);
   evas\_object\_smart\_callback\_add(btn, \textcolor{stringliteral}{"unpressed"}, \_btn\_cursors\_release\_cb,
                                  &data);

   icon = elm_icon_add(win);
   elm_icon_standard_set(icon, \textcolor{stringliteral}{"arrow\_up"});
   elm_object_part_content_set(btn, \textcolor{stringliteral}{"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, \textcolor{stringliteral}{"repeated"}, \_btn\_cursors\_move\_cb, &data);
   evas\_object\_smart\_callback\_add(btn, \textcolor{stringliteral}{"unpressed"}, \_btn\_cursors\_release\_cb,
                                  &data);

   icon = elm_icon_add(win);
   elm_icon_standard_set(icon, \textcolor{stringliteral}{"arrow\_left"});
   elm_object_part_content_set(btn, \textcolor{stringliteral}{"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, \textcolor{stringliteral}{"close"});
   elm_object_part_content_set(btn, \textcolor{stringliteral}{"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, \textcolor{stringliteral}{"repeated"}, \_btn\_cursors\_move\_cb, &data);
   evas\_object\_smart\_callback\_add(btn, \textcolor{stringliteral}{"unpressed"}, \_btn\_cursors\_release\_cb,
                                  &data);

   icon = elm_icon_add(win);
   elm_icon_standard_set(icon, \textcolor{stringliteral}{"arrow\_right"});
   elm_object_part_content_set(btn, \textcolor{stringliteral}{"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, \textcolor{stringliteral}{"repeated"}, \_btn\_cursors\_move\_cb, &data);
   evas\_object\_smart\_callback\_add(btn, \textcolor{stringliteral}{"unpressed"}, \_btn\_cursors\_release\_cb,
                                  &data);

   icon = elm_icon_add(win);
   elm_icon_standard_set(icon, \textcolor{stringliteral}{"arrow\_down"});
   elm_object_part_content_set(btn, \textcolor{stringliteral}{"icon"}, icon);

   data.cursors.down = btn;

   elm_run();
   elm_shutdown();

   \textcolor{keywordflow}{return} 0;
\}
ELM_MAIN()
\end{DoxyCodeInclude}
 