-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Scrolling programmatically #307
Comments
We have not added support for scrolling programmatically in These methods are exposed so they can be used from custom widgets after layouting. We should probably clarify that in the docs. |
Still a Rust noob so this wasn't clear to me only because of that :P I think the canonical use cases for programmatic scrolling are
I'll continue thinking about this and how it could possibly fit in. :) |
I think for this, perhaps we can just replace |
As I said in #323, this will cause the scrolling offset to change when the layout of the contents change.
This is necessary because the offset can be completely out of bounds if the scrollable contents change. The API is meant to be "fault-tolerant". |
I'll continue the conversation from #323 here so its better tracked :)
Keeping a bounds independent variable in the state is still desirable to allow the developer to make manual decisions.
In all of these cases (except text input) you wouldn't want the viewable area to move at all as this would be jarring to the user. For text input you would want to scroll to bottom.
I agree. If we must pick a default I propose adding I would rather do less and enable the developer to make their own decisions. |
In #323, you mentioned the concept of an Should we also add a field to the state to remember if manual scrolling has occurred so that developers can decide how if they want to apply their manual scrolling logic or not. In terms of actual "Programmatic Scrolling" I'm still not sure what we can do. |
I think we can start by removing the boundary checks in If we then add the concept of an anchor, we should cover a bunch of use cases already. We need to decide how will the user define/change this anchor and the scrolling behavior. |
Summarizing ideas thus far Yes lets do these in the solution:
More discussion:
|
I think we can go ahead and implement (1). For (2), we still need to answer some questions:
A good alternative is making
Both of these are deeply involved design changes that break current API guarantees, add complexity, and remove boundaries. |
Yup I agree, its a weighty topic. How does the elm world do scrollable widgets? |
I'm actually sorta leaning more towards |
I've found the following user story helpful.
Normally it works like this
But we hit a subtle problem when the user wants to perform some logic that depends on the Problem So as a user, how can I correctly implement logic that depends on the I have thought of a few high level ways this might be achieved:
Other general questions on the principles of the framework that I'm unsure on:
|
I think we are over-abstracting things here. Let's keep this focused to the programmatic scrolling use cases. I am not convinced we need to expose layout to the user (and break the Elm Architecture) or introduce functions with temporal constraints (any kind of As I said in my previous comment, if we encode |
Nothing has been discarded, I am taking the enum approach with the Anchor. For my understanding, is it correct that in this approach with the interior mutability we mutate the offset when State::offset is called? If so, that is a neater solution although maybe less pure. I agree this is a good way to go if we are only mutating "internal" widget state. Do you think the offset should be inside the |
@krooq Sorry! I did not mention interior mutability because I'd prefer to focus on the actual design before focusing on the implementation details (the internals). For the More or less in order, I believe we need to answer these questions:
For (1), we mentioned already:
Can we elaborate on the needs of these? For instance, a chatbox needs the concept of "snapping":
Let's try to design the most ideal public API first, without compromises. |
Let's say we add the following public methods to
Which use cases would be satisfied by this design? Which ones would not? |
Ok but I think you may not see my point of view.
I'm not really thinking in terms of API. I just want to be able to do these things and I don't care how. I can iterate on these ideas myself, until I get something decent to present. What I cant do is make decisions about fundamental aspects of the framework.
These cover most of the cases, whats missing:
|
Although we still have the issue I describe above in all of these. This issue doesn't just apply to scrolling, anything that changes content in |
I understand, but I believe these are not really use cases but a way to satisfy many of them (XY problem). I think we should be focusing on actual problems, for instance:
I don't believe these use cases are inherently tied with a viewport, layout, and content changes. These seem like implementation details to me. Does the user really need to care about them?
What are these cases? We need examples! How and when will these methods be used? What are we solving? I am asking you, the user! If we don't have clear examples for a particular one, then let's simply not implement it.
Yes, I believe we agreed this is possible without any further abstractions.
For now, there will be no generic API for that. We will specifically build APIs for each of the particular set of problems we identify, unifying as necessary. |
Ok, lets not plan for a future that may never exist.
My application use case is a chatbox/terminal (simple chatbox).
I don't really know whats best here and I don't really mind.
I really dunno with these until I try them and see what feels good.
FYI, I was able to get this working with the interior mutability and delayed computation in |
Been trying out the API..
Not sure about this one, its heavily dependent on the user application.
I'm not really sold on the closure. Might be better to just call a once off on the |
I believe most of your use cases can be satisfied with a simple
The content can only change through an
This should be default behavior, after calling
For this, we can consider adding an
Call
Call
This should work by default. If
This is not really a use case, but the default behavior is probably what you want here.
The above behaviors only make sense for a |
Yep the
Yep ok, if I want to jump to new content when it appears even after a "scroll up" event I can just use the
Yeah last 2 are more like requirements than use cases.
This just meant that I want to be able to use any widget as the content inside a The EDIT3 (clarity)
Keeping in mind we should also consider what the horizontal case would look like. It might be relevant for left-to-right vs right-to-left text. EDIT1: Do you think we should also supply the previous scroll value or delta to the on_scroll message constructor? |
I faced this issue while I was trying to implement some features for my Matrix chat client. I created a branch in my fork of iced, which solves the issues I had.
This doesn't really implement things said in this thread (and the code looks ugly) but it works for my case. Just wanted to share it if someone wants to take a look. |
The scroll_to method on the State in Scrollable is useful for scrolling programmatically but it requires knowledge of the layout bounds which isn't public.
Either this information should be exposed, probably for all widgets, or the State should contain the bounds of the Scrollable so that scroll_to can be used as public api without needing to create a custom widget.
What do you think?
EDIT: zulip links
https://iced.zulipchat.com/#narrow/stream/213316-general/topic/infinite.20list
https://iced.zulipchat.com/#narrow/stream/213445-help/topic/Scrollable.3A.3Apush_back
https://iced.zulipchat.com/#narrow/stream/213445-help/topic/how.20to.20scroll.20programmatically.3F
https://iced.zulipchat.com/#narrow/stream/213445-help/topic/scroll_to
The text was updated successfully, but these errors were encountered: