-
Notifications
You must be signed in to change notification settings - Fork 62
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
Lenses for setting arrow head, tail, and shaft colors #138
Merged
Conversation
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 allows (partial) conversions in both directions, which I found necessary for implementing some lenses to set some color in a given style. Adding such a method seems generally unobjectionable to me.
These are intentionally not re-exported from the Prelude; most users should not need them.
This is the sort of convenient thing that we can do now that we use lens for everything: we can provide headColor, tailColor, and shaftColor directly as "virtual fields" so the user doesn't have to think about style modification functions in the common case where they just want to set the color (and we also protect them from the easy mistake of setting the line color on the head, or fill color on the shaft). This is something of a proof-of-concept. Ideally we could even refactor these as e.g. headColor = headStyle . styleFillColor where styleFillColor :: (Color c, Color c') => Setter (Style v) (Style v) c c'.
Not sure why we were missing this before.
Note these can't be lenses because there's nothing to return if the style does not contain a line or fill color attribute. (One could just return a default value but that would violate the lens laws.) Seems to work pretty well! Perhaps we should add setters for other attributes as well.
…tyle{Line,Fill}Color
The more polymorphic versions caused problems for type inference in typical use cases.
The shaft width will now be taken from the ambient line width attribute by default. Explicitly setting the line width via the shaftStyle will always override this default.
bergey
added a commit
that referenced
this pull request
Nov 16, 2013
Lenses for setting arrow head, tail, and shaft colors
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This pull request contains the following:
Color
class,fromAlphaColour
. See @9a89228.Diagrams.Attributes
. See @a9339c6.Default FillColor
instance. Not sure why it was missing before.lw
function to an arrow, as well as by setting theshaftStyle
.Generally I am excited about the possibility of providing more of these sorts of "virtual fields" --- lenses which allow you to query, modify, or traverse some aspect of a thing even when that aspect is not actually a literal record field.