From c41b282a0f652397aacc080d7f30a702959a32eb Mon Sep 17 00:00:00 2001 From: Marcel Hollerbach Date: Wed, 20 Nov 2019 16:16:22 +0100 Subject: [PATCH] efl_ui_spotligt: make it possible to freeze animations this new API makes it possible to stop animations beeing executed in the spotlight manager. (The logic in the spotlight managers itself are already implemented). The animation will also be frozen during construction time of the spotlight. --- .../elementary/efl_ui_spotlight_container.c | 31 ++++++++++++++-- .../elementary/efl_ui_spotlight_container.eo | 6 ++++ src/tests/elementary/efl_ui_test_spotlight.c | 35 +++++++++++++++++-- 3 files changed, 67 insertions(+), 5 deletions(-) diff --git a/src/lib/elementary/efl_ui_spotlight_container.c b/src/lib/elementary/efl_ui_spotlight_container.c index f725f4830c..993438c200 100644 --- a/src/lib/elementary/efl_ui_spotlight_container.c +++ b/src/lib/elementary/efl_ui_spotlight_container.c @@ -33,6 +33,8 @@ typedef struct _Efl_Ui_Spotlight_Container_Data Eina_Bool fill_width: 1; Eina_Bool fill_height: 1; Eina_Bool prevent_transition_interaction : 1; + Eina_Bool animation_enabled_internal : 1; + Eina_Bool animation_enabled : 1; } Efl_Ui_Spotlight_Container_Data; #define MY_CLASS EFL_UI_SPOTLIGHT_CONTAINER_CLASS @@ -186,6 +188,7 @@ _efl_ui_spotlight_container_efl_object_constructor(Eo *obj, elm_widget_theme_style_get(obj)) == EFL_UI_THEME_APPLY_ERROR_GENERIC) CRI("Failed to set layout!"); + pd->animation_enabled = EINA_TRUE; pd->position = -1; pd->curr.page = NULL; pd->curr.pos = 0.0; @@ -214,13 +217,19 @@ _efl_ui_spotlight_container_efl_object_constructor(Eo *obj, return obj; } +static void +_animated_transition_manager_eval(Eo *obj EINA_UNUSED, Efl_Ui_Spotlight_Container_Data *pd) +{ + efl_ui_spotlight_manager_animated_transition_set(pd->transition, pd->animation_enabled_internal && pd->animation_enabled); +} + EOLIAN static Efl_Object* -_efl_ui_spotlight_container_efl_object_finalize(Eo *obj, Efl_Ui_Spotlight_Container_Data *pd EINA_UNUSED) +_efl_ui_spotlight_container_efl_object_finalize(Eo *obj, Efl_Ui_Spotlight_Container_Data *pd) { Efl_Ui_Spotlight_Manager *manager; obj = efl_finalize(efl_super(obj, MY_CLASS)); - + pd->animation_enabled_internal = EINA_TRUE; manager = efl_ui_spotlight_manager_get(obj); //set a view manager in case nothing is here if (!manager) @@ -229,7 +238,8 @@ _efl_ui_spotlight_container_efl_object_finalize(Eo *obj, Efl_Ui_Spotlight_Contai } else { - efl_ui_spotlight_manager_animated_transition_set(manager, EINA_TRUE); + + _animated_transition_manager_eval(obj, pd); } return obj; @@ -619,6 +629,7 @@ _efl_ui_spotlight_container_spotlight_manager_set(Eo *obj, Efl_Ui_Spotlight_Cont //the api indicates that the caller passes ownership to this function, so we need to unref here efl_unref(pd->transition); //disable animation when not finalized yet, this help reducing the overhead of scheduling a animation that will not be displayed + _animated_transition_manager_eval(obj, pd); efl_ui_spotlight_manager_animated_transition_set(pd->transition, efl_finalized_get(obj)); efl_ui_spotlight_manager_bind(pd->transition, obj, pd->page_root); @@ -738,5 +749,19 @@ _efl_ui_spotlight_container_pop(Eo *obj, Efl_Ui_Spotlight_Container_Data *pd, Ei return transition_done; } +EOLIAN static void +_efl_ui_spotlight_container_animated_transition_set(Eo *obj, Efl_Ui_Spotlight_Container_Data *pd, Eina_Bool enable) +{ + pd->animation_enabled = enable; + _animated_transition_manager_eval(obj, pd); +} + +EOLIAN static Eina_Bool +_efl_ui_spotlight_container_animated_transition_get(const Eo *obj EINA_UNUSED, Efl_Ui_Spotlight_Container_Data *pd) +{ + return pd->animation_enabled; +} + + #include "efl_ui_spotlight_container.eo.c" diff --git a/src/lib/elementary/efl_ui_spotlight_container.eo b/src/lib/elementary/efl_ui_spotlight_container.eo index fcd0bc30a3..16928d7d56 100644 --- a/src/lib/elementary/efl_ui_spotlight_container.eo +++ b/src/lib/elementary/efl_ui_spotlight_container.eo @@ -65,6 +65,12 @@ class @beta Efl.Ui.Spotlight.Container extends Efl.Ui.Layout_Base implements Efl (-1, -1) means that all available space inside the container can be used.]] } } + @property animated_transition { + [[When this flag is $true the transitions caused by @.push, @.pop or @.active_element are animated (if the @.spotlight_manager supports that). $false means immidiate displaying at the final position.]] + values { + enable : bool; [[$true to enable animated transitions. If $false, then any transition is displayed at the final position immidiatly]] + } + } push @beta { [[Packs a new sub-widget before @.active_element, and move the spotlight there. diff --git a/src/tests/elementary/efl_ui_test_spotlight.c b/src/tests/elementary/efl_ui_test_spotlight.c index 02edfcb652..c7fd2d7d2b 100644 --- a/src/tests/elementary/efl_ui_test_spotlight.c +++ b/src/tests/elementary/efl_ui_test_spotlight.c @@ -116,6 +116,7 @@ typedef struct { } spotlight; struct { int called; + Eina_Bool value; } animation; double last_position; } Transition_Calls; @@ -187,7 +188,7 @@ static void _transition_animation_set(Eo *obj EINA_UNUSED, void *pd EINA_UNUSED, Eina_Bool animation) { transition_calls.animation.called++; - ck_assert_int_eq(animation, EINA_TRUE); + transition_calls.animation.value = animation; } static Eina_Bool @@ -265,7 +266,8 @@ EFL_START_TEST (efl_ui_smart_transition_calls) efl_ui_spotlight_manager_set(container, t); transition_calls.last_position = -2.0; - ck_assert_int_eq(transition_calls.animation.called, 1); + ck_assert_int_eq(transition_calls.animation.called, 2); + ck_assert_int_eq(transition_calls.animation.value, EINA_TRUE); ck_assert_int_eq(transition_calls.spotlight.called, 1); ck_assert_ptr_eq(transition_calls.spotlight.spotlight, container); //We cannot verify group @@ -618,6 +620,34 @@ EFL_START_TEST (efl_ui_spotlight_test_pop3) } EFL_END_TEST +EFL_START_TEST (efl_ui_spotlight_animated_transition) +{ + //this checks animation handing with the plain manager, there is no animation that will be played, but the flag should be preserved + ck_assert_int_eq(efl_ui_spotlight_animated_transition_get(container), EINA_TRUE); + efl_ui_spotlight_animated_transition_set(container, EINA_FALSE); + ck_assert_int_eq(efl_ui_spotlight_manager_animated_transition_get(efl_ui_spotlight_manager_get(container)), EINA_FALSE); + + //now check with a real spotlight manager + efl_ui_spotlight_manager_set(container, efl_new(EFL_UI_SPOTLIGHT_MANAGER_STACK_CLASS)); + efl_ui_spotlight_animated_transition_set(container, EINA_TRUE); + ck_assert_int_eq(efl_ui_spotlight_animated_transition_get(container), EINA_TRUE); + ck_assert_int_eq(efl_ui_spotlight_manager_animated_transition_get(efl_ui_spotlight_manager_get(container)), EINA_TRUE); + + efl_ui_spotlight_animated_transition_set(container, EINA_FALSE); + ck_assert_int_eq(efl_ui_spotlight_animated_transition_get(container), EINA_FALSE); + ck_assert_int_eq(efl_ui_spotlight_manager_animated_transition_get(efl_ui_spotlight_manager_get(container)), EINA_FALSE); + + Eo *manager2 = efl_new(EFL_UI_SPOTLIGHT_MANAGER_STACK_CLASS); + Eina_Bool animated_transition_manager; + efl_add(EFL_UI_SPOTLIGHT_CONTAINER_CLASS, win, + efl_ui_spotlight_manager_set(efl_added, manager2), + efl_ui_spotlight_animated_transition_set(efl_added, EINA_TRUE), + animated_transition_manager = efl_ui_spotlight_manager_animated_transition_get(manager2)); + ck_assert_int_eq(animated_transition_manager, EINA_FALSE); + ck_assert_int_eq(efl_ui_spotlight_manager_animated_transition_get(manager2), EINA_TRUE); +} +EFL_END_TEST + static void spotlight_setup() { @@ -653,4 +683,5 @@ void efl_ui_test_spotlight(TCase *tc) tcase_add_test(tc, efl_ui_spotlight_test_pop1); tcase_add_test(tc, efl_ui_spotlight_test_pop2); tcase_add_test(tc, efl_ui_spotlight_test_pop3); + tcase_add_test(tc, efl_ui_spotlight_animated_transition); }