2 * @page Examples Examples
4 * Here is a page with Elementary examples.
6 * @ref bg_01_example_page
8 * @ref bg_02_example_page
10 * @ref bg_03_example_page
12 * @ref actionslider_example_page
14 * @ref elm_animator_example_page_01
16 * @ref transit_example_01_explained
18 * @ref transit_example_02_explained
22 * @page bg_01_example_page elm_bg - Plain color background.
23 * @dontinclude bg_example_01.c
25 * The full code for this example can be found at @ref bg_example_01_c,
26 * in the function @c test_bg_plain. It's part of the @c elementar_test
27 * suite, and thus has the code for the three examples referenced by this
30 * This first example just sets a default background with a plain color. The
31 * first part consists of creating an Elementary window. It's the common
32 * piece of code that you'll see everywhere in Elementary: @skip elm_main
35 * Now we really create our background object, using the window object as
40 * Then we set the size hints of the background object so that it will use
41 * all space available for it, and then add it as a resize object to the
42 * window, making it visible in the end:
44 * @skip size_hint_weight_set
45 * @until resize_object_add
47 * See @ref evas_object_size_hint_weight_set and elm_win_resize_object_add()
48 * for more detailed info about these functions.
50 * The end of the example is quite simple, just setting the minimum and
51 * maximum size of the background, so the Elementary window knows that it
52 * has to have at least the minimum size. The background also won't scale to
53 * a size above its maximum. Then we resize the window and show it in the
56 * @skip set size hints
59 * And here we finish our very simple background object usage example.
63 * @page bg_02_example_page elm_bg - Image background.
64 * @dontinclude bg_example_02.c
66 * The full code for this example can be found at @ref bg_example_02_c,
67 * in the function @c test_bg_image. It's part of the @c elementar_test
68 * suite, and thus has the code for the three examples referenced by this
71 * This is the second example, and shows how to use the Elementary
72 * background object to set an image as background of your application.
74 * We start this example exactly in the same way as the previous one, even
75 * when creating the background object:
80 * Now it's the different part.
82 * Our background will have an image, that will be displayed over the
83 * background color. Before loading the image, we set the load size of the
84 * image. The load size is a hint about the size that we want the image
85 * displayed in the screen. It's not the exact size that the image will have,
86 * but usually a bit bigger. The background object can still be scaled to a
87 * size bigger than the one set here. Setting the image load size to
88 * something smaller than its real size will reduce the memory used to keep
89 * the pixmap representation of the image, and the time to load it. Here we
90 * set the load size to 20x20 pixels, but the image is loaded with a size
91 * bigger than that (since it's just a hint):
93 * @skipline load_size_set
95 * And set our background image to be centered, instead of stretched or
96 * scaled, so the effect of the elm_bg_load_size_set() can be easily
99 * @skipline option_set
101 * We need a filename to set, so we get one from the previous installed
102 * images in the @c PACKAGE_DATA_DIR, and write its full path to a buffer.
103 * Then we use this buffer to set the filename in the background object:
108 * Notice that the third argument of the elm_bg_file_set() function is @c
109 * NULL, since we are setting an image to this background. This function
110 * also supports setting an edje group as background, in which case the @c
111 * group parameter wouldn't be @c NULL, but be the name of the group
114 * Finally, we can set the size hints, add the background as a resize
115 * object, and resize the window, exactly the same thing we do in the @ref
116 * bg_01_example_page example:
121 * And this is the end of this example.
123 * This example will look like this:
124 * @image html screenshots/bg_01.png
125 * @image latex screenshots/bg_01.eps
129 * @page bg_03_example_page elm_bg - Background properties.
130 * @dontinclude bg_example_03.c
132 * The full code for this example can be found at @ref bg_example_03_c, in the
133 * function @c test_bg_options, with the callbacks @c _cb_overlay_changed, @c
134 * _cb_color_changed and @c _cb_radio_changed defined in the beginning of the
135 * file. It's part of the @c elementar_test suite, and thus has the code for
136 * the three examples referenced by this documentation.
138 * This example will show the properties available for the background object,
139 * and will use of some more widgets to set them.
141 * In order to do this, we will set some callbacks for these widgets. The
142 * first is for the radio buttons that will be used to choose the option
143 * passed as argument to elm_bg_option_set():
145 * @skip _cb_radio_changed
148 * The next callback will be used when setting the overlay (using
149 * elm_bg_overlay_set()):
151 * @skip _cb_overlay_changed
155 * And the last one, used to set the color (with elm_bg_color_set()):
157 * @skip _cb_color_changed
160 * We will get back to what these functions do soon. If you want to know more
161 * about how to set these callbacks and what these widgets are, look for:
162 * @li elm_radio_add()
163 * @li elm_check_add()
164 * @li elm_spinner_add()
166 * Now going to the main function, @c test_bg_options, we have the common
167 * code with the other examples:
172 * We add a plain background to this window, so it will have the default
173 * background color behind everything:
175 * @skip bg = elm_bg_add
176 * @until evas_object_show(bg)
178 * Then we add a vertical box (elm_box_add()) that will hold the background
179 * object that we are going to play with, as well as a horizontal box that
183 * @until evas_object_show
185 * Now we add the background object that is going to be of use for our
186 * example. It is an image background, as used in @ref bg_02_example_page ,
187 * so the code should be familiar:
190 * @until evas_object_show
192 * Notice the call to elm_box_pack_end(): it will pack the background object
193 * in the end of the Elementary box declared above. Just refer to that
194 * documentation for more info.
196 * Since this Elementary background is already an image background, we are
197 * going to play with its other properties. We will change its option
198 * (CENTER, SCALE, STRETCH, TILE), its color (RGB), and add an overlay to it.
199 * For all of these properties, we are going to add widgets that will
202 * First, lets add the horizontal box that will hold these widgets:
206 * For now, just consider this @c hbox as a rectangle that will contain the
207 * widgets, and will distribute them horizontally inside its content. Then we
208 * add radio buttons that will allow us to choose the property to use with
212 * @until evas_object_show
214 * Again, I won't give details about the use of these widgets, just look for
215 * their documentation if necessary. It's enough to know for now that we are
216 * packing them in the @c hbox, setting a label for them, and the most
217 * important parts: setting its value to @c ELM_BG_OPTION_CENTER and its
218 * callback to @c _cb_radio_changed (the function defined in the beginning of
219 * this example). We do this for the next 3 radio buttons added after this
220 * one, each of them with a different value.
222 * Now taking a look at the code of the callback @c _cb_radio_changed again,
223 * it will call elm_bg_option_set() with the value set from the checked radio
224 * button, thus setting the option for this background. The background is
225 * passed as argument to the @p data parameter of this callback, and is
226 * referenced here as @c o_bg.
228 * Later we set the default value for this radio button:
230 * @skipline elm_radio_value_set
232 * Then we add a checkbox for the elm_bg_overlay_set() function:
235 * @until evas_object_show
237 * Now look at the code of the @c _cb_overlay_changed again. If the checkbox
238 * state is checked, an overlay will be added to the background. It's done by
239 * creating an Edje object, and setting it with elm_bg_overlay_set() to the
240 * background object. For information about what are and how to set Edje
241 * object, look at the Edje documentation.
243 * Finally we add a spinner object (elm_spinner_add()) to be used to select
244 * the color of our background. In its callback it's possible to see the call
245 * to elm_bg_color_set(), which will change the color of this background.
246 * This color is used by the background to fill areas where the image doesn't
247 * cover (in this case, where we have an image background). The spinner is
248 * also packed into the @c hbox :
250 * @skip elm_spinner_add
251 * @until evas_object_show
253 * Then we just have to pack the @c hbox inside the @c box, set some size
254 * hints, and show our window:
259 * Now to see this code in action, open elementary_test, and go to the "Bg
260 * Options" test. It should demonstrate what was implemented here.
264 * @page actionslider_example_page Actionslider usage
265 * @dontinclude actionslider_example_01.c
267 * For this example we are going to assume knowledge of evas smart callbacks
268 * and some basic evas object functions. Elementary is not meant to be used
269 * without evas, if you're not yet familiar with evas it probably is worth
272 * And now to the example, when using Elementary we start by including
276 * Next we define some callbacks, they all share the same signature because
277 * they are all to be used with evas_object_smart_callback_add().
278 * The first one just prints the selected label(in two different ways):
281 * This next callback is a little more interesting, it makes the selected
282 * label magnetic(except if it's the center label):
285 * This callback enables or disables the magnetic propertty of the center
289 * And finally a callback to stop the main loop when the window is closed:
292 * To be able to create our actionsliders we need to do some setup, but this
293 * isn't really relevant here, so if you want to know about that go @ref
296 * With all that boring stuff out of the way we can proceed to creating some
298 * All actionsliders are created the same way:
299 * @skipline actionslider_add
300 * Next we must choose where the indicator starts, and for this one we choose
301 * the right, and set the right as magnetic:
302 * @skipline indicator_pos_set
303 * @until magnet_pos_set
305 * We then set the labels for the left and right, passing NULL as an argument
306 * to any of the labels makes that position have no label.
309 * Furthermore we mark both left and right as enabled positions, if we didn't
310 * do this all three positions would be enabled:
313 * Having the the enabled positions we now add a smart callback to change
314 * which position is magnetic, so that only the last selected position is
318 * And finally we set our printing callback and show the actionslider:
322 * For our next actionslider we are going to do much as we did for the
323 * previous except we are going to have the center as the magnet(and not
325 * @skipline actionslider_add
326 * @skipline indicator_pos_set
329 * And another actionslider, in this one the indicator starts on the left.
330 * It has labels only in the center and right, and both bositions are
331 * magnetic. Because the left doesn't have a label and is not magnetic once
332 * the indicator leaves it can't return:
333 * @skipline actionslider_add
334 * @skipline indicator_pos_set
336 * @note The greyed out area is a @ref Styles "style".
338 * And now an actionslider with a label in the indicator, and whose magnet
339 * properties change based on what was last selected:
340 * @skipline actionslider_add
341 * @skipline indicator_pos_set
343 * @note The greyed out area is a @ref Styles "style".
345 * We are almost done, this next one is just an actionslider with all
346 * positions magnetized and having every possible label:
347 * @skipline actionslider_add
348 * @skipline indicator_pos_set
351 * And for our last actionslider we have one that turns the magnetic property
353 * @skipline actionslider_add
354 * @skipline indicator_pos_set
357 * The example will look like this:
358 * @image html screenshots/actionslider_01.png
359 * @image latex screenshots/actionslider_01.eps
361 * See the full source code @ref actionslider_example_01 "here"
365 * @page elm_animator_example_page_01 Animator usage
366 * @dontinclude animator_example_01.c
368 * For this example we will be using a bit of evas, you could animate a
369 * elementary widget in much the same way, but to keep things simple we use
370 * an evas_object_rectangle.
372 * As every other example we start with our include and a simple callback to
373 * exit the app when the window is closed:
377 * This next callback is the one that actually creates our animation, it
378 * changes the size, position and color of a rectangle given to it in @a
382 * Next we have a callback that prints a string, nothing special:
385 * This next callback is a little more interesting, it has a state variable
386 * to know if the animation is currently paused or running, and it toogles
387 * the state of the animation accordingly:
392 * Finally we have a callback to stop the animation:
395 * As with every example we need to do a bit of setup before we can actually
396 * use an animation, but for the purposes of this example that's not relevant
397 * so let's just skip to the good stuff, creating an animator:
398 * @skipline animator_add
399 * @note Since elm_animator is not a widget we can give it a NULL parent.
401 * Now that we have an elm_animator we set it's duration to 1 second:
404 * We would also like our animation to be reversible, so:
407 * We also set our animation to repeat as many times as possible, which will
408 * mean that _end_cb will only be called after UINT_MAX * 2 seconds(UINT_MAX
409 * for the animation running forward and UNIT_MAX for the animation running
413 * To add some fun to our animation we will use the IN_OUT curve style:
416 * To actually animate anything we need an operation callback:
417 * @line operation_callback
419 * Even though we set our animation to repeat for a very long time we are
420 * going to set a end callback to it:
421 * @line completion_callback
422 * @note Notice that stoping the animation with the stop button will not make
425 * Now that we have fully set up our animator we can tell it to start
429 * There's a bit more of code that doesn't really matter to use so we skip
430 * right down to our last interesting point:
431 * @skipline animator_del
432 * @note Because we created our animator with no parent we need to delete it
435 * The example should look like this:
436 * @image html screenshots/animator_example_01.png
437 * @image latex screenshots/animator_example_01.eps
439 * @image html screenshots/animator_example_02.png
440 * @image latex screenshots/animator_example_02.eps
442 * @image html screenshots/animator_example_03.png
443 * @image latex screenshots/animator_example_03.eps
445 * The full source code for this example can be found @ref
446 * animator_example_01_c "here"
450 * @page transit_example_03_c elm_transit - Combined effects and options.
452 * This example shows how to apply the following transition effects:
460 * It allows you to apply more than one effect at once, and also allows to
461 * set properties like event_enabled, auto_reverse, repeat_times and
464 * @include transit_example_03.c
468 * @page transit_example_04_c elm_transit - Combined effects over two objects.
470 * This example shows how to apply the transition effects:
475 * over two objects. This kind of transition effect is used to make one
476 * object disappear and another one appear on its place.
478 * You can mix more than one effect of this type on the same objects, and the
479 * transition will apply both.
481 * @include transit_example_04.c
485 * @page transit_example_01_explained elm_transit - Basic transit usage.
486 * @dontinclude transit_example_01.c
488 * The full code for this example can be found at @ref transit_example_01_c.
490 * This example shows the simplest way of creating a transition and applying
491 * it to an object. Similarly to every other elementary example, we create a
492 * window, set its title, size, autodel property, and setup a callback to
493 * exit the program when finished:
496 * @until evas_object_resize
498 * We also add a resizeable white background to use behind our animation:
501 * @until evas_object_show
503 * And then we add a button that we will use to demonstrate the effects of
507 * @until evas_object_show(win)
509 * Notice that we are not adding the button with elm_win_resize_object_add()
510 * because we don't want the window to control the size of the button. We
511 * will use the transition to change the button size, so it could conflict
512 * with something else trying to control that size.
514 * Now, the simplest code possible to create the resize animation:
519 * As you can see, this code is very easy to understand. First, we create the
520 * transition itself with elm_transit_add(). Then we add the button to this
521 * transition with elm_transit_object_add(), which means that the transition
522 * will operate over this button. The effect that we want now is changing the
523 * object size from 100x50 to 300x150, and can be achieved by adding the
524 * resize effect with elm_transit_effect_resizing_add().
526 * Finally, we set the transition time to 5 seconds and start the transition
527 * with elm_transit_go(). If we wanted more effects applied to this
528 * button, we could add them to the same transition. See the
529 * @ref transit_example_03_c to watch many transitions being applied to an
534 * @page transit_example_02_explained elm_transit - Chained transitions.
535 * @dontinclude transit_example_02.c
537 * The full code for this example can be found at @ref transit_example_02_c.
539 * This example shows how to implement a chain of transitions. This chain is
540 * used to start a transition just after another transition ended. Similarly
541 * to every other elementary example, we create a window, set its title,
542 * size, autodel property, and setup a callback to exit the program when
546 * @until evas_object_resize
548 * We also add a resizeable white background to use behind our animation:
551 * @until evas_object_show
553 * This example will have a chain of 4 transitions, each of them applied to
554 * one button. Thus we create 4 different buttons:
557 * @until evas_object_show(bt4)
559 * Now we create a simple translation transition that will be started as soon
560 * as the program loads. It will be our first transition, and the other
561 * transitions will be started just after this transition ends:
566 * The code displayed until now has nothing different from what you have
567 * already seen in @ref transit_example_01_explained, but now comes the new
568 * part: instead of creating a second transition that will start later using
569 * a timer, we create the it normally, and use
570 * elm_transit_chain_transit_add() instead of elm_transit_go. Since we are
571 * adding it in a chain after the first transition, it will start as soon as
572 * the first transition ends:
575 * @until transit_chain_transit_add
577 * Finally we add the 2 other transitions to the chain, and run our program.
578 * It will make one transition start after the other finish, and there is the
583 * @page bg_example_01_c bg_example_01.c
584 * @include bg_example_01.c
585 * @example bg_example_01.c
589 * @page bg_example_02_c bg_example_02.c
590 * @include bg_example_02.c
591 * @example bg_example_02.c
595 * @page bg_example_03_c bg_example_03.c
596 * @include bg_example_03.c
597 * @example bg_example_03.c
601 * @page actionslider_example_01 Actionslider example
602 * @include actionslider_example_01.c
603 * @example actionslider_example_01.c
607 * @page animator_example_01_c Animator example 01
608 * @include animator_example_01.c
609 * @example animator_example_01.c
613 * @page transit_example_01_c Transit example 1
614 * @include transit_example_01.c
615 * @example transit_example_01.c
619 * @page transit_example_02_c Transit example 2
620 * @include transit_example_02.c
621 * @example transit_example_02.c