forked from enlightenment/efl
New Elementary API -- elm_multibuttonentry_format_function_set().
Useful when one does not want the default multi button entry counter item's format string.
This commit is contained in:
parent
31f2530bd7
commit
f6ad9605d6
|
@ -3,6 +3,17 @@
|
||||||
#endif
|
#endif
|
||||||
#include <Elementary.h>
|
#include <Elementary.h>
|
||||||
|
|
||||||
|
static Elm_Multibuttonentry_Format_Cb format_func = NULL;
|
||||||
|
|
||||||
|
static char *
|
||||||
|
_custom_format(int count, void *data EINA_UNUSED)
|
||||||
|
{
|
||||||
|
char buf[32];
|
||||||
|
|
||||||
|
if (!snprintf(buf, sizeof(buf), "+ %d rabbits", count)) return NULL;
|
||||||
|
return strdup(buf);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_item_selected_cb(void *data EINA_UNUSED,
|
_item_selected_cb(void *data EINA_UNUSED,
|
||||||
Evas_Object *obj EINA_UNUSED,
|
Evas_Object *obj EINA_UNUSED,
|
||||||
|
@ -122,11 +133,32 @@ _item_filter_cb(Evas_Object *obj EINA_UNUSED,
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_button_clicked_cb(void *data EINA_UNUSED,
|
_format_change_cb(void *data,
|
||||||
Evas_Object *obj EINA_UNUSED,
|
Evas_Object *obj EINA_UNUSED,
|
||||||
void *event_info EINA_UNUSED)
|
void *event_info EINA_UNUSED)
|
||||||
{
|
{
|
||||||
printf("%s button is clicked\n", __func__);
|
Evas_Object *mbe = data;
|
||||||
|
|
||||||
|
if (format_func) format_func = NULL;
|
||||||
|
else format_func = _custom_format;
|
||||||
|
|
||||||
|
elm_multibuttonentry_format_function_set(mbe, format_func, NULL);
|
||||||
|
|
||||||
|
printf("Changing format function to %p\n", format_func);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Evas_Object*
|
||||||
|
_format_change_btn_add(Evas_Object *mbe)
|
||||||
|
{
|
||||||
|
Evas_Object *btn;
|
||||||
|
|
||||||
|
btn = elm_button_add(mbe);
|
||||||
|
evas_object_smart_callback_add(btn, "clicked", _format_change_cb, mbe);
|
||||||
|
elm_object_text_set(btn, "Change format function");
|
||||||
|
evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
||||||
|
evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
||||||
|
|
||||||
|
return btn;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Evas_Object*
|
static Evas_Object*
|
||||||
|
@ -134,6 +166,7 @@ _add_multibuttonentry(Evas_Object *parent)
|
||||||
{
|
{
|
||||||
Evas_Object *scr = NULL;
|
Evas_Object *scr = NULL;
|
||||||
Evas_Object *mbe = NULL;
|
Evas_Object *mbe = NULL;
|
||||||
|
Evas_Object *btn = NULL;
|
||||||
void *data = NULL;
|
void *data = NULL;
|
||||||
|
|
||||||
scr = elm_scroller_add(parent);
|
scr = elm_scroller_add(parent);
|
||||||
|
@ -166,39 +199,21 @@ _add_multibuttonentry(Evas_Object *parent)
|
||||||
evas_object_smart_callback_add(mbe, "contracted", _contracted_cb, NULL);
|
evas_object_smart_callback_add(mbe, "contracted", _contracted_cb, NULL);
|
||||||
evas_object_smart_callback_add(mbe, "shrink,state,changed", _shrink_state_changed_cb, NULL);
|
evas_object_smart_callback_add(mbe, "shrink,state,changed", _shrink_state_changed_cb, NULL);
|
||||||
|
|
||||||
|
btn = _format_change_btn_add(mbe);
|
||||||
|
elm_object_part_content_set(parent, "box", btn);
|
||||||
|
|
||||||
evas_object_resize(mbe, 220, 300);
|
evas_object_resize(mbe, 220, 300);
|
||||||
elm_object_focus_set(mbe, EINA_TRUE);
|
elm_object_focus_set(mbe, EINA_TRUE);
|
||||||
|
|
||||||
return scr;
|
return scr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Evas_Object*
|
|
||||||
_add_buttons(Evas_Object *parent)
|
|
||||||
{
|
|
||||||
Evas_Object *bx = NULL;
|
|
||||||
Evas_Object *btn;
|
|
||||||
|
|
||||||
bx = elm_box_add(parent);
|
|
||||||
elm_box_horizontal_set(bx, EINA_TRUE);
|
|
||||||
elm_box_homogeneous_set(bx, EINA_TRUE);
|
|
||||||
|
|
||||||
btn = elm_button_add(parent);
|
|
||||||
evas_object_smart_callback_add(btn, "clicked", _button_clicked_cb, NULL);
|
|
||||||
elm_object_text_set(btn, "click");
|
|
||||||
evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, 0.0);
|
|
||||||
evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
|
||||||
elm_box_pack_end(bx, btn);
|
|
||||||
evas_object_show(btn);
|
|
||||||
|
|
||||||
return bx;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
test_multibuttonentry(void *data EINA_UNUSED,
|
test_multibuttonentry(void *data EINA_UNUSED,
|
||||||
Evas_Object *obj EINA_UNUSED,
|
Evas_Object *obj EINA_UNUSED,
|
||||||
void *event_info EINA_UNUSED)
|
void *event_info EINA_UNUSED)
|
||||||
{
|
{
|
||||||
Evas_Object *win, *sc, *bx;
|
Evas_Object *win, *sc;
|
||||||
Evas_Object *ly;
|
Evas_Object *ly;
|
||||||
char buf[PATH_MAX];
|
char buf[PATH_MAX];
|
||||||
|
|
||||||
|
@ -215,9 +230,6 @@ test_multibuttonentry(void *data EINA_UNUSED,
|
||||||
sc = _add_multibuttonentry(ly);
|
sc = _add_multibuttonentry(ly);
|
||||||
elm_object_part_content_set(ly, "multibuttonentry", sc);
|
elm_object_part_content_set(ly, "multibuttonentry", sc);
|
||||||
|
|
||||||
bx = _add_buttons(ly);
|
|
||||||
elm_object_part_content_set(ly, "box", bx);
|
|
||||||
|
|
||||||
evas_object_resize(win, 320, 480);
|
evas_object_resize(win, 320, 480);
|
||||||
evas_object_show(win);
|
evas_object_show(win);
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,6 +55,15 @@ _elm_multibuttonentry_smart_translate(Eo *obj EINA_UNUSED, void *_pd, va_list *l
|
||||||
if (ret) *ret = EINA_TRUE;
|
if (ret) *ret = EINA_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char *
|
||||||
|
_format_count(int count, void *data EINA_UNUSED)
|
||||||
|
{
|
||||||
|
char buf[32];
|
||||||
|
|
||||||
|
if (!snprintf(buf, sizeof(buf), "... + %d", count)) return NULL;
|
||||||
|
return strdup(buf);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_elm_multibuttonentry_smart_theme(Eo *obj, void *_pd, va_list *list)
|
_elm_multibuttonentry_smart_theme(Eo *obj, void *_pd, va_list *list)
|
||||||
{
|
{
|
||||||
|
@ -173,7 +182,7 @@ _shrink_mode_set(Evas_Object *obj,
|
||||||
EINA_LIST_FOREACH(sd->items, l, item)
|
EINA_LIST_FOREACH(sd->items, l, item)
|
||||||
{
|
{
|
||||||
Evas_Coord w_label_count = 0, h = 0;
|
Evas_Coord w_label_count = 0, h = 0;
|
||||||
char buf[MAX_STR];
|
char *buf;
|
||||||
|
|
||||||
elm_box_pack_end(sd->box, item->button);
|
elm_box_pack_end(sd->box, item->button);
|
||||||
evas_object_show(item->button);
|
evas_object_show(item->button);
|
||||||
|
@ -185,8 +194,14 @@ _shrink_mode_set(Evas_Object *obj,
|
||||||
|
|
||||||
if (count > 0)
|
if (count > 0)
|
||||||
{
|
{
|
||||||
snprintf(buf, sizeof(buf), "... + %i", count);
|
buf = sd->format_func(count, (void *)sd->format_func_data);
|
||||||
edje_object_part_text_escaped_set(sd->end, "elm.text", buf);
|
if (buf)
|
||||||
|
{
|
||||||
|
edje_object_part_text_escaped_set
|
||||||
|
(sd->end, "elm.text", buf);
|
||||||
|
free(buf);
|
||||||
|
}
|
||||||
|
|
||||||
edje_object_size_min_calc(sd->end, &w_label_count, NULL);
|
edje_object_size_min_calc(sd->end, &w_label_count, NULL);
|
||||||
elm_coords_finger_size_adjust(1, &w_label_count, 1, NULL);
|
elm_coords_finger_size_adjust(1, &w_label_count, 1, NULL);
|
||||||
}
|
}
|
||||||
|
@ -196,10 +211,16 @@ _shrink_mode_set(Evas_Object *obj,
|
||||||
elm_box_unpack(sd->box, item->button);
|
elm_box_unpack(sd->box, item->button);
|
||||||
evas_object_hide(item->button);
|
evas_object_hide(item->button);
|
||||||
item->visible = EINA_FALSE;
|
item->visible = EINA_FALSE;
|
||||||
|
|
||||||
count++;
|
count++;
|
||||||
snprintf(buf, sizeof(buf), "... + %d", count);
|
|
||||||
edje_object_part_text_escaped_set(sd->end, "elm.text", buf);
|
buf = sd->format_func(count, (void *)sd->format_func_data);
|
||||||
|
if (buf)
|
||||||
|
{
|
||||||
|
edje_object_part_text_escaped_set
|
||||||
|
(sd->end, "elm.text", buf);
|
||||||
|
free(buf);
|
||||||
|
}
|
||||||
|
|
||||||
edje_object_size_min_calc(sd->end, &w_label_count, &h);
|
edje_object_size_min_calc(sd->end, &w_label_count, &h);
|
||||||
elm_coords_finger_size_adjust(1, &w_label_count, 1, &h);
|
elm_coords_finger_size_adjust(1, &w_label_count, 1, &h);
|
||||||
evas_object_size_hint_min_set
|
evas_object_size_hint_min_set
|
||||||
|
@ -1478,6 +1499,7 @@ _elm_multibuttonentry_smart_add(Eo *obj, void *_pd, va_list *list EINA_UNUSED)
|
||||||
priv->last_btn_select = EINA_TRUE;
|
priv->last_btn_select = EINA_TRUE;
|
||||||
priv->editable = EINA_TRUE;
|
priv->editable = EINA_TRUE;
|
||||||
priv->parent = obj;
|
priv->parent = obj;
|
||||||
|
priv->format_func = _format_count;
|
||||||
|
|
||||||
_view_init(obj, priv);
|
_view_init(obj, priv);
|
||||||
_callbacks_register(obj);
|
_callbacks_register(obj);
|
||||||
|
@ -1665,6 +1687,32 @@ _expanded_get(Eo *obj EINA_UNUSED, void *_pd, va_list *list)
|
||||||
EINA_FALSE : EINA_TRUE;
|
EINA_FALSE : EINA_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EAPI void
|
||||||
|
elm_multibuttonentry_format_function_set(Evas_Object *obj,
|
||||||
|
Elm_Multibuttonentry_Format_Cb f_func,
|
||||||
|
const void *data)
|
||||||
|
{
|
||||||
|
ELM_MULTIBUTTONENTRY_CHECK(obj);
|
||||||
|
|
||||||
|
eo_do((Eo *) obj, elm_obj_multibuttonentry_format_function_set
|
||||||
|
(f_func, data));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
_format_function_set(Eo *obj EINA_UNUSED, void *_pd, va_list *list)
|
||||||
|
{
|
||||||
|
Elm_Multibuttonentry_Smart_Data *sd = _pd;
|
||||||
|
|
||||||
|
sd->format_func = va_arg(*list, Elm_Multibuttonentry_Format_Cb);
|
||||||
|
|
||||||
|
if (!sd->format_func) sd->format_func = _format_count;
|
||||||
|
|
||||||
|
sd->format_func_data = va_arg(*list, void *);
|
||||||
|
|
||||||
|
_view_update(sd);
|
||||||
|
}
|
||||||
|
|
||||||
EAPI void
|
EAPI void
|
||||||
elm_multibuttonentry_expanded_set(Evas_Object *obj,
|
elm_multibuttonentry_expanded_set(Evas_Object *obj,
|
||||||
Eina_Bool expanded)
|
Eina_Bool expanded)
|
||||||
|
@ -2158,6 +2206,7 @@ _class_constructor(Eo_Class *klass)
|
||||||
EO_OP_FUNC(ELM_OBJ_MULTIBUTTONENTRY_ID(ELM_OBJ_MULTIBUTTONENTRY_SUB_ID_ITEM_FILTER_APPEND), _item_filter_append),
|
EO_OP_FUNC(ELM_OBJ_MULTIBUTTONENTRY_ID(ELM_OBJ_MULTIBUTTONENTRY_SUB_ID_ITEM_FILTER_APPEND), _item_filter_append),
|
||||||
EO_OP_FUNC(ELM_OBJ_MULTIBUTTONENTRY_ID(ELM_OBJ_MULTIBUTTONENTRY_SUB_ID_ITEM_FILTER_PREPEND), _item_filter_prepend),
|
EO_OP_FUNC(ELM_OBJ_MULTIBUTTONENTRY_ID(ELM_OBJ_MULTIBUTTONENTRY_SUB_ID_ITEM_FILTER_PREPEND), _item_filter_prepend),
|
||||||
EO_OP_FUNC(ELM_OBJ_MULTIBUTTONENTRY_ID(ELM_OBJ_MULTIBUTTONENTRY_SUB_ID_ITEM_FILTER_REMOVE), _item_filter_remove),
|
EO_OP_FUNC(ELM_OBJ_MULTIBUTTONENTRY_ID(ELM_OBJ_MULTIBUTTONENTRY_SUB_ID_ITEM_FILTER_REMOVE), _item_filter_remove),
|
||||||
|
EO_OP_FUNC(ELM_OBJ_MULTIBUTTONENTRY_ID(ELM_OBJ_MULTIBUTTONENTRY_SUB_ID_FORMAT_FUNCTION_SET), _format_function_set),
|
||||||
EO_OP_FUNC_SENTINEL
|
EO_OP_FUNC_SENTINEL
|
||||||
};
|
};
|
||||||
eo_class_funcs_set(klass, func_desc);
|
eo_class_funcs_set(klass, func_desc);
|
||||||
|
@ -2185,6 +2234,7 @@ static const Eo_Op_Description op_desc[] = {
|
||||||
EO_OP_DESCRIPTION(ELM_OBJ_MULTIBUTTONENTRY_SUB_ID_ITEM_FILTER_APPEND, "Append an item filter function for text inserted in the Multibuttonentry."),
|
EO_OP_DESCRIPTION(ELM_OBJ_MULTIBUTTONENTRY_SUB_ID_ITEM_FILTER_APPEND, "Append an item filter function for text inserted in the Multibuttonentry."),
|
||||||
EO_OP_DESCRIPTION(ELM_OBJ_MULTIBUTTONENTRY_SUB_ID_ITEM_FILTER_PREPEND, "Prepend a filter function for text inserted in the Multibuttonentry."),
|
EO_OP_DESCRIPTION(ELM_OBJ_MULTIBUTTONENTRY_SUB_ID_ITEM_FILTER_PREPEND, "Prepend a filter function for text inserted in the Multibuttonentry."),
|
||||||
EO_OP_DESCRIPTION(ELM_OBJ_MULTIBUTTONENTRY_SUB_ID_ITEM_FILTER_REMOVE, "Remove a filter from the list."),
|
EO_OP_DESCRIPTION(ELM_OBJ_MULTIBUTTONENTRY_SUB_ID_ITEM_FILTER_REMOVE, "Remove a filter from the list."),
|
||||||
|
EO_OP_DESCRIPTION(ELM_OBJ_MULTIBUTTONENTRY_SUB_ID_FORMAT_FUNCTION_SET, "Set a function to format the string that will be used to display the hidden items counter."),
|
||||||
EO_OP_DESCRIPTION_SENTINEL
|
EO_OP_DESCRIPTION_SENTINEL
|
||||||
};
|
};
|
||||||
static const Eo_Class_Description class_desc = {
|
static const Eo_Class_Description class_desc = {
|
||||||
|
|
|
@ -13,3 +13,21 @@
|
||||||
*/
|
*/
|
||||||
typedef Eina_Bool (*Elm_Multibuttonentry_Item_Filter_Cb)(Evas_Object *obj, const char *item_label, void *item_data, void *data);
|
typedef Eina_Bool (*Elm_Multibuttonentry_Item_Filter_Cb)(Evas_Object *obj, const char *item_label, void *item_data, void *data);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef Elm_Multibuttonentry_Format_Cb
|
||||||
|
*
|
||||||
|
* This callback type is used to format the string that will be used
|
||||||
|
* to display the hidden items counter, when not in expanded mode.
|
||||||
|
*
|
||||||
|
* @param count Number of hidden items
|
||||||
|
* @param data The (context) data passed in to
|
||||||
|
* elm_multibuttonentry_format_function_set()
|
||||||
|
* @return String representing the counter that will be set to
|
||||||
|
* multibuttonentry's counter item's text.
|
||||||
|
*
|
||||||
|
* @see elm_multibuttonentry_format_function_set()
|
||||||
|
* @see elm_multibuttonentry_expanded_set()
|
||||||
|
*
|
||||||
|
* @ingroup Multibuttonentry
|
||||||
|
*/
|
||||||
|
typedef char * (*Elm_Multibuttonentry_Format_Cb)(int count, void *data);
|
||||||
|
|
|
@ -23,6 +23,7 @@ enum
|
||||||
ELM_OBJ_MULTIBUTTONENTRY_SUB_ID_ITEM_FILTER_APPEND,
|
ELM_OBJ_MULTIBUTTONENTRY_SUB_ID_ITEM_FILTER_APPEND,
|
||||||
ELM_OBJ_MULTIBUTTONENTRY_SUB_ID_ITEM_FILTER_PREPEND,
|
ELM_OBJ_MULTIBUTTONENTRY_SUB_ID_ITEM_FILTER_PREPEND,
|
||||||
ELM_OBJ_MULTIBUTTONENTRY_SUB_ID_ITEM_FILTER_REMOVE,
|
ELM_OBJ_MULTIBUTTONENTRY_SUB_ID_ITEM_FILTER_REMOVE,
|
||||||
|
ELM_OBJ_MULTIBUTTONENTRY_SUB_ID_FORMAT_FUNCTION_SET,
|
||||||
ELM_OBJ_MULTIBUTTONENTRY_SUB_ID_LAST
|
ELM_OBJ_MULTIBUTTONENTRY_SUB_ID_LAST
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -282,3 +283,22 @@ enum
|
||||||
* @ingroup Multibuttonentry
|
* @ingroup Multibuttonentry
|
||||||
*/
|
*/
|
||||||
#define elm_obj_multibuttonentry_item_filter_remove(func, data) ELM_OBJ_MULTIBUTTONENTRY_ID(ELM_OBJ_MULTIBUTTONENTRY_SUB_ID_ITEM_FILTER_REMOVE), EO_TYPECHECK(Elm_Multibuttonentry_Item_Filter_Cb, func), EO_TYPECHECK(void *, data)
|
#define elm_obj_multibuttonentry_item_filter_remove(func, data) ELM_OBJ_MULTIBUTTONENTRY_ID(ELM_OBJ_MULTIBUTTONENTRY_SUB_ID_ITEM_FILTER_REMOVE), EO_TYPECHECK(Elm_Multibuttonentry_Item_Filter_Cb, func), EO_TYPECHECK(void *, data)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @def elm_obj_multibuttonentry_format_function_set
|
||||||
|
* @since 1.9
|
||||||
|
*
|
||||||
|
* Set a function to format the string that will be used to display
|
||||||
|
* the hidden items counter.
|
||||||
|
*
|
||||||
|
* @param[in] format_function The actual format function
|
||||||
|
* @param[in] data User data to passed to @a format_function
|
||||||
|
*
|
||||||
|
* If @a format_function is @c NULL, the default format will be used,
|
||||||
|
* which is @c "... + %d".
|
||||||
|
*
|
||||||
|
* @see elm_multibuttonentry_format_function_set
|
||||||
|
*
|
||||||
|
* @ingroup Multibuttonentry
|
||||||
|
*/
|
||||||
|
#define elm_obj_multibuttonentry_format_function_set(format_function, data) ELM_OBJ_MULTIBUTTONENTRY_ID(ELM_OBJ_MULTIBUTTONENTRY_SUB_ID_FORMAT_FUNCTION_SET), EO_TYPECHECK(Elm_Multibuttonentry_Format_Cb, format_function), EO_TYPECHECK(const void *, data)
|
||||||
|
|
|
@ -245,6 +245,27 @@ EAPI void elm_multibuttonentry_item_filter_prepend(Evas_Ob
|
||||||
*/
|
*/
|
||||||
EAPI void elm_multibuttonentry_item_filter_remove(Evas_Object *obj, Elm_Multibuttonentry_Item_Filter_Cb func, void *data);
|
EAPI void elm_multibuttonentry_item_filter_remove(Evas_Object *obj, Elm_Multibuttonentry_Item_Filter_Cb func, void *data);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a function to format the string that will be used to display
|
||||||
|
* the hidden items counter.
|
||||||
|
*
|
||||||
|
* @param[in] obj The multi button entry to get format function changed
|
||||||
|
* @param[in] format_function The actual format function
|
||||||
|
* @param[in] data User data to passed to @a format_function
|
||||||
|
*
|
||||||
|
* If @a format_function is @c NULL, the default format will be used,
|
||||||
|
* which is @c "... + %d".
|
||||||
|
*
|
||||||
|
* @see elm_multibuttonentry_format_function_set
|
||||||
|
* @since 1.9
|
||||||
|
*
|
||||||
|
* @ingroup Multibuttonentry
|
||||||
|
*/
|
||||||
|
EAPI void
|
||||||
|
elm_multibuttonentry_format_function_set(Evas_Object *obj,
|
||||||
|
Elm_Multibuttonentry_Format_Cb f_func,
|
||||||
|
const void *data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets if the multibuttonentry is to be editable or not.
|
* Sets if the multibuttonentry is to be editable or not.
|
||||||
*
|
*
|
||||||
|
|
|
@ -82,6 +82,9 @@ struct _Elm_Multibuttonentry_Smart_Data
|
||||||
Eina_List *filter_list;
|
Eina_List *filter_list;
|
||||||
Elm_Object_Item *selected_it; /* selected item */
|
Elm_Object_Item *selected_it; /* selected item */
|
||||||
|
|
||||||
|
Elm_Multibuttonentry_Format_Cb format_func;
|
||||||
|
const void *format_func_data;
|
||||||
|
|
||||||
const char *label_str, *guide_text_str;
|
const char *label_str, *guide_text_str;
|
||||||
|
|
||||||
int n_str;
|
int n_str;
|
||||||
|
|
Loading…
Reference in New Issue