From b9b20733761857fab6619a82c5854278231c1523 Mon Sep 17 00:00:00 2001 From: Brent Yorgey Date: Thu, 5 Jun 2014 13:40:31 -0400 Subject: [PATCH] add convenience synonyms [hv]sep for [hv]cat' (with & sep .~ x) --- src/Diagrams/TwoD.hs | 4 ++-- src/Diagrams/TwoD/Combinators.hs | 25 ++++++++++++++++++++----- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/Diagrams/TwoD.hs b/src/Diagrams/TwoD.hs index c899512c..69cd39ec 100644 --- a/src/Diagrams/TwoD.hs +++ b/src/Diagrams/TwoD.hs @@ -201,8 +201,8 @@ module Diagrams.TwoD -- * Combinators -- ** Combining multiple diagrams , (===), (|||), atAngle - , hcat, hcat' - , vcat, vcat' + , hcat, hcat', hsep + , vcat, vcat', vsep -- ** Spacing and envelopes , strutX, strutY diff --git a/src/Diagrams/TwoD/Combinators.hs b/src/Diagrams/TwoD/Combinators.hs index 775d6dc8..ef0ee07a 100644 --- a/src/Diagrams/TwoD/Combinators.hs +++ b/src/Diagrams/TwoD/Combinators.hs @@ -21,8 +21,8 @@ module Diagrams.TwoD.Combinators (===), (|||), atAngle -- * n-ary combinators - , hcat, hcat' - , vcat, vcat' + , hcat, hcat', hsep + , vcat, vcat', vsep -- * Spacing/envelopes , strutR2 @@ -37,6 +37,7 @@ module Diagrams.TwoD.Combinators ) where +import Control.Lens ((&), (.~)) import Data.AffineSpace import Data.Colour import Data.Default.Class @@ -116,11 +117,18 @@ hcat = hcat' def -- | A variant of 'hcat' taking an extra 'CatOpts' record to control -- the spacing. See the 'cat'' documentation for a description of --- the possibilities. +-- the possibilities. For the common case of setting just a +-- separation amount, see 'hsep'. hcat' :: (Juxtaposable a, HasOrigin a, Monoid' a, V a ~ R2) => CatOpts R2 -> [a] -> a hcat' = cat' unitX +-- | A convenient synonym for horizontal concatenation with +-- separation: @hsep s === hcat' (with & sep .~ s)@. +hsep :: (Juxtaposable a, HasOrigin a, Monoid' a, V a ~ R2) + => Scalar R2 -> [a] -> a +hsep s = hcat' (def & sep .~ s) + -- | Lay out a list of juxtaposable objects in a column from top to -- bottom, so that their local origins lie along a single vertical -- line, with successive envelopes tangent to one another. @@ -137,12 +145,19 @@ vcat :: (Juxtaposable a, HasOrigin a, Monoid' a, V a ~ R2) vcat = vcat' def -- | A variant of 'vcat' taking an extra 'CatOpts' record to control --- the spacing. See the 'cat'' documentation for a description of the --- possibilities. +-- the spacing. See the 'cat'' documentation for a description of +-- the possibilities. For the common case of setting just a +-- separation amount, see 'vsep'. vcat' :: (Juxtaposable a, HasOrigin a, Monoid' a, V a ~ R2) => CatOpts R2 -> [a] -> a vcat' = cat' (negateV unitY) +-- | A convenient synonym for vertical concatenation with +-- separation: @vsep s === vcat' (with & sep .~ s)@. +vsep :: (Juxtaposable a, HasOrigin a, Monoid' a, V a ~ R2) + => Scalar R2 -> [a] -> a +vsep s = vcat' (def & sep .~ s) + -- | @strutR2 v@ is a two-dimensional diagram which produces no -- output, but with respect to alignment, envelope, /and trace/ acts -- like a 1-dimensional segment oriented along the vector @v@, with