Skip to content

Do not scroll List items unless selected item is out of view#218

Closed
ardnew wants to merge 1 commit intorivo:masterfrom
ardnew:list-viewtracking
Closed

Do not scroll List items unless selected item is out of view#218
ardnew wants to merge 1 commit intorivo:masterfrom
ardnew:list-viewtracking

Conversation

@ardnew
Copy link
Copy Markdown
Contributor

@ardnew ardnew commented Jan 3, 2019

This change adds a single new field viewOffset to the List struct because it is impossible (I'm pretty sure) to determine which items should be drawn at any given instant with only the state information available when Draw() is called.

This new viewOffset field effectively remembers where the view existed the last time Draw() was called, and from that along with the currently selected item, determines which items need to be drawn.

Please test this out, it felt very natural to me, but I haven't looked to see if Table or TreeView would also benefit from the same logic.

This resolves issue #217

@rivo
Copy link
Copy Markdown
Owner

rivo commented Jan 23, 2019

Totally agree with the requirement described in #217. However, here again, I'm providing my own implementation (see 0a17957), mostly because I find the use of two switch statements and the -1/+1/0 return values for the helper function a bit cumbersome. And it would have been quite a bit more code than what was needed.

So I'll close this one without merging. Hope you don't mind.

@ardnew
Copy link
Copy Markdown
Contributor Author

ardnew commented Jan 23, 2019

That -1/+1/0 is bad habit from my C programming, where that idiom is used pretty extensively, such as in strcmp() from the C standard library:

The strcmp() and strncmp() functions return an integer greater than, equal to, or less than 0, according as the string s1 is greater than, equal to, or less than the string s2.

@rivo
Copy link
Copy Markdown
Owner

rivo commented Jan 24, 2019

I know strcmp(), C was one of the first languages I learned (25 years ago, haha!). That idiom makes sense where e.g. you need to sort an array, as there are three cases to consider (less, greater, equal). There are three cases here, too, but you're only using contains() once and only act on two of its cases. So I thought this could be simplified.

Thanks anyway for your submission. It's always interesting to see a different approach.

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

Successfully merging this pull request may close these issues.

2 participants