From 627ba403ac869e44b13939d3733b3ce247ecd598 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Paulo=20Fernandes=20Ventura?= Date: Mon, 19 Mar 2012 12:58:12 +0000 Subject: [PATCH] New simpler button example. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Patch by: João Paulo Fernandes Ventura SVN revision: 69508 --- legacy/elementary/doc/examples.dox | 57 +++++++++++++++++++ .../src/examples/button_example_00.c | 54 ++++++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 legacy/elementary/src/examples/button_example_00.c diff --git a/legacy/elementary/doc/examples.dox b/legacy/elementary/doc/examples.dox index 0af84f52ea..7b4e625b7e 100644 --- a/legacy/elementary/doc/examples.dox +++ b/legacy/elementary/doc/examples.dox @@ -810,6 +810,63 @@ */ /** + * @page button_example_00 Button - Hello, Button! + * + * @dontinclude button_example_00.c + * + * Keeping the tradition, this is a simple "Hello, World" button example. We + * will show how to create a button and associate and action to be performed + * when you click on it. + * + * In the end, we'll be presented with something that looks like this: + * + * @image html screenshots/button_00.png + * @image latex screenshots/button_00.eps width=\textwidth + * + * The full code of the example is @ref button_example_00.c "here" and we + * will follow here with a rundown of it. + * + * + * There is only one button on the interface which performs a basic action: + * close the application. This behavior is described by on_click() function, + * that interrupt the program invoking elm_exit(). + * @skip static void + * @until } + * + * + * On the main() function, we set the basic characteristics of the user + * interface. First we use the Elementary library to create a window and + * set its policies (such as close when the user click on the window close + * icon). + * + * @skip elm_win_add + * @until elm_policy_set + * + * In order to turn it visible on the WM (Window Manager), we also have to + * associate it to a canvas through Evas library, and set its dimensions. + * + * @skip evas_object_resize + * @until evas_object_show(win) + * + * Then we create a background associated to the window, define its dimensions, + * and turn it visible on the canvas. + * @skip elm_bg_add + * @until evas_object_show(bg) + * + * + * Finally we use Elementary to create a button and Evas to set its + * proprieties. Here we have not only to give the button dimensions, but also + * its coordinates and the action to be performed on the click event. + * @skip elm_button_add + * @until evas_object_show(btn) + * + * + * And we are done. + * + * @example button_example_00.c + */ + +/** * @page button_example_01 Button - Complete example * * @dontinclude button_example_01.c diff --git a/legacy/elementary/src/examples/button_example_00.c b/legacy/elementary/src/examples/button_example_00.c new file mode 100644 index 0000000000..cc69c2813f --- /dev/null +++ b/legacy/elementary/src/examples/button_example_00.c @@ -0,0 +1,54 @@ +/* + * gcc -o button_example_00 button_example_00.c `pkg-config --cflags --libs elementary` + */ +#include +#ifdef HAVE_CONFIG_H +#include "elementary_config.h" +#else +#define __UNUSED__ +#endif + +static void +on_click(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__) +{ + elm_exit(); +} + +int +elm_main(int argc __UNUSED__, char **argv __UNUSED__) +{ + Evas_Object *win = NULL; + Evas_Object *bg = NULL; + Evas_Object *btn = NULL; + + /* Create an win, associate it with a canvas and */ + /* turn it visible on WM (Window Manager). */ + win = elm_win_add(NULL, "Greetings", ELM_WIN_BASIC); + elm_win_title_set(win, "Hello, World!"); + elm_win_autodel_set(win, EINA_TRUE); + elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED); + evas_object_resize(win, 240, 60); + evas_object_show(win); + + /* Create a bg, associate it to an win */ + /* and turn it visible on WM. */ + bg = elm_bg_add(win); + evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + elm_win_resize_object_add(win, bg); + evas_object_show(bg); + + /* Create a btn, associate to a function, associate */ + /* to win, give a dimension and position. */ + btn = elm_button_add(win); + elm_object_text_set(btn, "Good-Bye, World!"); + evas_object_smart_callback_add(btn, "clicked", on_click, NULL); + evas_object_resize(btn, 120, 30); + evas_object_move(btn, 60, 15); + evas_object_show(btn); + + elm_run(); + + return 0; +} + +ELM_MAIN();