This repository has been archived by the owner on Jan 16, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
layout: change Widget to take explicit Context and return explicit Di…
…mensions Change the definition of Widget from the implicit type Widget func() to the explicit functional type Widget func(gtx layout.Context) layout.Dimensions The advantages are numerous: - Clearer connection between the incoming context and the output dimensions. - Returning the Dimensions are impossible to omit. - Contexts passed by value, so its fields can be exported and freely mutated by the program. The only disadvantage is the longer function literals and the many "returns". What tipped the scales in favour of the explicit Widget variant is that type aliases can dramatically shorten the literals: type ( C = layout.Context D = layout.Dimensions ) widget := func(gtx C) D { ... } Note that the aliases are not part of the Gio API and it is up to each user whether they want to use them. Finally the Go proposal for lightweight function literals, golang/go#21498, may remove the disadvantage completely in future. Context becomes a plain struct with only public fields, and its Reset is replaced by a NewContext convenience constructor. Signed-off-by: Elias Naur <mail@eliasnaur.com>
- Loading branch information
Showing
25 changed files
with
226 additions
and
208 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.