mirror of
https://github.com/rgleichman/glance.git
synced 2024-11-30 05:47:46 +03:00
Fix comment text alignment.
This commit is contained in:
parent
d60977eee1
commit
4d979ac5a3
34
app/Icons.hs
34
app/Icons.hs
@ -7,7 +7,7 @@ module Icons
|
|||||||
iconToDiagram,
|
iconToDiagram,
|
||||||
nameDiagram,
|
nameDiagram,
|
||||||
textBox,
|
textBox,
|
||||||
multilineText,
|
multilineComment,
|
||||||
enclosure,
|
enclosure,
|
||||||
lambdaRegion,
|
lambdaRegion,
|
||||||
resultIcon,
|
resultIcon,
|
||||||
@ -184,15 +184,23 @@ bindTextBox :: SpecialBackend b =>
|
|||||||
bindTextBox = coloredTextBox (bindTextBoxTextC colorScheme) $ opaque (bindTextBoxC colorScheme)
|
bindTextBox = coloredTextBox (bindTextBoxTextC colorScheme) $ opaque (bindTextBoxC colorScheme)
|
||||||
|
|
||||||
|
|
||||||
multilineText :: SpecialBackend b =>
|
multilineComment :: SpecialBackend b =>
|
||||||
Colour Double
|
Colour Double
|
||||||
-> AlphaColour Double -> String -> SpecialQDiagram b
|
-> AlphaColour Double -> String -> SpecialQDiagram b
|
||||||
multilineText textColor boxColor t = lwG (0.6 * defaultLineWidth) $ textDia
|
multilineComment textColor boxColor t = lwG (0.6 * defaultLineWidth) textDia
|
||||||
where
|
where
|
||||||
textLines = lines t
|
textLines = lines t
|
||||||
textAreas = map (singleLineTextArea textColor) textLines
|
textAreas = map (commentTextArea textColor) textLines
|
||||||
textDia = vcat textAreas
|
textDia = vcat textAreas
|
||||||
|
|
||||||
|
-- | Given the number of letters in a textbox string, make a rectangle that will
|
||||||
|
-- enclose the text box.
|
||||||
|
rectForText :: (InSpace V2 n t, TrailLike t, OrderedField n) => Int -> t
|
||||||
|
rectForText n = rect rectangleWidth (textBoxFontSize * textBoxHeightFactor)
|
||||||
|
where
|
||||||
|
rectangleWidth = fromIntegral n * textBoxFontSize * monoLetterWidthToHeightFraction
|
||||||
|
+ (textBoxFontSize * 0.2)
|
||||||
|
|
||||||
-- Since the normal SVG text has no size, some hackery is needed to determine
|
-- Since the normal SVG text has no size, some hackery is needed to determine
|
||||||
-- the size of the text's bounding box.
|
-- the size of the text's bounding box.
|
||||||
coloredTextBox :: SpecialBackend b =>
|
coloredTextBox :: SpecialBackend b =>
|
||||||
@ -200,21 +208,13 @@ coloredTextBox :: SpecialBackend b =>
|
|||||||
-> AlphaColour Double -> String -> SpecialQDiagram b
|
-> AlphaColour Double -> String -> SpecialQDiagram b
|
||||||
coloredTextBox textColor boxColor t =
|
coloredTextBox textColor boxColor t =
|
||||||
fontSize (local textBoxFontSize) (bold $ font "freemono" $ fc textColor $ text t)
|
fontSize (local textBoxFontSize) (bold $ font "freemono" $ fc textColor $ text t)
|
||||||
<> lwG (0.6 * defaultLineWidth) (lcA boxColor $ rect rectangleWidth (textBoxFontSize * textBoxHeightFactor))
|
<> lwG (0.6 * defaultLineWidth) (lcA boxColor $ rectForText (length t))
|
||||||
where
|
|
||||||
rectangleWidth = textBoxFontSize * monoLetterWidthToHeightFraction
|
|
||||||
* fromIntegral (length t)
|
|
||||||
+ (textBoxFontSize * 0.2)
|
|
||||||
|
|
||||||
singleLineTextArea :: SpecialBackend b =>
|
commentTextArea :: SpecialBackend b =>
|
||||||
Colour Double -> String -> SpecialQDiagram b
|
Colour Double -> String -> SpecialQDiagram b
|
||||||
singleLineTextArea textColor t =
|
commentTextArea textColor t =
|
||||||
alignL $ fontSize (local textBoxFontSize) (font "freemono" $ fc textColor $ text t)
|
alignL $ fontSize (local textBoxFontSize) (font "freemono" $ fc textColor $ topLeftText t)
|
||||||
<> rect rectangleWidth (textBoxFontSize * textBoxHeightFactor)
|
<> alignTL (lw none $ rectForText (length t))
|
||||||
where
|
|
||||||
rectangleWidth = textBoxFontSize * monoLetterWidthToHeightFraction
|
|
||||||
* fromIntegral (length t)
|
|
||||||
+ (textBoxFontSize * 0.2)
|
|
||||||
|
|
||||||
-- ENCLOSING REGION --
|
-- ENCLOSING REGION --
|
||||||
enclosure :: SpecialBackend b =>
|
enclosure :: SpecialBackend b =>
|
||||||
|
@ -8,7 +8,7 @@ import Diagrams.Prelude hiding ((#), (&))
|
|||||||
import Diagrams.Backend.SVG.CmdLine
|
import Diagrams.Backend.SVG.CmdLine
|
||||||
import qualified Language.Haskell.Exts as Exts
|
import qualified Language.Haskell.Exts as Exts
|
||||||
|
|
||||||
import Icons(ColorStyle(..), colorScheme, multilineText)
|
import Icons(ColorStyle(..), colorScheme, multilineComment)
|
||||||
import Rendering(renderDrawing)
|
import Rendering(renderDrawing)
|
||||||
import Translate(drawingsFromModule)
|
import Translate(drawingsFromModule)
|
||||||
|
|
||||||
@ -69,7 +69,7 @@ renderFile inputFilename includeComments = do
|
|||||||
|
|
||||||
diagrams <- traverse renderDrawing drawings
|
diagrams <- traverse renderDrawing drawings
|
||||||
let
|
let
|
||||||
commentsInBoxes = fmap (\(Exts.Comment _ _ c) -> alignL $ multilineText white (opaque white) c) comments
|
commentsInBoxes = fmap (\(Exts.Comment _ _ c) -> alignL $ multilineComment white (opaque white) c) comments
|
||||||
diagramsAndComments = vsep 2 $ zipWith (\x y -> x === strutY 0.4 === y) commentsInBoxes (fmap alignL diagrams)
|
diagramsAndComments = vsep 2 $ zipWith (\x y -> x === strutY 0.4 === y) commentsInBoxes (fmap alignL diagrams)
|
||||||
justDiagrams = vsep 1 $ fmap alignL diagrams
|
justDiagrams = vsep 1 $ fmap alignL diagrams
|
||||||
diagramsAndMaybeComments = if includeComments == "c" then diagramsAndComments else justDiagrams
|
diagramsAndMaybeComments = if includeComments == "c" then diagramsAndComments else justDiagrams
|
||||||
|
@ -201,9 +201,9 @@ apply icons should be made more dissimilar so that they can not be confused with
|
|||||||
each other, even when displaying Glance drawings in black and white.
|
each other, even when displaying Glance drawings in black and white.
|
||||||
|
|
||||||
Now that you are fammiliar with matches, here's a simple case expression.
|
Now that you are fammiliar with matches, here's a simple case expression.
|
||||||
y = case maybeInt of
|
--y = case maybeInt of
|
||||||
Just x -> x + 1
|
-- Just x -> x + 1
|
||||||
Nothing -> 0
|
-- Nothing -> 0
|
||||||
-}
|
-}
|
||||||
y = case maybeInt of
|
y = case maybeInt of
|
||||||
Just x -> x + 1
|
Just x -> x + 1
|
||||||
@ -225,8 +225,8 @@ as opposed to the case icon which would create many cycles if remote result circ
|
|||||||
were not allowed.
|
were not allowed.
|
||||||
|
|
||||||
Guards and if expressions look like this:
|
Guards and if expressions look like this:
|
||||||
y | x == 0 = 1
|
--y | x == 0 = 1
|
||||||
| otherwise = x + 1
|
--- | otherwise = x + 1
|
||||||
-}
|
-}
|
||||||
y | x == 0 = 1
|
y | x == 0 = 1
|
||||||
| otherwise = x + 1
|
| otherwise = x + 1
|
||||||
@ -242,10 +242,10 @@ in better icon versions.
|
|||||||
|
|
||||||
If expressions are rendered the same as a guard with only one boolean.
|
If expressions are rendered the same as a guard with only one boolean.
|
||||||
|
|
||||||
factorial x =
|
--factorial x =
|
||||||
if x == 0
|
-- if x == 0
|
||||||
then 1
|
-- then 1
|
||||||
else x * factorial (x - 1)
|
-- else x * factorial (x - 1)
|
||||||
-}
|
-}
|
||||||
factorial x =
|
factorial x =
|
||||||
if x == 0
|
if x == 0
|
||||||
|
Loading…
Reference in New Issue
Block a user