forked from enlightenment/efl
New simpler button example.
Patch by: João Paulo Fernandes Ventura<ventura@profusion.mobi> SVN revision: 69508
This commit is contained in:
parent
80a39ad311
commit
627ba403ac
|
@ -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
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* gcc -o button_example_00 button_example_00.c `pkg-config --cflags --libs elementary`
|
||||
*/
|
||||
#include <Elementary.h>
|
||||
#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();
|
Loading…
Reference in New Issue