add rouding+base to spinner - otherwise u can never slow it down and u

cant round to specific values. fixed month test to do this too.



SVN revision: 67982
This commit is contained in:
Carsten Haitzler 2012-02-15 12:32:02 +00:00
parent 70be2f1078
commit b6fd8c353e
3 changed files with 129 additions and 11 deletions

View File

@ -63,9 +63,13 @@ test_spinner(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_inf
evas_object_show(sp);
sp = elm_spinner_add(win);
elm_spinner_wrap_set(sp, EINA_TRUE);
elm_spinner_min_max_set(sp, 1, 12);
elm_spinner_value_set(sp, 1);
elm_spinner_step_set(sp, 0.05);
elm_spinner_base_set(sp, 1);
elm_spinner_round_set(sp, 1);
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");

View File

@ -9,8 +9,9 @@ struct _Widget_Data
{
Evas_Object *spinner, *ent;
const char *label;
double val, val_min, val_max, orig_val, step;
double val, val_min, val_max, orig_val, step, base;
double drag_start_pos, spin_speed, interval, first_interval;
int round;
Ecore_Timer *delay, *spin;
Eina_List *special_values;
Eina_Bool wrap : 1;
@ -210,6 +211,7 @@ _write_label(Evas_Object *obj)
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)
{
@ -230,12 +232,16 @@ apply:
}
static Eina_Bool
_value_set(Evas_Object *obj, double delta)
_value_set(Evas_Object *obj, double new_val)
{
Widget_Data *wd = elm_widget_data_get(obj);
double new_val;
if (!wd) return EINA_FALSE;
new_val = wd->val + delta;
if (wd->round > 0)
new_val = wd->base +
(double)((((int)(new_val - wd->base)) / wd->round) * wd->round);
if (wd->wrap)
{
while (new_val < wd->val_min)
@ -306,13 +312,12 @@ _drag(void *data, Evas_Object *_obj __UNUSED__, const char *emission __UNUSED__,
if (wd->entry_visible) return;
edje_object_part_drag_value_get(wd->spinner, "elm.dragable.slider",
&pos, NULL);
offset = wd->step;
offset = wd->step * _elm_config->scale;
delta = (pos - wd->drag_start_pos) * offset;
/* If we are on rtl mode, change the delta to be negative on such changes */
if (elm_widget_mirrored_get(obj))
delta *= -1;
if (_value_set(data, delta)) _write_label(data);
wd->drag_start_pos = pos;
if (elm_widget_mirrored_get(obj)) delta *= -1;
if (_value_set(data, wd->drag_start_pos + delta)) _write_label(data);
wd->dragging = 1;
}
@ -400,7 +405,7 @@ _spin_value(void *data)
{
Widget_Data *wd = elm_widget_data_get(data);
if (!wd) return ECORE_CALLBACK_CANCEL;
if (_value_set(data, wd->spin_speed)) _write_label(data);
if (_value_set(data, wd->val + wd->spin_speed)) _write_label(data);
wd->interval = wd->interval / 1.05;
ecore_timer_interval_set(wd->spin, wd->interval);
return ECORE_CALLBACK_RENEW;
@ -779,3 +784,39 @@ elm_spinner_interval_get(const Evas_Object *obj)
if (!wd) return 0.0;
return wd->first_interval;
}
EAPI void
elm_spinner_base_set(Evas_Object *obj, double base)
{
ELM_CHECK_WIDTYPE(obj, widtype);
Widget_Data *wd = elm_widget_data_get(obj);
if (!wd) return;
wd->base = base;
}
EAPI double
elm_spinner_base_get(const Evas_Object *obj)
{
ELM_CHECK_WIDTYPE(obj, widtype) 0.0;
Widget_Data *wd = elm_widget_data_get(obj);
if (!wd) return 0.0;
return wd->base;
}
EAPI void
elm_spinner_round_set(Evas_Object *obj, int round)
{
ELM_CHECK_WIDTYPE(obj, widtype);
Widget_Data *wd = elm_widget_data_get(obj);
if (!wd) return;
wd->round = round;
}
EAPI int
elm_spinner_round_get(const Evas_Object *obj)
{
ELM_CHECK_WIDTYPE(obj, widtype) 0;
Widget_Data *wd = elm_widget_data_get(obj);
if (!wd) return 0;
return wd->round;
}

View File

@ -348,6 +348,79 @@ EAPI void elm_spinner_interval_set(Evas_Object *obj, double interval);
*/
EAPI double elm_spinner_interval_get(const Evas_Object *obj);
/**
* Set the base for rounding
*
* @param obj The spinner object
* @param base The base value
*
* Rounding works as follows:
*
* rounded_val = base + (double)(((value - base) / round) * round)
*
* Where rounded_val, value and base are doubles, and round is an integer.
*
* This means that things will be rounded to increments (or decrements) of
* "round" starting from value @p base. The default base for rounding is 0.
*
* Example: round = 3, base = 2
* Values: 3, 6, 9, 12, 15, ...
*
* Example: round = 2, base = 5.5
* Values: 5.5, 7.5, 9.5, 11.5, ...
*
* @see elm_spinner_round_get()
* @see elm_spinner_base_get() too.
*
* @ingroup Spinner
*/
EAPI void elm_spinner_base_set(Evas_Object *obj, double base);
/**
* Get the base for rounding
*
* @param obj The spinner object
* @return The base rounding value
*
* This returns the base for rounding.
*
* @see elm_spinner_round_set() too.
* @see elm_spinner_base_set() too.
*
* @ingroup Spinner
*/
EAPI double elm_spinner_base_get(const Evas_Object *obj);
/**
* Set the round value for rounding
*
* @param obj The spinner object
* @param round The rounding value
*
* Sets the rounding value used for value rounding in the spinner.
*
* @see elm_spinner_round_get()
* @see elm_spinner_base_set()
*
* @ingroup Spinner
*/
EAPI void elm_spinner_round_set(Evas_Object *obj, int round);
/**
* Get the round value for rounding
*
* @param obj The spinner object
* @return The rounding value
*
* This returns the round value for rounding.
*
* @see elm_spinner_round_set() too.
* @see elm_spinner_base_set() too.
*
* @ingroup Spinner
*/
EAPI int elm_spinner_round_get(const Evas_Object *obj);
/**
* @}
*/