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

Lenses for setting arrow head, tail, and shaft colors #138

Merged
merged 11 commits into from Nov 16, 2013
Merged

Conversation

byorgey
Copy link
Member

@byorgey byorgey commented Nov 14, 2013

This pull request contains the following:

  1. A new method for the Color class, fromAlphaColour. See @9a89228.
  2. A few new utility functions in Diagrams.Attributes. See @a9339c6.
  3. Adds a Default FillColor instance. Not sure why it was missing before.
  4. Setters for the fill and line color attributes within a style.
  5. Setters for directly setting the color of arrow heads, tails, and shafts. These are much more convenient than using lenses for the head, tail, and shaft styles in the common case that you just want to set the color, since it's less to type, and less to get wrong (you don't have to remember whether to set the fill or line color).
  6. Remove the default shaft width. This means that shaft width is now by default taken from the ambient line width, and can be set just by applying the lw function to an arrow, as well as by setting the shaftStyle.

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.

Brent Yorgey added 11 commits November 14, 2013 11:44
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.
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
@bergey bergey merged commit 56cf164 into master Nov 16, 2013
@bergey bergey deleted the arrow-attr-lenses branch December 9, 2013 03:36
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