forked from enlightenment/efl
efl_ui_tab_bar: implement efl.ui.single_selectable
this is for now the simples way IMO, the one or another implementation thing in efl_ui_tab_pager is a little bit clumsy, but that should be able to be improved once Efl.Pack_Linear is implemented. Reviewed-by: WooHyun Jung <woohyun0705@gmail.com> Differential Revision: https://phab.enlightenment.org/D9729
This commit is contained in:
parent
f52a0b25f3
commit
3c317618e5
|
@ -11,19 +11,11 @@
|
|||
#define MY_CLASS EFL_UI_TAB_BAR_CLASS
|
||||
#define MY_CLASS_NAME "Efl.Ui.Tab_Bar"
|
||||
|
||||
EOLIAN static void
|
||||
_efl_ui_tab_bar_current_tab_set(Eo *obj EINA_UNUSED, Efl_Ui_Tab_Bar_Data *sd, int index)
|
||||
{
|
||||
Efl_Ui_Item *item;
|
||||
item = eina_list_nth(sd->tab_infos, index);
|
||||
|
||||
efl_ui_selectable_selected_set(item, EINA_TRUE);
|
||||
}
|
||||
|
||||
EOLIAN static int
|
||||
_efl_ui_tab_bar_current_tab_get(const Eo *obj EINA_UNUSED, Efl_Ui_Tab_Bar_Data *sd)
|
||||
EOLIAN static Efl_Ui_Selectable*
|
||||
_efl_ui_tab_bar_efl_ui_single_selectable_last_selected_get(const Eo *obj EINA_UNUSED, Efl_Ui_Tab_Bar_Data *pd)
|
||||
{
|
||||
return eina_list_data_idx(sd->tab_infos, sd->selected);
|
||||
return pd->selected;
|
||||
}
|
||||
|
||||
EOLIAN static unsigned int
|
||||
|
@ -32,6 +24,20 @@ _efl_ui_tab_bar_tab_count(const Eo *obj EINA_UNUSED, Efl_Ui_Tab_Bar_Data *sd)
|
|||
return sd->cnt;
|
||||
}
|
||||
|
||||
EOLIAN static void
|
||||
_efl_ui_tab_bar_efl_ui_single_selectable_fallback_selection_set(Eo *obj EINA_UNUSED, Efl_Ui_Tab_Bar_Data *pd, Efl_Ui_Selectable *fallback)
|
||||
{
|
||||
pd->fallback_selection = fallback;
|
||||
if (!pd->selected)
|
||||
efl_ui_selectable_selected_set(pd->fallback_selection, EINA_TRUE);
|
||||
}
|
||||
|
||||
EOLIAN static Efl_Ui_Selectable*
|
||||
_efl_ui_tab_bar_efl_ui_single_selectable_fallback_selection_get(const Eo *obj EINA_UNUSED, Efl_Ui_Tab_Bar_Data *pd)
|
||||
{
|
||||
return pd->fallback_selection;
|
||||
}
|
||||
|
||||
static void _remove_item(Eo *obj, Efl_Ui_Tab_Bar_Data *pd, Efl_Ui_Item *item);
|
||||
|
||||
static void
|
||||
|
@ -45,15 +51,27 @@ _selelction_change_cb(void *data, const Efl_Event *ev)
|
|||
{
|
||||
pd->selected = NULL;
|
||||
}
|
||||
//checkout if we want to do fallback handling
|
||||
if (!pd->in_value_change)
|
||||
{
|
||||
if (!pd->selected && pd->fallback_selection)
|
||||
efl_ui_selectable_selected_set(pd->fallback_selection, EINA_TRUE);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
pd->in_value_change = EINA_TRUE;
|
||||
if (pd->selected)
|
||||
efl_ui_selectable_selected_set(pd->selected, EINA_FALSE);
|
||||
pd->in_value_change = EINA_FALSE;
|
||||
EINA_SAFETY_ON_FALSE_RETURN(!pd->selected);
|
||||
pd->selected = ev->object;
|
||||
efl_event_callback_call(data, EFL_UI_EVENT_ITEM_SELECTED, NULL);
|
||||
}
|
||||
if (!pd->in_value_change)
|
||||
{
|
||||
efl_event_callback_call(data, EFL_UI_SINGLE_SELECTABLE_EVENT_SELECTION_CHANGED, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -2,11 +2,6 @@ class @beta Efl.Ui.Tab_Bar extends Efl.Ui.Layout_Base implements Efl.Ui.Single_S
|
|||
{
|
||||
[[Tab Bar class]]
|
||||
methods {
|
||||
@property current_tab {
|
||||
values {
|
||||
index: int;
|
||||
}
|
||||
}
|
||||
tab_count @const {
|
||||
return: uint;
|
||||
}
|
||||
|
@ -25,5 +20,22 @@ class @beta Efl.Ui.Tab_Bar extends Efl.Ui.Layout_Base implements Efl.Ui.Single_S
|
|||
implements {
|
||||
Efl.Object.constructor;
|
||||
Efl.Object.destructor;
|
||||
Efl.Ui.Single_Selectable.last_selected {get;}
|
||||
Efl.Ui.Single_Selectable.fallback_selection {get; set;}
|
||||
Efl.Pack.pack;
|
||||
Efl.Pack.pack_clear;
|
||||
Efl.Pack.unpack_all;
|
||||
Efl.Pack.unpack;
|
||||
Efl.Pack_Linear.pack_unpack_at;
|
||||
Efl.Pack_Linear.pack_begin;
|
||||
Efl.Pack_Linear.pack_end;
|
||||
Efl.Pack_Linear.pack_before;
|
||||
Efl.Pack_Linear.pack_after;
|
||||
Efl.Pack_Linear.pack_at;
|
||||
Efl.Container.content_count;
|
||||
Efl.Container.content_iterate;
|
||||
}
|
||||
composite {
|
||||
Efl.Pack_Linear;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,9 +8,9 @@ struct _Efl_Ui_Tab_Bar_Data
|
|||
Efl_Canvas_Object *bx;
|
||||
int cnt;
|
||||
Efl_Ui_Layout_Orientation dir;
|
||||
|
||||
Eina_List *tab_infos;
|
||||
Efl_Ui_Item *selected;
|
||||
Efl_Ui_Item *selected, *fallback_selection;
|
||||
Eina_Bool in_value_change;
|
||||
};
|
||||
|
||||
#define EFL_UI_TAB_BAR_DATA_GET(o, sd) \
|
||||
|
|
|
@ -18,15 +18,31 @@ _select(Eo *obj, int index)
|
|||
if (sd->cnt > index) sd->cur = index;
|
||||
else sd->cur = 0;
|
||||
|
||||
efl_ui_tab_bar_current_tab_set(sd->tab_bar, sd->cur);
|
||||
Efl_Ui_Tab_Page *page = eina_list_nth(sd->tab_pages, sd->cur);
|
||||
|
||||
efl_ui_selectable_selected_set(efl_ui_tab_page_tab_bar_item_get(page), EINA_TRUE);
|
||||
}
|
||||
|
||||
static void
|
||||
_tab_select_cb(void *data, const Efl_Event *event)
|
||||
{
|
||||
int index = efl_ui_tab_bar_current_tab_get(event->object);
|
||||
if (efl_ui_spotlight_active_index_get(data) != index)
|
||||
efl_ui_spotlight_active_index_set(data, index);
|
||||
Eina_List *n;
|
||||
Efl_Ui_Tab_Page *p;
|
||||
EFL_UI_TAB_PAGER_DATA_GET(data, sd);
|
||||
int i = 0;
|
||||
//FIXME this is super clumsy, this can be improved later on
|
||||
Efl_Ui_Tab_Bar_Default_Item *selected;
|
||||
|
||||
selected = efl_ui_single_selectable_last_selected_get(event->object);
|
||||
EINA_LIST_FOREACH(sd->tab_pages, n, p)
|
||||
{
|
||||
if (efl_ui_tab_page_tab_bar_item_get(p) == selected)
|
||||
{
|
||||
if (efl_ui_spotlight_active_index_get(data) != i)
|
||||
efl_ui_spotlight_active_index_set(data, i);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
EOLIAN static void
|
||||
|
|
Loading…
Reference in New Issue