Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scroll on focus without animation #2342

Closed
boraozgen opened this issue Jul 1, 2021 · 16 comments
Closed

Scroll on focus without animation #2342

boraozgen opened this issue Jul 1, 2021 · 16 comments

Comments

@boraozgen
Copy link
Contributor

Introduce the problem

In case LV_OBJ_FLAG_SCROLL_ON_FOCUS is set, the object scrolls into view when focused:

lvgl/src/core/lv_obj.c

Lines 671 to 673 in 77cedfa

if(lv_obj_has_flag(obj, LV_OBJ_FLAG_SCROLL_ON_FOCUS)) {
lv_obj_scroll_to_view_recursive(obj, LV_ANIM_ON);
}

Here, the scroll animation is on by default and cannot be turned off.

Examples and cases

Turning off these animations could be important for resource-constrained, keypad based systems, where the animations are slow, yet scrolling is desired.

Suggested solution

We can make this configurable, the place and switch name are up to the maintainers.

@boraozgen boraozgen changed the title Make possible to scroll on focus without animation Scroll on focus without animation Jul 1, 2021
@kisvegabor
Copy link
Member

kisvegabor commented Jul 1, 2021

Thanks for the suggestion.

A similar issue came up once to disable to scroll animation when the tabview changes tab. The use case was the same: animations are ugly on a slow screen.

The idea of mimicking CSS's prefers-reduced-motion also came up but finally, we found a local solution to it.

Thinking about it again prefers-reduced-motion as a display driver option seems like a flexible solution.

@embeddedt @boraozgen What do you think?

@embeddedt
Copy link
Member

I think LV_EVENT_SCROLL_BEGIN bubbles to parent objects, so can't animations be disabled simply by adding this event handler to lv_scr_act()?

@boraozgen
Copy link
Contributor Author

boraozgen commented Jul 2, 2021

Attaching it to the screen doesn't seem to call the event handler. It is not in the bubbled list anyway:

static bool event_is_bubbled(lv_event_code_t e)

Attaching it to the scrollable object gets the handler called, but does not seem to disable the animation for me. I'm running v8.0.1, if that makes any difference.

Edit: I just checked lv_anim_start and the animation seems to be copied, so how should modifying the original animation time affect the already started animation?

Thinking about it again prefers-reduced-motion as a display driver option seems like a flexible solution.

This should not disable animations completely, as animations with small objects usually run OK. I think I would prefer switches/configurations for each use case, providing more flexibility.

@embeddedt
Copy link
Member

This should not disable animations completely, as animations with small objects usually run OK. I think I would prefer switches/configurations for each use case, providing more flexibility.

I agree; that's why I suggested the bubbling approach. I'll need to test it to find out why it's not being bubbled; the list in event_is_bubbled is a blacklist of which events should not be bubbled, from my understanding.

I just checked lv_anim_start and the animation seems to be copied, so how should modifying the original animation time affect the already started animation?

LV_EVENT_SCROLL_BEGIN is fired before lv_anim_start gets called:

res = lv_event_send(obj, LV_EVENT_SCROLL_BEGIN, &a);
if(res != LV_RES_OK) return;
lv_anim_start(&a);

@boraozgen
Copy link
Contributor Author

LV_EVENT_SCROLL_BEGIN is fired before lv_anim_start gets called:

Not for y direction :) is there a particular reason or is it a bug?

the list in event_is_bubbled is a blacklist of which events should not be bubbled, from my understanding.

True. I checked again, my object seems to have LV_OBJ_FLAG_EVENT_BUBBLE not set. Does it have to be set explicitly?

@embeddedt
Copy link
Member

Not for y direction :) is there a particular reason or is it a bug?

That is indeed a bug. I see no reason why the two axes should behave differently. Thank you for pointing it out, and sorry that I missed it when you mentioned it earlier. 🙂

Fixed here: b158932

I checked again, my object seems to have LV_OBJ_FLAG_EVENT_BUBBLE not set. Does it have to be set explicitly?

I thought it was enabled by default, but upon a closer look, it appears that you do have to set it manually. That makes my solution much more cumbersome, as you would essentially have to enable this flag on all your objects.

@boraozgen
Copy link
Contributor Author

The LV_EVENT_SCROLL_BEGIN seems to solve it, however it's still kind of hacky.

BTW I noticed another issue: It looks weird when the scrollbar lights up when the animation is disabled. It flashes once as the scrolling takes just a moment. Can we disable this too?

@boraozgen
Copy link
Contributor Author

Fixed here: b158932

Thanks. Are the fixes going to be cherry picked into v8 during release? Did you consider another branch model?

@embeddedt
Copy link
Member

Yes. As of v8, minor versions receive fixes for 1 year as well, so 8.0.2 should arrive sooner rather than later.

@kisvegabor
Copy link
Member

kisvegabor commented Jul 5, 2021

The scroll events are not bubbled as it'd mean a huge amount of LV_EVENT_SCROLLs.

BTW I noticed another issue: It looks weird when the scrollbar lights up when the animation is disabled. It flashes once as the scrolling takes just a moment. Can we disable this too?

You can disable the scroll "effect" with

    lv_obj_remove_style(cont, NULL, LV_PART_SCROLLBAR | LV_STATE_SCROLLED);

@boraozgen
Copy link
Contributor Author

Thanks. Then my issue is resolved, you can close the issue or leave it open depending on whether you think it makes sense to add a configuration for this.

@kisvegabor
Copy link
Member

kisvegabor commented Jul 6, 2021

Great!

Let's see if we get other related issues. If so we can find a more generic solution. So I close this issue for now.

@boraozgen
Copy link
Contributor Author

I came up with an idea while I was trying to disable the animations for lv_roller. There, we can set the anim_time style to zero, which basically disables the animations. Could this be applied to the scrollbars, i.e. when the style is applied to the container object, the scrollbar animation time changes accordingly?

@kisvegabor
Copy link
Member

By the scrollbar animation do you mean

  1. the opacity animation of the scrollbar?
  2. the movement of the scrollbar and scrolling in general?

@boraozgen
Copy link
Contributor Author

I mean the movement of the scrollbar.

@kisvegabor
Copy link
Member

I'd find it a little bit misleading as not really to scrollbar is moving. It's just an indicator of the moving content.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants