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

Lens style #236

Merged
merged 8 commits into from
Feb 28, 2015
Merged

Lens style #236

merged 8 commits into from
Feb 28, 2015

Conversation

cchalmers
Copy link
Member

See diagrams/diagrams-core#80. Includes a bunch of lenses onto attributes of a Style.

The only real issue is lenses that include a Recommend are always "committed" (this is how the previous styleFillTexture setter was). This is almost always what you want, otherwise styles set with a lens could be accidentally overwritten. These lenses have warnings and a valid R variant that includes the Recommend.

The 3D attributes lenses haven't been added these lenses because the povray backend needs changes, I'll do that later if this gets merged.

Other then that this should be ready to merge.

@cchalmers
Copy link
Member Author

I've added Isos in the form _Attribute :: Iso AttributeA Attribute and an _attribute :: Lens' (Style v n) Attribute for most attributes. Some of them are Maybe Attribute and some of them have a _attributeR :: Lens' (Style v n) (Recommend Attribute) variant. I've also added some lenses / prisms for Recommend.

The changes shouldn't break any backends (except for povray which I'll fix). Overall I'm reasonably happy with it, I think it's ready to merge. What do people think?

_recommend f (Recommend a) = Recommend <$> f a
_recommend f (Commit a) = Commit <$> f a

-- | Lens onto weather something is committed or not.
Copy link
Member

Choose a reason for hiding this comment

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

whether, not weather

Copy link
Member

Choose a reason for hiding this comment

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

If only we had a lens into weather...

On Fri, Feb 27, 2015 at 10:19 AM, Daniel Bergey notifications@github.com
wrote:

In src/Diagrams/Attributes.hs
#236 (comment):

+-- | Prism onto a 'Recommend'.
+_Recommend :: Prism' (Recommend a) a
+_Recommend = prism' Recommend $ \case (Recommend a) -> Just a; _ -> Nothing
+
+-- | Prism onto a 'Commit'.
+_Commit :: Prism' (Recommend a) a
+_Commit = prism' Commit $ \case (Commit a) -> Just a; _ -> Nothing
+
+-- | Lens onto the value inside either a 'Recommend' or 'Commit'. Unlike
+-- 'committed', this is a valid lens.
+_recommend :: Lens (Recommend a) (Recommend b) a b
+_recommend f (Recommend a) = Recommend <$> f a
+_recommend f (Commit a) = Commit <$> f a
+
+-- | Lens onto weather something is committed or not.

whether, not weather


Reply to this email directly or view it on GitHub
https://github.com/diagrams/diagrams-lib/pull/236/files#r25512596.

@bergey
Copy link
Member

bergey commented Feb 27, 2015

Looks good to me.

@byorgey
Copy link
Member

byorgey commented Feb 28, 2015

Looks good to me too.

3D attributes haven't been changed yet. This requires changes to the povray backend.
Now _Attribute is an Iso and _attribute is a lens onto the attribute in a style.
They're just added noise, you never really use them because you need to know the types. We can always add them later.
There's no need to use the maybe value, transparent it equivilent to no
fill.

This reverts commit 731f181.
cchalmers added a commit that referenced this pull request Feb 28, 2015
@cchalmers cchalmers merged commit 1f8d7f0 into master Feb 28, 2015
@cchalmers cchalmers deleted the lens-style branch February 28, 2015 12:37
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

4 participants