feat: extend gbuilder by aliases and constructor #92
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
The syntax
Spacing(top = 10, bottom = 10, left = 5, right = 5)
is annoying to declare because or repeating and it's also applicable forSpacing(top = 5, bottom = 5, left = 5, right = 5)
. Therefore, need to something that should help write less information but achieve the same result.Changes
Value
enum type is now extended by availability toclone
. It's optional but urgent for assignment the same value for different fields. Of course, for single field theclone
characteristic will not be used, so don't worry about it.alias
of field. Some fields can have the same aliases and it means that for this alias value will assigned for these fields.constructor
syntax. If the struct is homogeneous (have the same types of all fields), it can possibility to have a constructor which consumes single value and assigns to all fields.New syntax
The old syntax remains as is. That's why the PR is extension.
Currently only
Spacing
andAlignment
have simplifications:Spacing
introduced newhorizontal
,vertical
andall
aliases. Thehorizontal
is alias oftop
andbottom
both,vertical
-left
andright
both,all
-top
,bottom
,left
andright
together (why not?).Alignment
introduced newdiagonal
alias ofhorizontal
andvertial
both.Spacing
there is a constructor that consumesUInt
value and assigns to all directions (behaves likeall
alias).Alignment
there is a constructor that consumerLiteral
value and assigns to all fields (behaves likediagonal
alias).Example of usage:
What about other types?
Currently there's not so much helpful types to configure layout for which is need to shorthand. But in future might be a type that is homogeneous or some fields are homogeneous and have same semantic, and for these types this shorthand will be applied.