forked from enlightenment/efl
Add special values to spinner.
Special value is a string showed instead a numerical one. By: Rafael Fonseca <rfonseca@profusion.mobi> SVN revision: 48090
This commit is contained in:
parent
37d6782967
commit
8a23d2a6b7
|
@ -59,6 +59,28 @@ test_spinner(void *data, Evas_Object *obj, void *event_info)
|
|||
elm_box_pack_end(bx, sp);
|
||||
evas_object_show(sp);
|
||||
|
||||
sp = elm_spinner_add(win);
|
||||
elm_spinner_min_max_set(sp, 1, 12);
|
||||
elm_spinner_label_format_set(sp, "%.0f");
|
||||
elm_spinner_step_set(sp, 1.0);
|
||||
elm_spinner_editable_set(sp, EINA_FALSE);
|
||||
elm_spinner_special_value_add(sp, 1, "January");
|
||||
elm_spinner_special_value_add(sp, 2, "February");
|
||||
elm_spinner_special_value_add(sp, 3, "March");
|
||||
elm_spinner_special_value_add(sp, 4, "April");
|
||||
elm_spinner_special_value_add(sp, 5, "May");
|
||||
elm_spinner_special_value_add(sp, 6, "June");
|
||||
elm_spinner_special_value_add(sp, 7, "July");
|
||||
elm_spinner_special_value_add(sp, 8, "August");
|
||||
elm_spinner_special_value_add(sp, 9, "September");
|
||||
elm_spinner_special_value_add(sp, 10, "October");
|
||||
elm_spinner_special_value_add(sp, 11, "November");
|
||||
elm_spinner_special_value_add(sp, 12, "December");
|
||||
evas_object_size_hint_align_set(sp, EVAS_HINT_FILL, 0.5);
|
||||
evas_object_size_hint_weight_set(sp, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
||||
elm_box_pack_end(bx, sp);
|
||||
evas_object_show(sp);
|
||||
|
||||
evas_object_show(win);
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -1197,6 +1197,9 @@ extern "C" {
|
|||
EAPI double elm_spinner_value_get(const Evas_Object *obj);
|
||||
EAPI void elm_spinner_wrap_set(Evas_Object *obj, Eina_Bool wrap);
|
||||
EAPI Eina_Bool elm_spinner_wrap_get(const Evas_Object *obj);
|
||||
EAPI void elm_spinner_editable_set(Evas_Object *obj, Eina_Bool editable);
|
||||
EAPI Eina_Bool elm_spinner_editable_get(const Evas_Object *obj);
|
||||
EAPI void elm_spinner_special_value_add(Evas_Object *obj, double value, const char *label);
|
||||
/* smart callbacks called:
|
||||
* "changed" - when the spinner value changes
|
||||
* "delay,changed" - when the spinner value changed, but a small time after a change (use this if you only want to respond to a change once the spinner is held still for a short while).
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
* expensive reactions to the value change.
|
||||
*/
|
||||
typedef struct _Widget_Data Widget_Data;
|
||||
typedef struct _Elm_Spinner_Special_Value Elm_Spinner_Special_Value;
|
||||
|
||||
struct _Widget_Data
|
||||
{
|
||||
|
@ -31,9 +32,16 @@ struct _Widget_Data
|
|||
double val, val_min, val_max, orig_val, step;
|
||||
double drag_start_pos, spin_speed, interval;
|
||||
Ecore_Timer *delay, *spin;
|
||||
Eina_List *special_values;
|
||||
Eina_Bool wrap : 1;
|
||||
Eina_Bool entry_visible : 1;
|
||||
Eina_Bool dragging : 1;
|
||||
Eina_Bool editable : 1;
|
||||
};
|
||||
|
||||
struct _Elm_Spinner_Special_Value {
|
||||
double value;
|
||||
const char *label;
|
||||
};
|
||||
|
||||
static const char *widtype = NULL;
|
||||
|
@ -47,10 +55,17 @@ static Eina_Bool _value_set(Evas_Object *obj, double delta);
|
|||
static void
|
||||
_del_hook(Evas_Object *obj)
|
||||
{
|
||||
Elm_Spinner_Special_Value *sv;
|
||||
Widget_Data *wd = elm_widget_data_get(obj);
|
||||
if (!wd) return;
|
||||
if (wd->label) eina_stringshare_del(wd->label);
|
||||
if (wd->delay) ecore_timer_del(wd->delay);
|
||||
if (wd->special_values)
|
||||
EINA_LIST_FREE(wd->special_values, sv)
|
||||
{
|
||||
eina_stringshare_del(sv->label);
|
||||
free(sv);
|
||||
}
|
||||
free(wd);
|
||||
}
|
||||
|
||||
|
@ -135,13 +150,23 @@ _entry_show(Widget_Data *wd)
|
|||
static void
|
||||
_write_label(Evas_Object *obj)
|
||||
{
|
||||
Eina_List *l;
|
||||
Elm_Spinner_Special_Value *sv;
|
||||
Widget_Data *wd = elm_widget_data_get(obj);
|
||||
char buf[1024];
|
||||
if (!wd) return;
|
||||
EINA_LIST_FOREACH(wd->special_values, l, sv)
|
||||
if (sv->value == wd->val)
|
||||
{
|
||||
snprintf(buf, sizeof(buf), "%s", sv->label);
|
||||
goto apply;
|
||||
}
|
||||
if (wd->label)
|
||||
snprintf(buf, sizeof(buf), wd->label, wd->val);
|
||||
else
|
||||
snprintf(buf, sizeof(buf), "%.0f", wd->val);
|
||||
|
||||
apply:
|
||||
edje_object_part_text_set(wd->spinner, "elm.text", buf);
|
||||
if (wd->entry_visible) _entry_show(wd);
|
||||
}
|
||||
|
@ -295,6 +320,7 @@ _toggle_entry(void *data, Evas_Object *obj __UNUSED__, const char *emission __UN
|
|||
return;
|
||||
}
|
||||
if (elm_widget_disabled_get(data)) return;
|
||||
if (!wd->editable) return;
|
||||
if (wd->entry_visible) _apply_entry_value(data);
|
||||
else
|
||||
{
|
||||
|
@ -472,6 +498,7 @@ elm_spinner_add(Evas_Object *parent)
|
|||
wd->wrap = 0;
|
||||
wd->step = 1.0;
|
||||
wd->entry_visible = 0;
|
||||
wd->editable = EINA_TRUE;
|
||||
|
||||
wd->spinner = edje_object_add(e);
|
||||
_elm_theme_set(wd->spinner, "spinner", "base", "default");
|
||||
|
@ -710,3 +737,62 @@ elm_spinner_wrap_get(const Evas_Object *obj)
|
|||
if (!wd) return EINA_FALSE;
|
||||
return wd->wrap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a special value to display in the place of the numerical one.
|
||||
*
|
||||
* @param obj The spinner object
|
||||
* @param value The value to be replaced
|
||||
* @param label The label to be used
|
||||
*
|
||||
* @ingroup Spinner
|
||||
*/
|
||||
EAPI void
|
||||
elm_spinner_special_value_add(Evas_Object *obj, double value, const char *label)
|
||||
{
|
||||
Elm_Spinner_Special_Value *sv;
|
||||
ELM_CHECK_WIDTYPE(obj, widtype);
|
||||
Widget_Data *wd = elm_widget_data_get(obj);
|
||||
if (!wd) return;
|
||||
|
||||
sv = calloc(1, sizeof(*sv));
|
||||
if (!sv) return;
|
||||
sv->value = value;
|
||||
sv->label = eina_stringshare_add(label);
|
||||
|
||||
wd->special_values = eina_list_append(wd->special_values, sv);
|
||||
_write_label(obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether the spinner can be directly edited by the user or not.
|
||||
* Default is editable.
|
||||
*
|
||||
* @param obj The spinner object
|
||||
* @param editable Bool value of the edit option
|
||||
* (EINA_FALSE = not editable, EINA_TRUE = editable)
|
||||
*/
|
||||
EAPI void
|
||||
elm_spinner_editable_set(Evas_Object *obj, Eina_Bool editable)
|
||||
{
|
||||
ELM_CHECK_WIDTYPE(obj, widtype);
|
||||
Widget_Data *wd = elm_widget_data_get(obj);
|
||||
if (!wd) return;
|
||||
wd->editable = editable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether the spinner is editable.
|
||||
*
|
||||
* @param obj The spinner object
|
||||
* @return Bool value of edit option
|
||||
* (EINA_FALSE = not editable, EINA_TRUE = editable)
|
||||
*/
|
||||
EAPI Eina_Bool
|
||||
elm_spinner_editable_get(const Evas_Object *obj)
|
||||
{
|
||||
ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
|
||||
Widget_Data *wd = elm_widget_data_get(obj);
|
||||
if (!wd) return EINA_FALSE;
|
||||
return wd->editable;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue