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

\begin{DoxyCodeInclude}
\textcolor{comment}{//Compile with:}
\textcolor{comment}{//gcc -g layout\_example\_01.c -o layout\_example\_01 `pkg-config --cflags --libs elementary`}

\textcolor{preprocessor}{#include <Elementary.h>}

\textcolor{preprocessor}{#define TABLE "example/table"}
\textcolor{preprocessor}{}\textcolor{preprocessor}{#define BOX "example/box"}
\textcolor{preprocessor}{}\textcolor{preprocessor}{#define TITLE "example/title"}
\textcolor{preprocessor}{}\textcolor{preprocessor}{#define SWALLOW "example/custom"}
\textcolor{preprocessor}{}
\textcolor{keyword}{static} \textcolor{keywordtype}{int} \_box\_buttons = 0;

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_tbl\_btn\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *btn, \textcolor{keywordtype}{void} *event\_info)
\{
   Evas\_Object *layout = data;

   elm_layout_table_unpack(layout, TABLE, btn);
   evas\_object\_del(btn);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_box\_btn\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *btn, \textcolor{keywordtype}{void} *event\_info)
\{
   Evas\_Object *layout = data;
   Evas\_Object *item;
   \textcolor{keywordtype}{char} buf[30];

   snprintf(buf, \textcolor{keyword}{sizeof}(buf), \textcolor{stringliteral}{"Button %02d"}, \_box\_buttons++);

   item = elm_button_add(elm_object_parent_widget_get(layout));
   elm\_object\_text\_set(item, buf);
   evas\_object\_size\_hint\_weight\_set(item, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   evas\_object\_size\_hint\_align\_set(item, EVAS\_HINT\_FILL, EVAS\_HINT\_FILL);
   elm_layout_box_insert_before(layout, BOX, item, btn);
   evas\_object\_smart\_callback\_add(item, \textcolor{stringliteral}{"clicked"}, \_box\_btn\_cb, layout);
   evas\_object\_show(item);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_swallow\_btn\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *btn, \textcolor{keywordtype}{void} *event\_info)
\{
   Evas\_Object *layout = data;
   Evas\_Object *item;

   elm_layout_table_clear(layout, TABLE, EINA\_TRUE);
   elm_layout_box_remove_all(layout, BOX, EINA\_TRUE);
   item = elm_object_part_content_unset(layout, SWALLOW);
   evas\_object\_del(item);
\}

EAPI\_MAIN \textcolor{keywordtype}{int}
elm\_main(\textcolor{keywordtype}{int} argc, \textcolor{keywordtype}{char} **argv)
\{
   Evas\_Object *win, *icon, *icon2, *bt, *bt2, *layout;
   Evas\_Object *clk;
   Evas\_Object *item;
   \textcolor{keywordtype}{char} buf[PATH\_MAX];

   elm_app_info_set(elm\_main, \textcolor{stringliteral}{"elementary"}, \textcolor{stringliteral}{"examples/layout\_example.edj"});
   elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);

   win = elm_win_util_standard_add(\textcolor{stringliteral}{"layout"}, \textcolor{stringliteral}{"Layout"});
   elm_win_autodel_set(win, EINA\_TRUE);

   \textcolor{comment}{// Adding layout and filling it with widgets}
   layout = elm_layout_add(win);
   evas\_object\_size\_hint\_weight\_set(layout, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   elm_win_resize_object_add(win, layout);
   snprintf(buf, \textcolor{keyword}{sizeof}(buf), \textcolor{stringliteral}{"%s/examples/layout\_example.edj"}, 
      elm_app_data_dir_get());
   elm_layout_file_set(layout, buf, \textcolor{stringliteral}{"example/mylayout"});
   evas\_object\_show(layout);

   \textcolor{comment}{// Setting title}
   \textcolor{keyword}{const} \textcolor{keywordtype}{char} *title = elm_layout_data_get(layout, \textcolor{stringliteral}{"title"});
   \textcolor{keywordflow}{if} (title)
     \{
        elm_win_title_set(win, title);
        elm_object_part_text_set(layout, TITLE, title);
     \}

   \textcolor{comment}{// Add icon, clock and button to the table}
   icon = elm_icon_add(win);
   elm_icon_standard_set(icon, \textcolor{stringliteral}{"home"});
   evas\_object\_size\_hint\_weight\_set(icon, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   evas\_object\_size\_hint\_align\_set(icon, EVAS\_HINT\_FILL, EVAS\_HINT\_FILL);
   elm_layout_table_pack(layout, TABLE, icon, 0, 0, 1, 1);
   evas\_object\_show(icon);

   icon2 = elm_icon_add(win);
   elm_icon_standard_set(icon2, \textcolor{stringliteral}{"close"});
   evas\_object\_size\_hint\_weight\_set(icon2, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   evas\_object\_size\_hint\_align\_set(icon2, EVAS\_HINT\_FILL, EVAS\_HINT\_FILL);
   elm_layout_table_pack(layout, TABLE, icon2, 1, 0, 1, 1);
   evas\_object\_show(icon2);

   clk = elm_clock_add(win);
   evas\_object\_size\_hint\_weight\_set(clk, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   evas\_object\_size\_hint\_align\_set(clk, EVAS\_HINT\_FILL, EVAS\_HINT\_FILL);
   elm_layout_table_pack(layout, TABLE, clk, 2, 0, 1, 1);
   evas\_object\_show(clk);

   bt = elm_button_add(win);
   elm\_object\_text\_set(bt, \textcolor{stringliteral}{"Click me!"});
   evas\_object\_size\_hint\_weight\_set(bt, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   evas\_object\_size\_hint\_align\_set(bt, EVAS\_HINT\_FILL, EVAS\_HINT\_FILL);
   elm_layout_table_pack(layout, TABLE, bt, 0, 1, 3, 1);
   evas\_object\_smart\_callback\_add(bt, \textcolor{stringliteral}{"clicked"}, \_tbl\_btn\_cb, layout);
   evas\_object\_show(bt);

   item = elm_button_add(win);
   elm\_object\_text\_set(item, \textcolor{stringliteral}{"Position 0"});
   evas\_object\_size\_hint\_weight\_set(item, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   evas\_object\_size\_hint\_align\_set(item, EVAS\_HINT\_FILL, EVAS\_HINT\_FILL);
   elm_layout_box_insert_at(layout, BOX, item, 0);
   evas\_object\_smart\_callback\_add(item, \textcolor{stringliteral}{"clicked"}, \_box\_btn\_cb, layout);
   evas\_object\_show(item);

   item = elm_button_add(win);
   elm\_object\_text\_set(item, \textcolor{stringliteral}{"Prepended"});
   evas\_object\_size\_hint\_weight\_set(item, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   evas\_object\_size\_hint\_align\_set(item, EVAS\_HINT\_FILL, EVAS\_HINT\_FILL);
   elm_layout_box_prepend(layout, BOX, item);
   evas\_object\_smart\_callback\_add(item, \textcolor{stringliteral}{"clicked"}, \_box\_btn\_cb, layout);
   evas\_object\_show(item);

   bt2 = elm_button_add(win);
   elm\_object\_text\_set(bt2, \textcolor{stringliteral}{"Delete All"});
   elm_object_part_content_set(layout, SWALLOW, bt2);
   evas\_object\_smart\_callback\_add(bt2, \textcolor{stringliteral}{"clicked"}, \_swallow\_btn\_cb, layout);

   evas\_object\_resize(win, 320, 320);
   evas\_object\_show(win);

   elm_run();
   elm_shutdown();

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