-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Fix ScrollToBottom and ScrollToTop #4493
base: develop
Are you sure you want to change the base?
Conversation
I have realised that the tests are basically no-ops as the X/Y and assertions were confused. Try the following test cases (maybe commit them in this PR if you agree with them): func TestScrollContainer_ScrollToTop(t *testing.T) {
rect := canvas.NewRectangle(color.Black)
rect.SetMinSize(fyne.NewSize(100, 500))
scroll := NewScroll(rect)
scroll.Resize(fyne.NewSize(100, 50))
scroll.scrollBy(0, -100)
assert.Equal(t, float32(100), scroll.Offset.Y)
scroll.ScrollToTop()
assert.Equal(t, float32(0), scroll.Offset.Y)
}
func TestScrollContainer_ScrollToBottom(t *testing.T) {
rect := canvas.NewRectangle(color.Black)
rect.SetMinSize(fyne.NewSize(100, 500))
scroll := NewScroll(rect)
scroll.Resize(fyne.NewSize(100, 50))
scroll.ScrollToBottom()
assert.Equal(t, float32(450), scroll.Offset.Y)
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work but the ScrollToBottom
does not seem correct - it's got two codepaths and can be simplified as noted inline.
} | ||
|
||
// ScrollToTop will scroll content to container top | ||
func (s *Scroll) ScrollToTop() { | ||
s.scrollBy(0, -s.Offset.Y) | ||
s.scrollBy(0, s.Offset.Y) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!
@@ -393,13 +393,16 @@ func (s *Scroll) CreateRenderer() fyne.WidgetRenderer { | |||
|
|||
// ScrollToBottom will scroll content to container bottom - to show latest info which end user just added | |||
func (s *Scroll) ScrollToBottom() { | |||
if s.Content.MinSize().Height > s.Size().Height { | |||
s.Offset.Y = s.Content.MinSize().Height - s.Size().Height | |||
s.Base.Refresh() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fix doesn't seem right - making a change then refreshing but then also making another change.
Really it should call scrollBy
so the fix should be revising the parameters to that method.
And that Refresh
looks like it's not needed any more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should also save the result of MinSize()
and Size()
instead of computing it multiple times in succession.
修正好了嗎? |
Google translate:
No. If the issue was resulted this would have been closed. |
Description:
I managed to fix scroll to bottom issue, I tested and it works...
Fixes #2917
Checklist:
Where applicable: