Tizen(Headed) Native API
6.5
|
This code places an Elementary mapbuf widget on a window, to exemplify part of the widget's API.
First we'll add an window with a background and a vertical box to pack our interface elements:
Next we'll simply add the mapbuf widget to the box:
But mapbuf is a container widget, it won't do anything alone. So let's create a table full of icons. For that we'll loop to fill each line of each column. See tutorial_table_01 if you don't know how to use tables:
Finally, setting mapbuf content:
Also, would be good a horizontal box with some controls to change mapbuf behavior:
By default map is disabled. So just setting content isn't enough. Alpha and smooth settings will be applied when map is enabled. So we'll add a check for that. Everytime the map properties are changed, map will need to be enabled again. So if you want to play a bit with our example, remember to always enable map again after concluding your changes.
We have added a callback function to this check, so it will enable or disable map:
static void _alpha_cb(void *data, Evas_Object *obj, void *event_info EINA_UNUSED) { Evas_Object *mb = data; elm_mapbuf_alpha_set(mb, elm_check_state_get(obj)); }
Let's add check boxes for alpha blending and smooth rendering:
tg = elm_check_add(win); elm_object_style_set(tg, "toggle"); elm_object_part_text_set(tg, "on", "Enabled"); elm_object_part_text_set(tg, "off", "Disabled"); elm_object_text_set(tg, "Map"); evas_object_smart_callback_add(tg, "changed", _enabled_cb, mb); elm_box_pack_end(hbx, tg); evas_object_show(tg); ck = elm_check_add(win); elm_object_text_set(ck, "Alpha"); elm_check_state_set(ck, EINA_TRUE); evas_object_smart_callback_add(ck, "changed", _alpha_cb, mb); elm_box_pack_end(hbx, ck); evas_object_show(ck);
By default, mapbuf would enable alpha blending and smooth rendering, so we need to check boxes to be consistent with its behavior.
Callback functions look like the one added to the check. This way we could enable or disable the both properties:
static void _smooth_cb(void *data, Evas_Object *obj, void *event_info EINA_UNUSED) { Evas_Object *mb = data; elm_mapbuf_smooth_set(mb, elm_check_state_get(obj)); } EAPI_MAIN int elm_main(int argc EINA_UNUSED, char **argv EINA_UNUSED) { Evas_Object *win, *bx, *hbx, *tg, *ck, *mb, *tb, *ic; unsigned int i, j; elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED); win = elm_win_util_standard_add("mapbuf", "Mapbuf Example"); elm_win_autodel_set(win, EINA_TRUE); bx = elm_box_add(win); evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); elm_win_resize_object_add(win, bx); evas_object_show(bx); mb = elm_mapbuf_add(win); evas_object_size_hint_weight_set(mb, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(mb, EVAS_HINT_FILL, EVAS_HINT_FILL); elm_box_pack_end(bx, mb); tb = elm_table_add(win); evas_object_size_hint_weight_set(tb, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(tb, EVAS_HINT_FILL, EVAS_HINT_FILL); evas_object_show(tb); for (i = 0; i < 8; i++) { for (j = 0; j < 8; j++) { ic = elm_icon_add(win); elm_icon_standard_set(ic, "home"); elm_image_resizable_set(ic, EINA_FALSE, EINA_FALSE); evas_object_show(ic); elm_table_pack(tb, ic, i, j, 1, 1); }
You'll see that disabling alpha blending will set a black rectangle below the icons. That's the reason you only should enable that when you're sure the mapbuf content is 100% solid.
See the full source code for this example.