diff options
-rw-r--r-- | src/Makefile_Elementary.am | 1 | ||||
-rw-r--r-- | src/bin/elementary/test_ui_slider_interval.c | 13 | ||||
-rw-r--r-- | src/lib/efl/interfaces/efl_ui_format.c | 2 | ||||
-rw-r--r-- | src/lib/elementary/efl_ui_slider.c | 202 | ||||
-rw-r--r-- | src/lib/elementary/efl_ui_slider.eo | 47 | ||||
-rw-r--r-- | src/lib/elementary/efl_ui_slider_part.eo | 9 | ||||
-rw-r--r-- | src/lib/elementary/efl_ui_slider_private.h | 12 | ||||
-rw-r--r-- | src/lib/elementary/elm_slider_legacy.h | 52 |
8 files changed, 214 insertions, 124 deletions
diff --git a/src/Makefile_Elementary.am b/src/Makefile_Elementary.am index ea0e6bcf55..1c41f580f7 100644 --- a/src/Makefile_Elementary.am +++ b/src/Makefile_Elementary.am @@ -57,6 +57,7 @@ elm_public_eolian_files = \ lib/elementary/efl_ui_multibuttonentry_part.eo \ lib/elementary/efl_ui_panes_part.eo \ lib/elementary/efl_ui_progressbar_part.eo \ + lib/elementary/efl_ui_slider_part.eo \ lib/elementary/efl_ui_textpath_part.eo \ lib/elementary/efl_ui_widget_part.eo \ lib/elementary/efl_ui_win_part.eo \ diff --git a/src/bin/elementary/test_ui_slider_interval.c b/src/bin/elementary/test_ui_slider_interval.c index 518528e813..ebd3d3de5e 100644 --- a/src/bin/elementary/test_ui_slider_interval.c +++ b/src/bin/elementary/test_ui_slider_interval.c @@ -44,7 +44,7 @@ test_slider_interval(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void efl_text_set(efl_added, "Horizontal"), efl_ui_slider_indicator_visible_mode_set(efl_added, EFL_UI_SLIDER_INDICATOR_VISIBLE_MODE_NONE), efl_gfx_size_hint_min_set(efl_added, EINA_SIZE2D(160, 0)), - efl_ui_slider_indicator_format_set(efl_added, "%1.5f"), + efl_ui_format_string_set(efl_part(efl_added, "indicator"), "%1.5f"), efl_ui_slider_interval_value_set(efl_added, 0.4, 0.9), efl_pack(bx, efl_added)); @@ -53,7 +53,7 @@ test_slider_interval(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void efl_text_set(efl_added, "Manual step"), efl_gfx_size_hint_min_set(efl_added, EINA_SIZE2D(120, 0)), efl_ui_format_string_set(efl_added, "%1.1f units"), - efl_ui_slider_indicator_format_set(efl_added, "%1.1f"), + efl_ui_format_string_set(efl_part(efl_added, "indicator"), "%1.1f"), efl_ui_slider_interval_value_set(efl_added, 0.4, 0.9), efl_ui_slider_step_set(efl_added, step), efl_pack(bx, efl_added)); @@ -62,7 +62,7 @@ test_slider_interval(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void efl_text_set(efl_added, "Disabled"), efl_gfx_size_hint_min_set(efl_added, EINA_SIZE2D(120, 0)), efl_ui_format_string_set(efl_added, "%1.0f units"), - efl_ui_slider_indicator_format_set(efl_added, "%1.0f"), + efl_ui_format_string_set(efl_part(efl_added, "indicator"), "%1.0f"), efl_ui_range_min_max_set(efl_added, 10, 145), efl_ui_slider_interval_value_set(efl_added, 50, 100), efl_ui_slider_step_set(efl_added, step), @@ -77,7 +77,7 @@ test_slider_interval(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void efl_text_set(efl_added, "Vertical"), efl_gfx_size_hint_min_set(efl_added, EINA_SIZE2D(0, 160)), efl_ui_format_string_set(efl_added, "%1.0f units"), - efl_ui_slider_indicator_format_set(efl_added, "%1.0f"), + efl_ui_format_string_set(efl_part(efl_added, "indicator"), "%1.0f"), efl_ui_range_min_max_set(efl_added, 10, 145), efl_ui_slider_interval_value_set(efl_added, 50, 100), efl_ui_slider_step_set(efl_added, step), @@ -88,9 +88,8 @@ test_slider_interval(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void efl_text_set(efl_added, "Disabled"), efl_gfx_size_hint_min_set(efl_added, EINA_SIZE2D(0, 160)), efl_ui_format_string_set(efl_added, "%1.0f units"), - efl_ui_slider_indicator_format_set(efl_added, "%1.0f"), + efl_ui_format_string_set(efl_part(efl_added, "indicator"), "%1.0f"), efl_ui_range_min_max_set(efl_added, 10, 145), - efl_ui_slider_interval_value_set(efl_added, 50, 100), efl_ui_slider_step_set(efl_added, step), efl_ui_direction_set(efl_added, EFL_UI_DIR_VERTICAL), elm_object_disabled_set(efl_added, EINA_TRUE), @@ -101,7 +100,7 @@ test_slider_interval(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void efl_ui_slider_indicator_visible_mode_set(efl_added, EFL_UI_SLIDER_INDICATOR_VISIBLE_MODE_ON_FOCUS), efl_gfx_size_hint_min_set(efl_added, EINA_SIZE2D(260, 0)), efl_ui_format_string_set(efl_added, "%1.0f units"), - efl_ui_slider_indicator_format_set(efl_added, "%1.0f"), + efl_ui_format_string_set(efl_part(efl_added, "indicator"), "%1.0f"), efl_ui_range_min_max_set(efl_added, 0, 600), efl_ui_slider_interval_value_set(efl_added, 100, 500), efl_ui_slider_step_set(efl_added, step), diff --git a/src/lib/efl/interfaces/efl_ui_format.c b/src/lib/efl/interfaces/efl_ui_format.c index 6cb64f3913..c0dd9d6b42 100644 --- a/src/lib/efl/interfaces/efl_ui_format.c +++ b/src/lib/efl/interfaces/efl_ui_format.c @@ -38,7 +38,7 @@ _default_format_free_cb(void *data) { Efl_Ui_Format_Data *sd = data; - if (sd->template) + if (sd && sd->template) { eina_stringshare_del(sd->template); sd->template = NULL; diff --git a/src/lib/elementary/efl_ui_slider.c b/src/lib/elementary/efl_ui_slider.c index 919e0b7315..8362b06d24 100644 --- a/src/lib/elementary/efl_ui_slider.c +++ b/src/lib/elementary/efl_ui_slider.c @@ -12,6 +12,8 @@ #include "elm_priv.h" #include "efl_ui_slider_private.h" #include "elm_widget_layout.h" + +#include "efl_ui_slider_part.eo.h" #include "elm_part_helper.h" #define MY_CLASS EFL_UI_SLIDER_CLASS @@ -260,54 +262,35 @@ _indicator_set(Evas_Object *obj) { EFL_UI_SLIDER_DATA_GET(obj, sd); - if (sd->indicator_format_func) - { - char *buf; + Eina_Value val; + const char *str; - buf = sd->indicator_format_func(sd->val); - elm_layout_text_set(obj, "elm.indicator", buf); - elm_layout_text_set(obj, "elm.dragable.slider:elm.indicator", buf); - if (sd->popup) - edje_object_part_text_set(sd->popup, "elm.indicator", buf); - if (sd->popup2) - { - if (sd->indicator_format_free) sd->indicator_format_free(buf); - buf = sd->indicator_format_func(sd->intvl_to); - elm_layout_text_set(obj, "elm.dragable2.slider:elm.indicator", buf); - edje_object_part_text_set(sd->popup2, "elm.indicator", buf); - } + if (!sd->indi_format_cb) return; - if (sd->indicator_format_free) sd->indicator_format_free(buf); - } - else if (sd->indicator) - { - char buf[1024]; + eina_value_setup(&val, EINA_VALUE_TYPE_DOUBLE); + eina_strbuf_reset(sd->indi_format_strbuf); - snprintf(buf, sizeof(buf), sd->indicator, sd->val); - elm_layout_text_set(obj, "elm.indicator", buf); - elm_layout_text_set(obj, "elm.dragable.slider:elm.indicator", buf); - if (sd->popup) - edje_object_part_text_set(sd->popup, "elm.indicator", buf); - if (sd->popup2) - { - memset(buf, 0, 1024); - snprintf(buf, sizeof(buf), sd->indicator, sd->intvl_to); - elm_layout_text_set(obj, "elm.dragable2.slider:elm.indicator", buf); - edje_object_part_text_set(sd->popup2, "elm.indicator", buf); - } - } - else + eina_value_set(&val, sd->val); + sd->indi_format_cb(sd->indi_format_cb_data, sd->indi_format_strbuf, val); + + str = eina_strbuf_string_get(sd->indi_format_strbuf); + + elm_layout_text_set(obj, "elm.indicator", str); + elm_layout_text_set(obj, "elm.dragable.slider:elm.indicator", str); + if (sd->popup) + edje_object_part_text_set(sd->popup, "elm.indicator", str); + + if (sd->popup2) { - elm_layout_text_set(obj, "elm.indicator", NULL); - elm_layout_text_set(obj, "elm.dragable.slider:elm.indicator", NULL); - if (sd->popup) - edje_object_part_text_set(sd->popup, "elm.indicator", NULL); - if (sd->popup2) - { - elm_layout_text_set(obj, "elm.dragable2.slider:elm.indicator", NULL); - edje_object_part_text_set(sd->popup2, "elm.indicator", NULL); - } + eina_strbuf_reset(sd->indi_format_strbuf); + eina_value_set(&val, sd->intvl_to); + sd->indi_format_cb(sd->indi_format_cb_data, sd->indi_format_strbuf, val); + str = eina_strbuf_string_get(sd->indi_format_strbuf); + elm_layout_text_set(obj, "elm.dragable2.slider:elm.indicator", str); + edje_object_part_text_set(sd->popup2, "elm.indicator", str); } + + eina_value_flush(&val); } static void @@ -1171,12 +1154,14 @@ _efl_ui_slider_efl_canvas_group_group_add(Eo *obj, Efl_Ui_Slider_Data *priv) EOLIAN static void _efl_ui_slider_efl_canvas_group_group_del(Eo *obj, Efl_Ui_Slider_Data *sd) { - eina_stringshare_del(sd->indicator); ecore_timer_del(sd->delay); ecore_timer_del(sd->wheel_indicator_timer); evas_object_del(sd->popup); evas_object_del(sd->popup2); + ELM_SAFE_FREE(sd->indi_template, eina_stringshare_del); + eina_strbuf_free(sd->indi_format_strbuf); + efl_ui_format_cb_set(obj, NULL, NULL, NULL); eina_strbuf_free(sd->format_strbuf); @@ -1209,19 +1194,6 @@ _efl_ui_slider_efl_ui_direction_direction_get(Eo *obj EINA_UNUSED, Efl_Ui_Slider } EOLIAN static void -_efl_ui_slider_indicator_format_set(Eo *obj, Efl_Ui_Slider_Data *sd, const char *indicator) -{ - eina_stringshare_replace(&sd->indicator, indicator); - evas_object_smart_changed(obj); -} - -EOLIAN static const char* -_efl_ui_slider_indicator_format_get(Eo *obj EINA_UNUSED, Efl_Ui_Slider_Data *sd) -{ - return sd->indicator; -} - -EOLIAN static void _efl_ui_slider_efl_ui_range_range_min_max_set(Eo *obj, Efl_Ui_Slider_Data *sd, double min, double max) { if ((sd->val_min == min) && (sd->val_max == max)) return; @@ -1260,14 +1232,6 @@ _efl_ui_slider_efl_ui_range_range_value_get(Eo *obj EINA_UNUSED, Efl_Ui_Slider_D } EOLIAN static void -_efl_ui_slider_indicator_format_function_set(Eo *obj, Efl_Ui_Slider_Data *sd, slider_func_type func, slider_freefunc_type free_func) -{ - sd->indicator_format_func = func; - sd->indicator_format_free = free_func; - evas_object_smart_changed(obj); -} - -EOLIAN static void _efl_ui_slider_indicator_show_set(Eo *obj, Efl_Ui_Slider_Data *sd, Eina_Bool show) { if (show) @@ -1477,6 +1441,89 @@ _slider_span_size_set(Eo *obj, Efl_Ui_Slider_Data *sd, int size) evas_object_smart_changed(obj); } +/* Efl.Part begin */ + +EOLIAN static Eo * +_efl_ui_slider_efl_part_part(const Eo *obj, Efl_Ui_Slider_Data *sd EINA_UNUSED, const char *part) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(part, NULL); + + if (eina_streq(part, "indicator")) + return ELM_PART_IMPLEMENT(EFL_UI_SLIDER_PART_CLASS, obj, part); + + return efl_part(efl_super(obj, MY_CLASS), part); +} + +EOLIAN static void +_efl_ui_slider_part_efl_ui_format_format_cb_set(Eo *obj, void *_pd EINA_UNUSED, void *func_data, Efl_Ui_Format_Func_Cb func, Eina_Free_Cb func_free_cb) +{ + Elm_Part_Data *pd = efl_data_scope_get(obj, EFL_UI_WIDGET_PART_CLASS); + Efl_Ui_Slider_Data *sd = efl_data_scope_get(pd->obj, EFL_UI_SLIDER_CLASS); + + if (sd->indi_format_cb_data == func_data && sd->indi_format_cb == func) + return; + + if (sd->indi_format_cb_data && sd->indi_format_free_cb) + sd->indi_format_free_cb(sd->format_cb_data); + + sd->indi_format_cb = func; + sd->indi_format_cb_data = func_data; + sd->indi_format_free_cb = func_free_cb; + if (!sd->indi_format_strbuf) sd->indi_format_strbuf = eina_strbuf_new(); + + efl_canvas_group_change(pd->obj); +} + +static void +_indi_default_format_cb(void *data, Eina_Strbuf *str, const Eina_Value value) +{ + const Eina_Value_Type *type = eina_value_type_get(&value); + Efl_Ui_Slider_Data *sd = data; + double v; + + if (type != EINA_VALUE_TYPE_DOUBLE) return; + + eina_value_get(&value, &v); + eina_strbuf_append_printf(str, sd->indi_template, v); +} + +static void +_indi_default_format_free_cb(void *data) +{ + Efl_Ui_Slider_Data *sd = data; + + if (sd && sd->indi_template) + { + eina_stringshare_del(sd->indi_template); + sd->indi_template = NULL; + } +} + +EOLIAN static void +_efl_ui_slider_part_efl_ui_format_format_string_set(Eo *obj, void *_pd EINA_UNUSED, const char *template) +{ + Elm_Part_Data *pd = efl_data_scope_get(obj, EFL_UI_WIDGET_PART_CLASS); + Efl_Ui_Slider_Data *sd = efl_data_scope_get(pd->obj, EFL_UI_SLIDER_CLASS); + + if (!template) return; + eina_stringshare_replace(&sd->indi_template, template); + + efl_ui_format_cb_set(efl_part(pd->obj, "indicator"), sd, _indi_default_format_cb, _indi_default_format_free_cb); +} + +EOLIAN static const char * +_efl_ui_slider_part_efl_ui_format_format_string_get(Eo *obj, void *_pd EINA_UNUSED) +{ + Elm_Part_Data *pd = efl_data_scope_get(obj, EFL_UI_WIDGET_PART_CLASS); + Efl_Ui_Slider_Data *sd = efl_data_scope_get(pd->obj, EFL_UI_SLIDER_CLASS); + + return sd->indi_template; +} + +#include "efl_ui_slider_part.eo.c" + +/* Efl.Part end */ + /* Legacy APIs */ EAPI Evas_Object * @@ -1670,6 +1717,31 @@ elm_slider_min_max_get(const Evas_Object *obj, double *min, double *max) efl_ui_range_min_max_get(obj, min, max); } +EAPI void +elm_slider_indicator_format_set(Evas_Object *obj, const char *indicator) +{ + efl_ui_format_string_set(efl_part(obj, "indicator"), indicator); +} + +EAPI const char * +elm_slider_indicator_format_get(const Evas *obj) +{ + return efl_ui_format_string_get(efl_part(obj, "indicator")); +} + +EAPI void +elm_slider_indicator_format_function_set(Evas_Object *obj, slider_func_type func, slider_freefunc_type free_func) +{ + Slider_Format_Wrapper_Data *sfwd = malloc(sizeof(Slider_Format_Wrapper_Data)); + + sfwd->format_cb = func; + sfwd->format_free_cb = free_func; + + efl_ui_format_cb_set(efl_part(obj, "indicator"), sfwd, + _format_legacy_to_format_eo_cb, + _format_legacy_to_format_eo_free_cb); +} + /* Internal EO APIs and hidden overrides */ ELM_LAYOUT_CONTENT_ALIASES_IMPLEMENT(efl_ui_slider) diff --git a/src/lib/elementary/efl_ui_slider.eo b/src/lib/elementary/efl_ui_slider.eo index 609c3fa258..0368087ffd 100644 --- a/src/lib/elementary/efl_ui_slider.eo +++ b/src/lib/elementary/efl_ui_slider.eo @@ -8,46 +8,12 @@ class Efl.Ui.Slider (Efl.Ui.Layout, Efl.Ui.Range, Efl.Ui.Direction, [[Elementary slider class]] legacy_prefix: elm_slider; methods { - @property indicator_format { - set { - [[Set the format string for the indicator label. - - The slider may display its value somewhere else then unit label, - for example, above the slider knob that is dragged around. This - function sets the format string used for this. - - If $null, indicator label won't be visible. If not it sets the - format string for the label text. To the label text is provided - a floating point value, so the label text can display up to 1 - floating point value. Note that this is optional. - - Use a format string such as "%1.2f meters" for example, and it - will display values like: "3.14 meters" for a value equal to - 3.14159. - - Default is indicator label disabled. - ]] - } - get { - [[Get the indicator label format of the slider. - - The slider may display its value somewhere else then unit label, - for example, above the slider knob that is dragged around. This - function gets the format string used for this. - ]] - } - values { - indicator: string @nullable; [[The format string for the indicator display.]] - } - } @property indicator_show { set { [[Set whether to enlarge slider indicator (augmented knob) or not. By default, indicator will be bigger while dragged by the user. - Warning: It won't display values set with @.indicator_format.set - if you disable indicator. ]] } get { @@ -98,18 +64,6 @@ class Efl.Ui.Slider (Efl.Ui.Layout, Efl.Ui.Range, Efl.Ui.Direction, indicator_visible_mode: Efl.Ui.Slider.Indicator_Visible_Mode; [[The indicator visible mode.]] } } - @property indicator_format_function { - set { - [[Set the format function pointer for the indicator label - - Set the callback function to format the indicator string. - ]] - } - values { - func: slider_func_type @nullable; [[The indicator format function.]] - free_func: slider_freefunc_type @nullable; [[The freeing function for the format string.]] - } - } } implements { class.constructor; @@ -130,6 +84,7 @@ class Efl.Ui.Slider (Efl.Ui.Layout, Efl.Ui.Range, Efl.Ui.Direction, Efl.Text.Markup.markup { get; set; } Efl.Ui.Format.format_cb { set; } Efl.Ui.Translatable.translatable_text { get; set; } + Efl.Part.part; } events { changed; [[Called when slider changed]] diff --git a/src/lib/elementary/efl_ui_slider_part.eo b/src/lib/elementary/efl_ui_slider_part.eo new file mode 100644 index 0000000000..70d81de5a8 --- /dev/null +++ b/src/lib/elementary/efl_ui_slider_part.eo @@ -0,0 +1,9 @@ +class Efl.Ui.Slider.Part (Efl.Ui.Layout.Part, Efl.Ui.Format) +{ + [[Elementary slider internal part class]] + data: null; + implements { + Efl.Ui.Format.format_cb { set; } + Efl.Ui.Format.format_string { set; get; } + } +} diff --git a/src/lib/elementary/efl_ui_slider_private.h b/src/lib/elementary/efl_ui_slider_private.h index d79a1cc6de..c5baa83150 100644 --- a/src/lib/elementary/efl_ui_slider_private.h +++ b/src/lib/elementary/efl_ui_slider_private.h @@ -29,11 +29,6 @@ struct _Efl_Ui_Slider_Data Evas_Object *spacer, *popup, *popup2, *track, *track2; Ecore_Timer *delay; - const char *indicator; - - char *(*indicator_format_func)(double val); - void (*indicator_format_free)(char *str); - double val, val_min, val_max, val2, step; Ecore_Timer *wheel_indicator_timer; @@ -52,6 +47,13 @@ struct _Efl_Ui_Slider_Data void *format_cb_data; Eina_Strbuf *format_strbuf; + Efl_Ui_Format_Func_Cb indi_format_cb; + Eina_Free_Cb indi_format_free_cb; + void *indi_format_cb_data; + Eina_Strbuf *indi_format_strbuf; + const char *indi_template; + + Eina_Bool indicator_show : 1; Eina_Bool spacer_down : 1; Eina_Bool frozen : 1; diff --git a/src/lib/elementary/elm_slider_legacy.h b/src/lib/elementary/elm_slider_legacy.h index 07d29c1cfb..89df6f1bcc 100644 --- a/src/lib/elementary/elm_slider_legacy.h +++ b/src/lib/elementary/elm_slider_legacy.h @@ -231,4 +231,56 @@ EAPI void elm_slider_range_set(Evas_Object *obj, double from, double to); */ EAPI void elm_slider_range_get(const Evas_Object *obj, double *from, double *to); +/** + * @brief Set the format string for the indicator label. + * + * The slider may display its value somewhere else then unit label, for + * example, above the slider knob that is dragged around. This function sets + * the format string used for this. + * + * If @c null, indicator label won't be visible. If not it sets the format + * string for the label text. To the label text is provided a floating point + * value, so the label text can display up to 1 floating point value. Note that + * this is optional. + * + * Use a format string such as "%1.2f meters" for example, and it will display + * values like: "3.14 meters" for a value equal to 3.14159. + * + * Default is indicator label disabled. + * + * @param[in] obj The object. + * @param[in] indicator The format string for the indicator display. + * + * @ingroup Elm_Slider + */ + EAPI void elm_slider_indicator_format_set(Evas_Object *obj, const char *indicator); + + /** + * @brief Get the indicator label format of the slider. + * + * The slider may display its value somewhere else then unit label, for + * example, above the slider knob that is dragged around. This function gets + * the format string used for this. + * + * @param[in] obj The object. + * + * @return The format string for the indicator display. + * + * @ingroup Elm_Slider + */ + EAPI const char *elm_slider_indicator_format_get(const Evas_Object *obj); + + /** + * @brief Set the format function pointer for the indicator label + * + * Set the callback function to format the indicator string. + * + * @param[in] obj The object. + * @param[in] func The indicator format function. + * @param[in] free_func The freeing function for the format string. + * + * @ingroup Elm_Slider + */ +EAPI void elm_slider_indicator_format_function_set(Evas_Object *obj, slider_func_type func, slider_freefunc_type free_func); + #include "efl_ui_slider.eo.legacy.h" |