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

Refactor PopUp size and position handling #699

Merged

Conversation

toaster
Copy link
Member

@toaster toaster commented Feb 23, 2020

Description:

The PopUp size and position handling is a difficult thing.
I tried to improve the implementation and to reduce the visibility of internal structure.
This refactoring also fixes the bug which my previous bugfix of Select's drop-down size adjustment fixed. That's why I reverted the previous fix.
The refactoring reduces unwanted dependencies and also fixes the Select drop-down size on mobile.

Checklist:

  • [ ] Tests included.
  • Lint and formatter run with no errors.
  • Tests all pass.

This makes the widget.PopUp independent from internal.cache (see fyne-io#696).
This also removes a dependency of internal/driver/glfw from widget.
And it fixes the broken shadow size for select's drop-down.
Copy link
Member

@andydotxyz andydotxyz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to break combo popups when constrained (see graphics tab of fyne_demo).

@@ -48,6 +50,7 @@ func TestPopUp_Move(t *testing.T) {

pos := fyne.NewPos(10, 10)
pop.Move(pos)
cache.Renderer(pop).Layout(pop.Size())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This concerns me. This seems to be required because the Move function no longer lays out content to accommodate hitting the edge of the screen.
And so any code that calls PopUp.Move() may not work any more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Move method of a widget should not lay out anything. That's the responsibility of the renderer. That's why the adjustments are now made there.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case if the move could cause a need to layout then it should trigger it - that way the tests (and all other code) don't need this line added...

Copy link
Member Author

@toaster toaster Feb 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no “all other code” and the tests are not normal code. I don't think that a Move should run Layout immediately. This is for several reasons:

  1. I consider Layout as quite expensive
  2. The Move of an element X is not important for the layout of X but for its parent p(X). Also Move is normally called from parent's renderer's Layout because the parent decides where the element has to be placed..
  3. The PopUp is special because it mixes up two things: a container (an overlay with canvas size and 0,0 pos) and a content (a freely sizeable and positionable element). Inconsistent size/position handling for overlays #707 describes a proposal to reduce or even eliminate the effects of this special behaviour.
  4. Position adjustment due to outer constraints (window size) is clearly renderer responsibility. That's why the test that tests this adjustment has to ensure that the renderer is called. If Inconsistent size/position handling for overlays #707 was addressed, the container and its content would be separated and the position won't be sent to container's Move but to a specific container function like MoveContent or alike. This would also make the test more clear because it would call MoveContent which then might trigger a layout. But honestly I don't like the idea of the latter because it adds internal dependencies to the widget. This could be avoided by performing Refresh and call Layout from the renderer's Refresh if needed.

After writing all this I think I might add the Refresh mentioned in point 4 to PopUp. The Layout line then would vanish from the test again. Stay tuned :).

P.S.: This Refresh would take its proper place if #707 is being addressed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I think you're right. And this should get better now that #707 is landed.
Thanks

@@ -83,6 +83,7 @@ func TestSelect_Tapped_Constrained(t *testing.T) {
canvas := fyne.CurrentApp().Driver().CanvasForObject(combo)
canvas.(test.WindowlessCanvas).Resize(fyne.NewSize(100, 100))

combo.Resize(combo.MinSize())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The addition of this line is problematic, it seems to reflect a change in behaviour.
In fyne_demo go to Graphics, then tap the icon name combo...
You will see that it's sizing up to full size instead of staying the correct width.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is not the cause of the drop.down size bug. I reported it as #706.
This line is here because the test set-up is uncommon. The combo is not set as canvas' content and therefore never laid out and therefore does have size 0x0.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yes, thanks. in that case is the canvas resize really helping? If the component is not inside the canvas then the parent size may have no impact?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't resize the canvas but the combo :).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was meaning the resize call above, which is a canvas resize (I think it was perhaps put in accidentally?)

widget/popup_test.go Show resolved Hide resolved
@andydotxyz andydotxyz merged commit 5541e9b into fyne-io:develop Feb 25, 2020
@andydotxyz
Copy link
Member

much nicer now, thanks

@toaster toaster deleted the refactor/improve_select_size_adjustment branch February 26, 2020 06:13
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.

None yet

2 participants