diff options
author | Amitesh Singh <amitesh.sh@samsung.com> | 2018-01-17 15:52:58 +0900 |
---|---|---|
committer | Amitesh Singh <amitesh.sh@samsung.com> | 2018-01-31 17:17:31 +0900 |
commit | cc4595fd977fa7c7efee8c28a27093614cd621dd (patch) | |
tree | b4d6792f85ee10003eb5ddeac439e3fd100e11ab | |
parent | 959571b9955babc40367cf3a634dddba7a7cdcc2 (diff) | |
download | efl-devs/ami/pb_test.tar.gz |
Efl.Ui.Progressbar: implement range min maxdevs/ami/pb_test
-rw-r--r-- | po/POTFILES.in | 1 | ||||
-rw-r--r-- | src/Makefile_Elementary.am | 1 | ||||
-rw-r--r-- | src/bin/elementary/test.c | 2 | ||||
-rw-r--r-- | src/bin/elementary/test_ui_progressbar.c | 171 | ||||
-rw-r--r-- | src/lib/elementary/efl_ui_progressbar.c | 93 | ||||
-rw-r--r-- | src/lib/elementary/efl_ui_progressbar.eo | 1 | ||||
-rw-r--r-- | src/lib/elementary/efl_ui_progressbar_part.eo | 1 | ||||
-rw-r--r-- | src/lib/elementary/efl_ui_progressbar_private.h | 4 |
8 files changed, 268 insertions, 6 deletions
diff --git a/po/POTFILES.in b/po/POTFILES.in index 925b2952cf..425f35c5ad 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -49,6 +49,7 @@ src/bin/elementary/test_panes.c src/bin/elementary/test_photo.c src/bin/elementary/test_photocam.c src/bin/elementary/test_progressbar.c +src/bin/elementary/test_ui_progressbar.c src/bin/elementary/test_radio.c src/bin/elementary/test_scaling.c src/bin/elementary/test_scroller.c diff --git a/src/Makefile_Elementary.am b/src/Makefile_Elementary.am index b080c61f87..2325140ac7 100644 --- a/src/Makefile_Elementary.am +++ b/src/Makefile_Elementary.am @@ -928,6 +928,7 @@ bin/elementary/test_photocam.c \ bin/elementary/test_popup.c \ bin/elementary/test_prefs.c \ bin/elementary/test_progressbar.c \ +bin/elementary/test_ui_progressbar.c \ bin/elementary/test_radio.c \ bin/elementary/test_scaling.c \ bin/elementary/test_scroller.c \ diff --git a/src/bin/elementary/test.c b/src/bin/elementary/test.c index 1f75b930cb..74902ffcb3 100644 --- a/src/bin/elementary/test.c +++ b/src/bin/elementary/test.c @@ -169,6 +169,7 @@ void test_win_state2(void *data, Evas_Object *obj, void *event_info); void test_win_stack(void *data, Evas_Object *obj, void *event_info); void test_progressbar(void *data, Evas_Object *obj, void *event_info); void test_progressbar2(void *data, Evas_Object *obj, void *event_info); +void test_ui_progressbar(void *data, Evas_Object *obj, void *event_info); void test_fileselector(void *data, Evas_Object *obj, void *event_info); void test_separator(void *data, Evas_Object *obj, void *event_info); void test_scroller(void *data, Evas_Object *obj, void *event_info); @@ -1041,6 +1042,7 @@ add_tests: ADD_TEST(NULL, "Range Values", "Slider", test_slider); ADD_TEST(NULL, "Range Values", "Progressbar", test_progressbar); ADD_TEST(NULL, "Range Values", "Progressbar 2", test_progressbar2); + ADD_TEST_EO(NULL, "Range Values", "Efl.Ui.Progressbar", test_ui_progressbar); ADD_TEST_EO(NULL, "Range Values", "Efl.Ui.Nstate", test_nstate); ADD_TEST_EO(NULL, "Range Values", "Efl.Ui.Slider_Interval", test_slider_interval); ADD_TEST_EO(NULL, "Range Values", "Efl.Ui.Slider", test_ui_slider); diff --git a/src/bin/elementary/test_ui_progressbar.c b/src/bin/elementary/test_ui_progressbar.c new file mode 100644 index 0000000000..509969e83f --- /dev/null +++ b/src/bin/elementary/test_ui_progressbar.c @@ -0,0 +1,171 @@ +#ifdef HAVE_CONFIG_H +# include "elementary_config.h" +#endif +#include <Elementary.h> + +typedef struct _pbdata +{ + Eo *win; + Eo *pb1; + Eo *pb2; + Eo *btn_start; + Eo *btn_stop; + Eo *btn_reset; + Ecore_Timer *timer; +} pbdata; + +static Eina_Bool +_set_progress_val(Eo *pb, double inc_value) +{ + double progress; + + progress = efl_ui_range_value_get(pb); + + if (progress < 100.0) + progress += inc_value; + else + return EINA_TRUE; + + efl_ui_range_value_set(pb, progress); + + return EINA_FALSE; +} + +static Eina_Bool +_pb_timer_cb(void *d) +{ + pbdata *pd = d; + double progress_val; + + if (!pd) return ECORE_CALLBACK_CANCEL; + + progress_val = efl_ui_range_value_get(pd->pb1); + if (progress_val < 100.0) + { + progress_val += 1; + efl_ui_range_value_set(pd->pb2, progress_val); + } + + if (!_set_progress_val(pd->pb1, 0.14)) + return ECORE_CALLBACK_RENEW; + + pd->timer = NULL; + return ECORE_CALLBACK_CANCEL; +} + +static void +_start_btn_clicked_cb(void *d, const Efl_Event *ev EINA_UNUSED) +{ + pbdata *pd = d; + + if (!pd) return; + + printf("start button is clicked\n"); + + efl_ui_widget_disabled_set(pd->btn_start, EINA_TRUE); + efl_ui_widget_disabled_set(pd->btn_stop, EINA_FALSE); + + if (!pd->timer) pd->timer = ecore_timer_add(0.1, _pb_timer_cb, pd); +} + +static void +_stop_btn_clicked_cb(void *d, const Efl_Event *ev EINA_UNUSED) +{ + pbdata *pd = d; + + if (!pd) return; + printf("stop button is clicked\n"); + + efl_ui_widget_disabled_set(pd->btn_start, EINA_FALSE); + efl_ui_widget_disabled_set(pd->btn_stop, EINA_TRUE); + + if (pd->timer) + { + ecore_timer_del(pd->timer); + pd->timer = NULL; + } +} + +static void +_reset_btn_clicked_cb(void *d, const Efl_Event *ev EINA_UNUSED) +{ + pbdata *pd = d; + + if (!pd) return; + printf("reset button is clicked\n"); + + efl_ui_range_value_set(pd->pb1, 0.0); + efl_ui_range_value_set(pd->pb2, 0.0); +} + +static void +_win_delete_req_cb(void *d, const Efl_Event *ev EINA_UNUSED) +{ + pbdata *pd = d; + + if (pd->timer) ecore_timer_del(pd->timer); + efl_del(pd->win); + free(pd); +} + +void +test_ui_progressbar(void *data EINA_UNUSED, Eo *obj EINA_UNUSED, void *event_info EINA_UNUSED) +{ + Eo *win, *bx, *btbx; + pbdata *pd; + + pd = (pbdata *)calloc(1, sizeof(pbdata)); + + pd->win = win = efl_add(EFL_UI_WIN_CLASS, NULL, + efl_ui_win_type_set(efl_added, EFL_UI_WIN_BASIC), + efl_text_set(efl_added, "Efl.Ui.Progressbar"), + efl_ui_win_autodel_set(efl_added, EINA_TRUE), + efl_event_callback_add(efl_added, EFL_UI_WIN_EVENT_DELETE_REQUEST, + _win_delete_req_cb, pd) + ); + + bx = efl_add(EFL_UI_BOX_CLASS, win, + efl_content_set(win, efl_added) + ); + + pd->pb1 = efl_add(EFL_UI_PROGRESSBAR_CLASS, bx, + efl_pack(bx, efl_added), + efl_text_set(efl_added, "percent"), + efl_ui_range_min_max_set(efl_added, 0, 100), + efl_gfx_size_hint_min_set(efl_added, EINA_SIZE2D(250, 20)) + ); + + pd->pb2 = efl_add(EFL_UI_PROGRESSBAR_CLASS, bx, + efl_pack(bx, efl_added), + efl_text_set(efl_added, "10-100"), + efl_ui_progressbar_pulse_set(efl_added, EINA_TRUE), + efl_gfx_size_hint_min_set(efl_added, EINA_SIZE2D(250, 20)), + efl_ui_range_min_max_set(efl_added, 10, 100), + efl_ui_range_value_set(efl_added, 10) + ); + + btbx = efl_add(EFL_UI_BOX_CLASS, bx, + efl_pack(bx, efl_added), + efl_ui_direction_set(efl_added, EFL_UI_DIR_HORIZONTAL) + ); + + pd->btn_start = efl_add(EFL_UI_BUTTON_CLASS, btbx, + efl_text_set(efl_added, "start"), + efl_event_callback_add(efl_added, EFL_UI_EVENT_CLICKED, + _start_btn_clicked_cb, pd), + efl_pack(btbx, efl_added) + ); + + pd->btn_stop = efl_add(EFL_UI_BUTTON_CLASS, btbx, + efl_text_set(efl_added, "stop"), + efl_event_callback_add(efl_added, EFL_UI_EVENT_CLICKED, + _stop_btn_clicked_cb, pd), + efl_pack(btbx, efl_added) + ); + pd->btn_reset = efl_add(EFL_UI_BUTTON_CLASS, btbx, + efl_text_set(efl_added, "reset"), + efl_event_callback_add(efl_added, EFL_UI_EVENT_CLICKED, + _reset_btn_clicked_cb, pd), + efl_pack(btbx, efl_added) + ); +} diff --git a/src/lib/elementary/efl_ui_progressbar.c b/src/lib/elementary/efl_ui_progressbar.c index 0ecaed2a0b..9ab3e32de6 100644 --- a/src/lib/elementary/efl_ui_progressbar.c +++ b/src/lib/elementary/efl_ui_progressbar.c @@ -115,6 +115,8 @@ _units_set(Evas_Object *obj) // Keeping this bug since the legacy code was like that. if (sd->is_legacy_format_string && !sd->is_legacy_format_cb) eina_value_set(&val, 100 * sd->val); + else + eina_value_set(&val, sd->val); eina_strbuf_reset(sd->format_strbuf); sd->format_cb(sd->format_cb_data, sd->format_strbuf, val); @@ -141,7 +143,8 @@ _val_set(Evas_Object *obj) EINA_LIST_FOREACH(sd->progress_status, l, ps) { - pos = ps->val; + pos = (ps->val - ps->val_min)/(ps->val_max - ps->val_min); + if ((!rtl && _is_inverted(sd->dir)) || (rtl && ((sd->dir == EFL_UI_DIR_UP) || (sd->dir == EFL_UI_DIR_RIGHT)))) @@ -362,7 +365,7 @@ _efl_ui_progressbar_efl_canvas_group_group_add(Eo *obj, Efl_Ui_Progressbar_Data priv->dir = EFL_UI_DIR_RIGHT; priv->val = MIN_RATIO_LVL; - + priv->val_max = 1.0; group = _efl_ui_progressbar_theme_group_get(obj, priv); if (!elm_widget_theme_object_set(obj, wd->resize_obj, @@ -479,14 +482,49 @@ _progressbar_span_size_set(Eo *obj, Efl_Ui_Progressbar_Data *sd, Evas_Coord size } static void +_progress_part_min_max_set(Efl_Ui_Progressbar_Data *sd, const char *part_name, double min, double max) +{ + Efl_Ui_Progress_Status *ps; + Eina_Bool existing_ps = EINA_FALSE; + Eina_List *l; + + if (!strcmp(part_name, "elm.cur.progressbar")) + { + sd->val_min = min; + sd->val_max = max; + } + + EINA_LIST_FOREACH(sd->progress_status, l, ps) + { + if (!strcmp(ps->part_name, part_name)) + { + existing_ps = EINA_TRUE; + ps->val_min = min; + ps->val_max = max; + break; + } + } + if (!existing_ps) + { + ps = _progress_status_new(part_name, min); + ps->val_min = min; + ps->val_max = max; + sd->progress_status = eina_list_append(sd->progress_status, ps); + } +} + +static void _progressbar_part_value_set(Eo *obj, Efl_Ui_Progressbar_Data *sd, const char *part_name, double val) { Efl_Ui_Progress_Status *ps; Eina_Bool existing_ps = EINA_FALSE; Eina_List *l; + double min, max; + + efl_ui_range_min_max_get(efl_part(obj, part_name), &min, &max); - if (val < MIN_RATIO_LVL) val = MIN_RATIO_LVL; - if (val > MAX_RATIO_LVL) val = MAX_RATIO_LVL; + if (val < min) val = min; + if (val > max) val = max; if (!strcmp(part_name, "elm.cur.progressbar")) sd->val = val; @@ -503,6 +541,8 @@ _progressbar_part_value_set(Eo *obj, Efl_Ui_Progressbar_Data *sd, const char *pa if (!existing_ps) { ps = _progress_status_new(part_name, val); + ps->val_min = 0.0; + ps->val_max = 1.0; sd->progress_status = eina_list_append(sd->progress_status, ps); } else @@ -537,9 +577,9 @@ _efl_ui_progressbar_efl_ui_range_range_value_set(Eo *obj, Efl_Ui_Progressbar_Dat } EOLIAN static double -_efl_ui_progressbar_efl_ui_range_range_value_get(Eo *obj EINA_UNUSED, Efl_Ui_Progressbar_Data *sd) +_efl_ui_progressbar_efl_ui_range_range_value_get(Eo *obj, Efl_Ui_Progressbar_Data *sd EINA_UNUSED) { - return sd->val; + return efl_ui_range_value_get(efl_part(obj, "elm.cur.progressbar")); } EOLIAN static void @@ -586,6 +626,19 @@ _efl_ui_progressbar_pulse_get(Eo *obj EINA_UNUSED, Efl_Ui_Progressbar_Data *sd) } EOLIAN static void +_efl_ui_progressbar_efl_ui_range_range_min_max_set(Eo *obj EINA_UNUSED, Efl_Ui_Progressbar_Data *sd, double min, double max) +{ + _progress_part_min_max_set(sd, "elm.cur.progressbar", min, max); +} + +EOLIAN static void +_efl_ui_progressbar_efl_ui_range_range_min_max_get(Eo *obj EINA_UNUSED, Efl_Ui_Progressbar_Data *sd, double *min, double *max) +{ + if (min) *min = sd->val_min; + if (max) *max = sd->val_max; +} + +EOLIAN static void _efl_ui_progressbar_class_constructor(Efl_Class *klass) { evas_smart_legacy_type_register(MY_CLASS_NAME_LEGACY, klass); @@ -630,6 +683,34 @@ _efl_ui_progressbar_efl_access_value_value_and_text_get(Eo *obj EINA_UNUSED, Efl if (value) *value = _pd->val; } +EOLIAN static void +_efl_ui_progressbar_part_efl_ui_range_range_min_max_set(Eo *obj, void *_pd EINA_UNUSED, double min, double max) +{ + Elm_Part_Data *pd = efl_data_scope_get(obj, EFL_UI_WIDGET_PART_CLASS); + Efl_Ui_Progressbar_Data *sd = efl_data_scope_get(pd->obj, EFL_UI_PROGRESSBAR_CLASS); + + _progress_part_min_max_set(sd, pd->part, min, max); +} + +EOLIAN static void +_efl_ui_progressbar_part_efl_ui_range_range_min_max_get(Eo *obj, void *_pd EINA_UNUSED, double *min, double *max) +{ + Efl_Ui_Progress_Status *ps; + Eina_List *l; + + Elm_Part_Data *pd = efl_data_scope_get(obj, EFL_UI_WIDGET_PART_CLASS); + Efl_Ui_Progressbar_Data *sd = efl_data_scope_get(pd->obj, EFL_UI_PROGRESSBAR_CLASS); + + EINA_LIST_FOREACH(sd->progress_status, l, ps) + { + if (!strcmp(ps->part_name, pd->part)) + { + if (min) *min = ps->val_min; + if (max) *max = ps->val_max; + break; + } + } +} #include "efl_ui_progressbar_part.eo.c" /* Efl.Part end */ diff --git a/src/lib/elementary/efl_ui_progressbar.eo b/src/lib/elementary/efl_ui_progressbar.eo index 3100b90ec0..d58c764772 100644 --- a/src/lib/elementary/efl_ui_progressbar.eo +++ b/src/lib/elementary/efl_ui_progressbar.eo @@ -55,6 +55,7 @@ class Efl.Ui.Progressbar (Efl.Ui.Layout, Efl.Ui.Range, Efl.Ui.Format, Efl.Ui.Widget.widget_sub_object_add; Efl.Ui.Widget.widget_sub_object_del; Efl.Ui.Range.range_value { get; set; } + Efl.Ui.Range.range_min_max {get; set; } Efl.Ui.Direction.direction { get; set; } Efl.Ui.Format.format_cb { set; } Efl.Part.part; diff --git a/src/lib/elementary/efl_ui_progressbar_part.eo b/src/lib/elementary/efl_ui_progressbar_part.eo index a57bfa7cdc..f1d2515c96 100644 --- a/src/lib/elementary/efl_ui_progressbar_part.eo +++ b/src/lib/elementary/efl_ui_progressbar_part.eo @@ -4,5 +4,6 @@ class Efl.Ui.Progressbar.Part (Efl.Ui.Layout.Part, Efl.Ui.Range) data: null; implements { Efl.Ui.Range.range_value { set; get; } + Efl.Ui.Range.range_min_max {get; set; } } } diff --git a/src/lib/elementary/efl_ui_progressbar_private.h b/src/lib/elementary/efl_ui_progressbar_private.h index c9b0c9b11f..7bdf8a98a0 100644 --- a/src/lib/elementary/efl_ui_progressbar_private.h +++ b/src/lib/elementary/efl_ui_progressbar_private.h @@ -32,6 +32,9 @@ struct _Efl_Ui_Progressbar_Data Evas_Coord size; /**< Width or height of progressbar */ double val; /**< Value of progressbar */ + + double val_min; + double val_max; Eina_List *progress_status; /**< The list of _Elm_Progress_Status. To save the progress value(in percentage) each part of given progress bar */ @@ -52,6 +55,7 @@ struct _Efl_Ui_Progress_Status { const char *part_name; double val; + double val_min, val_max; }; /** |