forked from enlightenment/efl
Add a new shrink mode to elm_toolbar: SHRINK_HIDE
And fix the docs related to shrink mode: SHRINK_HIDE -> hide excess items SHRINK_NONE -> set toolbar minimun size to fit all the items SVN revision: 53895
This commit is contained in:
parent
01d04e55e0
commit
473d8bfc3f
|
@ -35,6 +35,7 @@ void test_anchorblock(void *data, Evas_Object *obj, void *event_info);
|
|||
void test_toolbar(void *data, Evas_Object *obj, void *event_info);
|
||||
void test_toolbar2(void *data, Evas_Object *obj, void *event_info);
|
||||
void test_toolbar3(void *data, Evas_Object *obj, void *event_info);
|
||||
void test_toolbar4(void *data, Evas_Object *obj, void *event_info);
|
||||
void test_hoversel(void *data, Evas_Object *obj, void *event_info);
|
||||
void test_list(void *data, Evas_Object *obj, void *event_info);
|
||||
void test_list_horizontal(void *data, Evas_Object *obj, void *event_info);
|
||||
|
@ -257,6 +258,7 @@ my_win_main(char *autorun)
|
|||
ADD_TEST("Toolbar", test_toolbar);
|
||||
ADD_TEST("Toolbar 2", test_toolbar2);
|
||||
ADD_TEST("Toolbar 3", test_toolbar3);
|
||||
ADD_TEST("Toolbar 4", test_toolbar4);
|
||||
ADD_TEST("Hoversel", test_hoversel);
|
||||
ADD_TEST("List", test_list);
|
||||
ADD_TEST("List - Horizontal", test_list_horizontal);
|
||||
|
|
|
@ -370,4 +370,114 @@ test_toolbar3(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_in
|
|||
evas_object_resize(win, 320, 300);
|
||||
evas_object_show(win);
|
||||
}
|
||||
|
||||
/* The same test of toolbar, but using hide shrink mode instead of menu */
|
||||
void
|
||||
test_toolbar4(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
|
||||
{
|
||||
Evas_Object *win, *bg, *bx, *tb, *ph, *menu;
|
||||
Evas_Object *ph1, *ph2, *ph3, *ph4;
|
||||
Elm_Toolbar_Item *item;
|
||||
Elm_Menu_Item *menu_item;
|
||||
char buf[PATH_MAX];
|
||||
|
||||
win = elm_win_add(NULL, "toolbar", ELM_WIN_BASIC);
|
||||
elm_win_title_set(win, "Toolbar 4");
|
||||
elm_win_autodel_set(win, EINA_TRUE);
|
||||
|
||||
bg = elm_bg_add(win);
|
||||
elm_win_resize_object_add(win, bg);
|
||||
evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
||||
evas_object_show(bg);
|
||||
|
||||
bx = elm_box_add(win);
|
||||
elm_win_resize_object_add(win, bx);
|
||||
evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
||||
evas_object_show(bx);
|
||||
|
||||
tb = elm_toolbar_add(win);
|
||||
elm_toolbar_homogenous_set(tb, 0);
|
||||
elm_toolbar_mode_shrink_set(tb, ELM_TOOLBAR_SHRINK_HIDE);
|
||||
evas_object_size_hint_weight_set(tb, 0.0, 0.0);
|
||||
evas_object_size_hint_align_set(tb, EVAS_HINT_FILL, 0.0);
|
||||
|
||||
ph1 = elm_photo_add(win);
|
||||
ph2 = elm_photo_add(win);
|
||||
ph3 = elm_photo_add(win);
|
||||
ph4 = elm_photo_add(win);
|
||||
|
||||
item = elm_toolbar_item_append(tb, "document-print", "Hello", tb_1, ph1);
|
||||
elm_toolbar_item_disabled_set(item, EINA_TRUE);
|
||||
elm_toolbar_item_priority_set(item, 100);
|
||||
|
||||
item = elm_toolbar_item_append(tb, "folder-new", "World", tb_2, ph1);
|
||||
elm_toolbar_item_priority_set(item, -100);
|
||||
|
||||
item = elm_toolbar_item_append(tb, "object-rotate-right", "H", tb_3, ph4);
|
||||
elm_toolbar_item_priority_set(item, 150);
|
||||
|
||||
item = elm_toolbar_item_append(tb, "mail-send", "Comes", tb_4, ph4);
|
||||
elm_toolbar_item_priority_set(item, 0);
|
||||
|
||||
item = elm_toolbar_item_append(tb, "clock", "Elementary", tb_5, ph4);
|
||||
elm_toolbar_item_priority_set(item, -200);
|
||||
|
||||
item = elm_toolbar_item_append(tb, "refresh", "Menu", NULL, NULL);
|
||||
elm_toolbar_item_menu_set(item, 1);
|
||||
elm_toolbar_item_priority_set(item, -999999);
|
||||
elm_toolbar_menu_parent_set(tb, win);
|
||||
menu = elm_toolbar_item_menu_get(item);
|
||||
|
||||
elm_menu_item_add(menu, NULL, "edit-cut", "Shrink", tb_3, ph4);
|
||||
menu_item = elm_menu_item_add(menu, NULL, "edit-copy", "Mode", tb_4, ph4);
|
||||
elm_menu_item_add(menu, menu_item, "edit-paste", "is set to", tb_4, ph4);
|
||||
elm_menu_item_add(menu, NULL, "edit-delete", "Menu", tb_5, ph4);
|
||||
|
||||
elm_box_pack_end(bx, tb);
|
||||
evas_object_show(tb);
|
||||
|
||||
tb = elm_table_add(win);
|
||||
evas_object_size_hint_weight_set(tb, 0.0, EVAS_HINT_EXPAND);
|
||||
evas_object_size_hint_fill_set(tb, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
||||
|
||||
ph = ph1;
|
||||
elm_photo_size_set(ph, 40);
|
||||
snprintf(buf, sizeof(buf), "%s/images/plant_01.jpg", PACKAGE_DATA_DIR);
|
||||
elm_photo_file_set(ph, buf);
|
||||
evas_object_size_hint_weight_set(ph, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
||||
evas_object_size_hint_align_set(ph, 0.5, 0.5);
|
||||
elm_table_pack(tb, ph, 0, 0, 1, 1);
|
||||
evas_object_show(ph);
|
||||
|
||||
ph = ph2;
|
||||
elm_photo_size_set(ph, 80);
|
||||
evas_object_size_hint_weight_set(ph, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
||||
evas_object_size_hint_align_set(ph, 0.5, 0.5);
|
||||
elm_table_pack(tb, ph, 1, 0, 1, 1);
|
||||
evas_object_show(ph);
|
||||
|
||||
ph = ph3;
|
||||
elm_photo_size_set(ph, 20);
|
||||
snprintf(buf, sizeof(buf), "%s/images/sky_01.jpg", PACKAGE_DATA_DIR);
|
||||
elm_photo_file_set(ph, buf);
|
||||
evas_object_size_hint_weight_set(ph, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
||||
evas_object_size_hint_align_set(ph, 0.5, 0.5);
|
||||
elm_table_pack(tb, ph, 0, 1, 1, 1);
|
||||
evas_object_show(ph);
|
||||
|
||||
ph = ph4;
|
||||
elm_photo_size_set(ph, 60);
|
||||
snprintf(buf, sizeof(buf), "%s/images/sky_02.jpg", PACKAGE_DATA_DIR);
|
||||
elm_photo_file_set(ph, buf);
|
||||
evas_object_size_hint_weight_set(ph, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
||||
evas_object_size_hint_align_set(ph, 0.5, 0.5);
|
||||
elm_table_pack(tb, ph, 1, 1, 1, 1);
|
||||
evas_object_show(ph);
|
||||
|
||||
elm_box_pack_end(bx, tb);
|
||||
evas_object_show(tb);
|
||||
|
||||
evas_object_resize(win, 320, 300);
|
||||
evas_object_show(win);
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -245,7 +245,8 @@ extern "C" {
|
|||
|
||||
typedef enum _Elm_Toolbar_Shrink_Mode
|
||||
{
|
||||
ELM_TOOLBAR_SHRINK_NONE, /**< hide excess items */
|
||||
ELM_TOOLBAR_SHRINK_NONE, /**< set toolbar minimun size to fit all the items */
|
||||
ELM_TOOLBAR_SHRINK_HIDE, /**< hide excess items */
|
||||
ELM_TOOLBAR_SHRINK_SCROLL, /**< allow accessing excess items through a scroller */
|
||||
ELM_TOOLBAR_SHRINK_MENU /**< inserts a button to pop up a menu with excess items */
|
||||
} Elm_Toolbar_Shrink_Mode;
|
||||
|
|
|
@ -283,6 +283,7 @@ _sizing_eval(Evas_Object *obj)
|
|||
switch (wd->shrink_mode)
|
||||
{
|
||||
case ELM_TOOLBAR_SHRINK_MENU: /* fallthrough */
|
||||
case ELM_TOOLBAR_SHRINK_HIDE: /* fallthrough */
|
||||
case ELM_TOOLBAR_SHRINK_SCROLL: minw = w - vw; break;
|
||||
case ELM_TOOLBAR_SHRINK_NONE: minw = minw + (w - vw); break;
|
||||
}
|
||||
|
@ -325,6 +326,28 @@ _toolbar_item_prio_compare_cb(const void *i1, const void *i2)
|
|||
return eti2->prio.priority - eti1->prio.priority;
|
||||
}
|
||||
|
||||
static void
|
||||
_fix_items_visibility(Widget_Data *wd, Evas_Coord *iw, Evas_Coord vw)
|
||||
{
|
||||
Elm_Toolbar_Item *it;
|
||||
Eina_List *sorted = NULL;
|
||||
|
||||
EINA_INLIST_FOREACH(wd->items, it)
|
||||
{
|
||||
sorted = eina_list_sorted_insert(sorted,
|
||||
_toolbar_item_prio_compare_cb, it);
|
||||
}
|
||||
|
||||
EINA_LIST_FREE(sorted, it)
|
||||
{
|
||||
Evas_Coord ciw;
|
||||
|
||||
evas_object_geometry_get(it->base.view, NULL, NULL, &ciw, NULL);
|
||||
*iw += ciw;
|
||||
it->prio.visible = (*iw <= vw);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
|
||||
{
|
||||
|
@ -344,25 +367,10 @@ _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event
|
|||
if (wd->shrink_mode == ELM_TOOLBAR_SHRINK_MENU)
|
||||
{
|
||||
Evas_Coord iw = 0;
|
||||
Eina_List *sorted = NULL;
|
||||
_fix_items_visibility(wd, &iw, vw);
|
||||
|
||||
EINA_INLIST_FOREACH(wd->items, it)
|
||||
{
|
||||
sorted = eina_list_sorted_insert(sorted,
|
||||
_toolbar_item_prio_compare_cb, it);
|
||||
}
|
||||
|
||||
EINA_LIST_FREE(sorted, it)
|
||||
{
|
||||
Evas_Coord ciw;
|
||||
|
||||
evas_object_geometry_get(it->base.view, NULL, NULL, &ciw, NULL);
|
||||
iw += ciw;
|
||||
it->prio.visible = (iw <= vw);
|
||||
}
|
||||
|
||||
/* All items are removed from the box object, since removing individual items won't trigger
|
||||
a resize. Items are be readded below. */
|
||||
/* All items are removed from the box object, since removing individual
|
||||
* items won't trigger a resize. Items are be readded below. */
|
||||
evas_object_box_remove_all(wd->bx, EINA_FALSE);
|
||||
if (iw > vw)
|
||||
{
|
||||
|
@ -401,7 +409,8 @@ _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event
|
|||
}
|
||||
else
|
||||
{
|
||||
/* All items are visible, show them all (except for the "More" button, of course). */
|
||||
/* All items are visible, show them all (except for the "More"
|
||||
* button, of course). */
|
||||
EINA_INLIST_FOREACH(wd->items, it)
|
||||
{
|
||||
if (it == wd->more_item)
|
||||
|
@ -414,6 +423,34 @@ _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event
|
|||
}
|
||||
}
|
||||
}
|
||||
else if (wd->shrink_mode == ELM_TOOLBAR_SHRINK_HIDE)
|
||||
{
|
||||
Evas_Coord iw = 0;
|
||||
_fix_items_visibility(wd, &iw, vw);
|
||||
evas_object_box_remove_all(wd->bx, EINA_FALSE);
|
||||
if (iw > vw)
|
||||
{
|
||||
EINA_INLIST_FOREACH(wd->items, it)
|
||||
{
|
||||
if (!it->prio.visible)
|
||||
evas_object_hide(it->base.view);
|
||||
else
|
||||
{
|
||||
evas_object_box_append(wd->bx, it->base.view);
|
||||
evas_object_show(it->base.view);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* All items are visible, show them all */
|
||||
EINA_INLIST_FOREACH(wd->items, it)
|
||||
{
|
||||
evas_object_show(it->base.view);
|
||||
evas_object_box_append(wd->bx, it->base.view);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
EINA_INLIST_FOREACH(wd->items, it)
|
||||
|
@ -816,10 +853,12 @@ elm_toolbar_item_toolbar_get(const Elm_Toolbar_Item *item)
|
|||
}
|
||||
|
||||
/**
|
||||
* Sets the priority of a toolbar item. This is used only when the toolbar expand mode
|
||||
* is set to ELM_TOOLBAR_SHRINK_MENU: when space is at a premium, items with low priority
|
||||
* will be removed from the toolbar and added to a dynamically-created menu, while items
|
||||
* with higher priority will remain on the toolbar, with the same order they were added.
|
||||
* Sets the priority of a toolbar item. This is used only when the toolbar
|
||||
* shrink mode is set to ELM_TOOLBAR_SHRINK_MENU or ELM_TOOLBAR_SHRINK_HIDE:
|
||||
* when space is at a premium, items with low priority will be removed from
|
||||
* the toolbar and added to a dynamically-created menu, while items with
|
||||
* higher priority will remain on the toolbar, with the same order they were
|
||||
* added.
|
||||
*
|
||||
* @param item The toolbar item.
|
||||
* @param priority The item priority. The default is zero.
|
||||
|
@ -1085,11 +1124,13 @@ elm_toolbar_item_separator_get(const Elm_Toolbar_Item *item)
|
|||
}
|
||||
|
||||
/**
|
||||
* Set the expand state of toolbar @p obj.
|
||||
* Set the shrink state of toolbar @p obj.
|
||||
*
|
||||
* @param obj The toolbar object
|
||||
* @param shrink_mode The toolbar won't scroll if ELM_TOOLBAR_SHRINK_NONE,
|
||||
* will scroll if ELM_TOOLBAR_SHRINK_SCROLL, and will create a button to
|
||||
* but will enforce a minimun size so all the items will fit, won't scroll
|
||||
* and won't show the items that don't fit if ELM_TOOLBAR_SHRINK_HIDE,
|
||||
* will scroll if ELM_TOOLBAR_SHRINK_SCROLL, and will create a button to
|
||||
* pop up excess elements with ELM_TOOLBAR_SHRINK_MENU.
|
||||
*
|
||||
* @ingroup Toolbar
|
||||
|
@ -1121,8 +1162,12 @@ elm_toolbar_mode_shrink_set(Evas_Object *obj, Elm_Toolbar_Shrink_Mode shrink_mod
|
|||
NULL, NULL);
|
||||
elm_toolbar_item_priority_set(wd->more_item, INT_MAX);
|
||||
}
|
||||
else if (shrink_mode == ELM_TOOLBAR_SHRINK_HIDE)
|
||||
elm_smart_scroller_policy_set(wd->scr, ELM_SMART_SCROLLER_POLICY_OFF,
|
||||
ELM_SMART_SCROLLER_POLICY_OFF);
|
||||
else
|
||||
elm_smart_scroller_policy_set(wd->scr, ELM_SMART_SCROLLER_POLICY_AUTO, ELM_SMART_SCROLLER_POLICY_OFF);
|
||||
elm_smart_scroller_policy_set(wd->scr, ELM_SMART_SCROLLER_POLICY_AUTO,
|
||||
ELM_SMART_SCROLLER_POLICY_OFF);
|
||||
_sizing_eval(obj);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue