Wiki pages basic_tutorial created : button, label, list + images + code c

Signed-off-by: Clément Bénier <clement.benier@openwide.fr>
Signed-off-by: Pierre Le Magourou <pierre.lemagourou@openwide.fr>
Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
This commit is contained in:
Clément Bénier 2015-06-12 10:18:18 +02:00 committed by Cedric BAIL
parent a76e0c907c
commit 960d5fe3ff
11 changed files with 723 additions and 0 deletions

BIN
media/basic_button.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

BIN
media/basic_label.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

BIN
media/basic_list.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

View File

@ -0,0 +1,142 @@
#include <Elementary.h>
//Click Callback: print Clicked
static void
_button_click_cb(void *data, Evas_Object *button, void *event_info)
{
elm_object_text_set(button, "Clicked!");
}
//Press callback: print Pressed
static void
_button_press_cb(void * data, Evas_Object *button, void *event_info)
{
elm_object_text_set(button, "Pressed!");
}
//Unpress callback: print Unpressed
static void
_button_unpress_cb(void *data, Evas_Object *button, void *event_info)
{
elm_object_text_set(button, "Unpressed!");
}
//Repeat callback: print number of times callback is called
static void
_button_repeat_cb(void *data, Evas_Object *button, void *event_info)
{
static int count = 0;
char buffer[16];
snprintf(buffer, sizeof(buffer), "Repeat %d", count++);
//print the number of time callback was called
elm_object_text_set(button, buffer);
}
//Unpress callback: print Focused
static void
_button_focused_cb(void * data, Evas_Object *button, void *event_info)
{
elm_object_text_set(button, "Focused");
}
//Unpress callback: print Unfocused
static void
_button_unfocused_cb(void * data, Evas_Object *button, void *event_info)
{
elm_object_text_set(button, "Unfocused");
}
EAPI_MAIN int
elm_main(int argc, char **argv)
{
Evas_Object *win;
elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
win = elm_win_util_standard_add("Main", "Hello, World!");
elm_win_autodel_set(win, EINA_TRUE);
//win 400x400
evas_object_resize(win, 400, 400);
/*basic tutorial code*/
//basic text button
Evas_Object *button_text;
button_text = elm_button_add(win);
elm_object_text_set(button_text,"Clik me");
//how a container object should resize a given child within its area
evas_object_size_hint_weight_set(button_text, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
//how to align an object
evas_object_size_hint_align_set(button_text, EVAS_HINT_FILL, 0.5);
evas_object_resize(button_text, 100, 30);
evas_object_show(button_text);
//Basic icon button
Evas_Object *button_icon, *icon;
button_icon = elm_button_add(win);
icon = elm_icon_add(win);
//set the image file and the button as an icon
elm_image_file_set(icon, "icon.png", NULL);
elm_object_part_content_set(button_icon, "icon", icon);
evas_object_size_hint_weight_set(button_icon, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(button_icon, EVAS_HINT_FILL, 0.5);
evas_object_resize(button_icon, 100, 30);
evas_object_move(button_icon, 110, 0);
evas_object_show(button_icon);
//Icon and text button
Evas_Object *button_icon_text, *icon2;
button_icon_text = elm_button_add(win);
icon2 = elm_icon_add(win);
elm_image_file_set(icon2, "icon.png", NULL);
elm_object_part_content_set(button_icon_text, "icon", icon2);
elm_object_text_set(button_icon_text, "Press me");
evas_object_size_hint_weight_set(button_icon_text, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(button_icon_text, EVAS_HINT_FILL, 0.5);
evas_object_resize(button_icon_text, 100, 30);
evas_object_move(button_icon_text, 220, 0);
evas_object_show(button_icon_text);
//Clik event
evas_object_smart_callback_add(button_text, "clicked", _button_click_cb, NULL);
//Press event
evas_object_smart_callback_add(button_icon, "pressed", _button_press_cb, NULL);
//Unpress event
evas_object_smart_callback_add(button_icon, "unpressed", _button_unpress_cb, NULL);
//Get whether the autorepeat feature is enabled.
elm_button_autorepeat_set(button_icon_text, EINA_TRUE);
//Set the initial timeout before the autorepeat event is generated.
elm_button_autorepeat_initial_timeout_set(button_icon_text, 1.0);
//gap between two callbacks
elm_button_autorepeat_gap_timeout_set(button_icon_text, 0.5);
//"repeated": the user pressed the button without releasing it.
evas_object_smart_callback_add(button_icon_text, "repeated", _button_repeat_cb, NULL);
//Focused/unfocused event
Evas_Object *button;
button = elm_button_add(win);
elm_object_text_set(button, "button");
evas_object_resize(button, 100, 30);
evas_object_move(button, 0, 40);
evas_object_show(button);
evas_object_smart_callback_add(button, "focused", _button_focused_cb, NULL);
evas_object_smart_callback_add(button, "unfocused", _button_unfocused_cb, NULL);
evas_object_show(win);
elm_run();
return 0;
}
ELM_MAIN()

View File

@ -0,0 +1,47 @@
#include <Elementary.h>
EAPI_MAIN int
elm_main(int argc, char **argv)
{
Evas_Object *win;
elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
win = elm_win_util_standard_add("Main", "Hello, World!");
elm_win_autodel_set(win, EINA_TRUE);
//win 400x400
evas_object_resize(win, 400, 400);
/*basic tutorial code*/
//text_label
Evas_Object *label_text;
label_text = elm_label_add(win);
elm_object_text_set(label_text,"My label");
evas_object_color_set(label_text, 0, 0, 255, 255);
evas_object_resize(label_text, 90, 30);
evas_object_show(label_text);
//sliding text
Evas_Object *label_slide;
label_slide = elm_label_add(win);
elm_object_text_set(label_slide, "<b>Some long bold text for our label_slide, that is long but</b>"
"<b>not too long.</b>");
elm_object_style_set(label_slide,"slide_bounce");
elm_label_slide_duration_set(label_slide, 3);
elm_label_slide_mode_set(label_slide, ELM_LABEL_SLIDE_MODE_ALWAYS);
elm_label_slide_go(label_slide);
evas_object_resize(label_slide, 200, 15);
evas_object_move(label_slide,0,40);
evas_object_show(label_slide);
evas_object_show(win);
elm_run();
return 0;
}
ELM_MAIN()

View File

@ -0,0 +1,66 @@
#include <Elementary.h>
static void
_prepend_itembutton_cb(void *data, Evas_Object *obj, void *event_info)
{
Elm_Object_Item *list_it;
Evas_Object *li = obj;
Elm_Object_Item *selected=elm_list_selected_item_get(li);
if(selected == (Elm_Object_Item*)data)
{
static int counter=0;
char label[32];
snprintf(label, sizeof(label), "Item %i", counter++);
list_it = elm_list_item_prepend(li, label, NULL, NULL, NULL, NULL);
elm_list_go(li);
if (!list_it) printf("Error adding item\n");
}
}
EAPI_MAIN int
elm_main(int argc, char **argv)
{
Evas_Object *win, *label, *label2;
elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
win = elm_win_util_standard_add("Main", "Hello, World!");
elm_win_autodel_set(win, EINA_TRUE);
evas_object_resize(win, 400, 400);
Evas_Object *list, *icon, *button;
list = elm_list_add(win);
/*elm_list_horizontal_set(list, EINA_TRUE);*/ //uncoment to get horizontal
//size giving scrollbar
evas_object_resize(list, 320, 300);
elm_list_mode_set(list, ELM_LIST_LIMIT);
// elm_scroller_bounce_set(list, EINA_TRUE, EINA_TRUE);
//first item: text
elm_list_item_append(list, "Text item", NULL, NULL, NULL, NULL);
//second item: icon
icon = elm_icon_add(list);
elm_icon_standard_set(icon, "chat");
elm_list_item_append(list, "Icon item", icon, NULL, NULL, NULL);
//third item: button
button = elm_button_add(list);
elm_object_text_set(button, "Button");
Elm_Object_Item *itembutton=elm_list_item_append(list, "Button item", NULL, button, NULL, NULL);
elm_list_go(list);
evas_object_show(list);
evas_object_smart_callback_add(list, "selected", _prepend_itembutton_cb, itembutton);
evas_object_show(win);
elm_run();
return 0;
}
ELM_MAIN()

View File

@ -34,6 +34,10 @@ Go check the current available version of EFL on each distro/platform:
* [[debugging/apps_efl_debugging|EFL application debugging]]
* [[debugging/report_bugs|Report bugs on Phabricator]]
=== Tutorials ===
* [[tutorial/basic_tutorial|Basic Tutorial]]
----
==== API Documentation ====

View File

@ -0,0 +1,194 @@
==== Button ====
=== Button styles ===
//**__Basic text button__**//
As seen in [[docs/efl/start|Get started with EFL]] tutorial, a text-only
button is created as follow :
<code c>
//basic text button
Evas_Object *button_text;
button_text = elm_button_add(win);
elm_object_text_set(button_text,"Clik me");
//how a container object should resize a given child within its area
evas_object_size_hint_weight_set(button_text, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
//how to align an object
evas_object_size_hint_align_set(button_text, EVAS_HINT_FILL, 0.5);
//100x30 px button
evas_object_resize(button_text, 100, 30);
evas_object_show(button_text);
</code>
//**__Basic icon button__**//
Instead of a button having only some text, you can also opt to having an
icon-only button.
<code c>
//Basic icon button
Evas_Object *button_icon, *icon;
button_icon = elm_button_add(win);
icon = elm_icon_add(win);
//set the image file and the button as an icon
elm_image_file_set(icon, "icon.png", NULL);
elm_object_part_content_set(button_icon, "icon", icon);
evas_object_size_hint_weight_set(button_icon, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(button_icon, EVAS_HINT_FILL, 0.5);
//100x30 px button
evas_object_resize(button_icon, 100, 30);
evas_object_move(button_icon, 110, 0);
evas_object_show(button_icon);
</code>
The function ''elm_object_part_content_set(button_icon, "icon",icon)'' sets
the content on part on a given container widget. All widgets
deriving from the Elementary Container Class may match. This sets new content
to a given part. If any object was already set as a content object, it will be
deleted.
//**__Icon and text button__**//
You can also have buttons holding both an icon and a label.
<code c>
//Icon and text button
Evas_Object *button_icon_text, *icon2;
button_icon_text = elm_button_add(win);
icon2 = elm_icon_add(win);
elm_image_file_set(icon2, "icon.png", NULL);
elm_object_part_content_set(button_icon_text, "icon", icon2);
elm_object_text_set(button_icon_text, "Press me");
evas_object_size_hint_weight_set(button_icon_text, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(button_icon_text, EVAS_HINT_FILL, 0.5);
evas_object_resize(button_icon_text, 100, 30);
evas_object_move(button_icon_text, 220, 0);
evas_object_show(button_icon_text);
</code>
//**__Disabled button__**//
If you want to disable your button but still visible:
<code c>
elm_object_disabled_set(button, EINA_TRUE);
</code>
== Callbacks ==
Elementary buttons respond to user interactions thanks to several events.
//**__Click event__**//
The “click” event is the most basic and well-known one. The following code
snippet will change the text of a button upon a click event: a press followed
by an unpress.
<code c>
//Click Callback: print Clicked
static void
_button_click_cb(void *data, Evas_Object *button, void *event_info){
elm_object_text_set(button, "Clicked!");
}
evas_object_smart_callback_add(button_text, "clicked", button_click_cb, NULL);
</code>
//**__Press/unpress events __**//
The button can also respond to the press and unpress events instead of the
whole click.
<code c>
//Press callback: print Pressed
static void
_button_press_cb(void * data, Evas_Object *button, void *event_info){
elm_object_text_set(button, "Pressed!");
}
//Unpress callback: print Unpressed
static void
_button_unpress_cb(void *data, Evas_Object *button, void *event_info){
elm_object_text_set(button, "Unpressed!");
}
evas_object_smart_callback_add(button_icon, "pressed", _button_press_cb, NULL);
evas_object_smart_callback_add(button_icon, "unpressed", _button_unpress_cb, NULL);
</code>
//**__Repeated events__**//
The button can also receive several events in case it is being held by the
user. Timings such as the initial timeout and the repeat interval can be set.
In this example, the initial timeout is set to one second, and the repeat
interval to half a second.
<code c>
static void
_button_repeat_cb(void *data, Evas_Object *button, void *event_info){
static int count = 0;
char buffer[16];
snprintf(buffer, sizeof(buffer), "Repeat %d", count++);
//print the number of time callback was called
elm_object_text_set(button, buffer);
}
//Get whether the autorepeat feature is enabled.
elm_button_autorepeat_set(button_icon_text, EINA_TRUE);
//Set the initial timeout before the autorepeat event is generated.
elm_button_autorepeat_initial_timeout_set(button_icon_text, 1.0);
//gap between two callbacks
elm_button_autorepeat_gap_timeout_set(button_icon_text, 0.5);
//"repeated": the user pressed the button without releasing it.
evas_object_smart_callback_add(button_icon_text, "repeated", _button_repeat_cb, NULL);
</code>
//**__Focused/unfocused events__**//
The event Focused is equivalent to click indeed callback is called when you
are "focused" on the button. So, you are unfocused when you are not focused on
the first button. For having two buttons, a box container will be needed.
The button can also receive event from another button in case it is being
focused when you click on it and unfocused when you press and unpress another
one.
<code c>
static void
_button_focused_cb(void * data, Evas_Object *button, void *event_info){
elm_object_text_set(button, "Focused");
}
static void
_button_unfocused_cb(void * data, Evas_Object *button, void *event_info){
elm_object_text_set(button, "Unfocused");
}
//Focused/unfocused event
Evas_Object *button;
button = elm_button_add(win);
elm_object_text_set(button, "button");
evas_object_resize(button, 100, 30);
evas_object_move(button, 0, 40);
evas_object_show(button);
evas_object_smart_callback_add(button, "focused", _button_focused_cb, NULL);
evas_object_smart_callback_add(button, "unfocused", _button_unfocused_cb, NULL);
</code>
\\
**//The whole code://** {{code_c/tutorial/basic/button.c}}
==== Next Part ====
//**__[[/tutorial/basic/label]]__**//

View File

@ -0,0 +1,75 @@
==== Simple Text ====
//**__Basic text__**//
Creating a label object, a widget to display text, with simple html-like
markup:
<code c>
//text_label
Evas_Object *label;
label_text = elm_label_add(win);
elm_object_text_set(label_text,"My label");
evas_object_resize(label_text, 90, 0);
evas_object_show(label_text);
</code>
//**__Sliding text__**//
If your text is too long, you can have it set to slide. The duration of the
slide is to be set: it is set to five seconds in the following example. You
can also have several styles:
- default - No animation
- marker - Centers the text in the label and makes it bold by default
- slide_long - The entire text appears from the right of the screen and slides until it disappears in the left of the screen(reappearing on the right again).
- slide_short - The text appears in the left of the label and slides to the right to show the overflow. When all of the text has been shown the position is reset.
- slide_bounce - The text appears in the left of the label and slides to the right to show the overflow. When all of the text has been shown the animation reverses, moving the text to the left.
<code c>
//sliding text
Evas_Object *label_slide;
label_slide = elm_label_add(win);
elm_object_text_set(label_slide, "Some long text for our label_slide, that is long but"
"not too long.");
elm_object_style_set(label_slide,"slide_bounce");
elm_label_slide_duration_set(label_slide, 3);
elm_label_slide_mode_set(label_slide, ELM_LABEL_SLIDE_MODE_ALWAYS);
elm_label_slide_go(label_slide);
evas_object_resize(label_slide, 200, 15);
evas_object_move(label_slide,0,40);
evas_object_show(label_slide);
</code>
If needed, you can respond to end of a slide thanks to the slide,end event.
//**__Marker text__**//
A marker is a text that is centered and bold by default. As the default color
is white, we will also set a color, blue in this example.
<code c>
elm_object_style_set(label, "marker");
evas_object_color_set(label, 0, 0, 255, 255);
</code>
//**__Styling the text__**//
You can apply basic styles to the text. If, for instance, you would like to
have a bold text, you can do as follows.
<code c>
elm_object_text_set(label, "<b>This text is bold.</b>");
</code>
**//The whole code://** {{/tutorial/basic/label.c}}
==== Next Part ====
//**__[[/tutorial/basic/list| Simple List Tutorial]]__**//

View File

@ -0,0 +1,124 @@
=== Simple List ===
//**__Basic list__**//
A list is a scrollable container whose children can be selected.
<code c>
Evas_Object *list, *icon, *button;
list = elm_list_add(win);
//size giving scrollbar
evas_object_resize(list, 320, 70);
//first item: text
Elm_Object_Item *item_text = elm_list_item_append(list, "Text item", NULL, NULL, NULL, NULL);
//second item: icon
icon = elm_icon_add(list);
elm_icon_standard_set(icon, "chat");
Elm_Object_Item *item_icon = elm_list_item_append(list, "Icon item", icon, NULL, NULL, NULL);
//third item: button
button = elm_button_add(list);
elm_object_text_set(button, "Button");
Elm_Object_Item *item_button = elm_list_item_append(list, "Button item", NULL, button, NULL, NULL);
elm_list_go(list);
evas_object_show(list);
</code>
Any Evas Object can be added as an icon, either at the beginning (third
parameter) or the end (fourth parameter).
//**__List mode__**//
There are several modes for the list item dimensions:
* //**ELM_LIST_COMPRESS**// The list won't set any of its size hints to inform how a possible container should resize it. Then, if it's not created as a "resize object", it might end with zeroed dimensions. The list will respect the container's geometry and, if any of its items won't fit into its transverse axis, one won't be able to scroll it in that direction.
* //**ELM_LIST_SCROLL**// Default value. This is the same as ELM_LIST_COMPRESS, with the exception that if any of its items won't fit into its transverse axis, one will be able to scroll it in that direction.
* //**ELM_LIST_LIMIT**// Sets a minimum size hint on the list object, so that containers may respect it (and resize itself to fit the child properly). More specifically, a minimum size hint will be set for its transverse axis, so that the largest item in that direction fits well. This is naturally bound by the list object's maximum size hints, set externally.
* //**ELM_LIST_EXPAND**// Besides setting a minimum size on the transverse axis, just like on ELM_LIST_LIMIT, the list will set a minimum size on the longitudinal axis, trying to reserve space to all its children to be visible at a time. This is naturally bound by the list object's maximum size hints, set externally.
* //**ELM_LIST_LAST**// Indicates error if returned by elm_list_mode_get()
<code c>
elm_list_mode_set(list, ELM_LIST_COMPRESS);
</code>
//**__Scroller policy__**//
Several effects can be shown on a list.
For instance, the scroller can set to bounce at the end on either direction.
<code c>
elm_scroller_bounce_set(list, EINA_TRUE, EINA_TRUE);
</code>
The second argument is for the horizontal axis, the third one for the vertical
axis.
You can also control whether to display scrollbars.
<code c>
elm_scroller_policy_set(list, ELM_SCROLLER_POLICY_AUTO,ELM_SCOLLER_POLICY_ON);
</code>
As for the bounce preference, the second argument is for the horizontal axis,
the third one for the vertical axis:
* //**ELM_SCROLLER_POLICY_OFF**// will always hide the scrollbar
* //**ELM_SCROLLER_POLICY_ON**// will always show the scrollbar
* //**ELM_SCROLLER_POLICY_AUTO**// means that the scrollbar will be only shown when needed, and hidden otherwise.
//**__Events__**//
A list can respond to several events:
* //**activated**// - The user has double-clicked or pressed (enter|return|spacebar) on an item. The event_info parameter is the item that was activated.
* //**clicked,double**// - The user has double-clicked an item. The event_info parameter is the item that was double-clicked.
* //**clicked,right**// - The user has right-clicked an item. The event_info parameter is the item that was right-clicked. (since 1.13)
* //**selected**// - when the user selected an item
* //**unselected**// - when the user unselected an item
* //**longpressed**// - an item in the list is long-pressed
* //**edge,top**// - the list is scrolled until the top edge
* //**edge,bottom**// - the list is scrolled until the bottom edge
* //**edge,left**// - the list is scrolled until the left edge
* //**edge,right**// - the list is scrolled until the right edge
* //**highlighted**// - an item in the list is highlighted. This is called when the user presses an item or keyboard selection is done so the item is physically highlighted. The event_info parameter is the item that was highlighted.
* //**unhighlighted**// - an item in the list is unhighlighted. This is called when the user releases an item or keyboard selection is moved so the item is physically unhighlighted. The event_info parameter is the item that was unhighlighted.
* //**language,changed**// - the program's language changed
* //**focused**// - When the list has received focus. (since 1.8)
* //**unfocused**// - When the list has lost focus. (since 1.8)
* //**item,focused**// - When the list item has received focus. (since 1.10)
* //**item,unfocused**// - When the list item has lost focus. (since 1.10)
//**__Selected event__**//
The selected event is received when the user selected an item, below the
callback add an new item only if it is the button item which is selected.
<code c>
static void
_prepend_itembutton_cb(void *data, Evas_Object *obj, void *event_info)
{
Elm_Object_Item *list_it;
Evas_Object *li = obj;
Elm_Object_Item *selected=elm_list_selected_item_get(li);
if(selected == (Elm_Object_Item*)data)
{
static int counter=0;
char label[32];
snprintf(label, sizeof(label), "Item %i", counter++);
list_it = elm_list_item_prepend(li, label, NULL, NULL, NULL, NULL);
elm_list_go(li);
if (!list_it)
printf("Error adding item\n");
}
}
evas_object_smart_callback_add(list, "selected", _prepend_itembutton_cb, item_button);
</code>
**//The whole code://** {{code_c/tutorial/basic/list.c}}

View File

@ -0,0 +1,71 @@
~~Title: Basic Tutorial~~
==== Basic Tutorial ====
These basic tutorials describe the basics of widget interactions.
== Prerequisite ==
* Do a helloworld program: [[docs/efl/start|Get started with EFL]].
* Work with this example.
<code c>
#include <Elementary.h>
EAPI_MAIN int
elm_main(int argc, char **argv)
{
Evas_Object *win;
elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
win = elm_win_util_standard_add("Main", "Hello, World!");
elm_win_autodel_set(win, EINA_TRUE);
//win 400x400
evas_object_resize(win, 400, 400);
/*basic tutorial code*/
evas_object_show(win);
elm_run();
return 0;
}
ELM_MAIN()
</code>
==== Basic Button ====
**__[[/tutorial/basic/button|Basic Button Tutorial]]:__**
//{{code_c/tutorial/basic/button.c}}//[[/tutorial/basic/button|{{ :basic_button.png?direct|button}}]]
\\
\\
\\
\\
\\
\\
\\
\\
\\
\\
\\
\\
\\
\\
\\
\\
------
==== Basic Label ====
**__[[/tutorial/basic/label|Simple Text Tutorial]]:__**//
{{code_c/tutorial/basic/label.c}}//[[/tutorial/basic/label|{{ :basic_label.png?direct|label}}]]
\\
\\
\\
\\
\\
\\
\\
\\
------
==== Basic List ====
**__[[tutorial/basic/list|Simple List Tutorial]]:__**//
{{code_c/tutorial/basic/list.c}}//[[/tutorial/basic/list|{{ :basic_list.png?direct|list}}]]