From efe0d114a6052431659419c4801424d1f2084875 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Sat, 25 Feb 2017 21:38:10 -0700 Subject: align defnList better when AlignLeft --- Brick/Widgets/DefnList.hs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'Brick') diff --git a/Brick/Widgets/DefnList.hs b/Brick/Widgets/DefnList.hs index 090428f..6ce0f48 100644 --- a/Brick/Widgets/DefnList.hs +++ b/Brick/Widgets/DefnList.hs @@ -19,16 +19,20 @@ defnList align attr defns = vBox $ line <$> defns where line (label, content) = markup $ (T.pack label @@ labelAttr) <> (T.pack sep @@ V.defAttr) - <> (if align == AlignRight - then (T.pack (gap label content) @@ V.defAttr) - else mempty - ) + <> (T.pack (gap label content) @@ V.defAttr) <> (T.pack content @@ V.defAttr) - gap a b = take (maxWidth - length a - length b - length sep) $ - repeat ' ' + gap a b + | align == AlignRight = + take (maxWidth - length a - length b - length sep) $ + repeat ' ' + | align == AlignLeft = + take (maxLabelWidth - length a) $ + repeat ' ' + maxWidth = maximum $ map (\(x,y) -> length sep + length x + length y) defns + maxLabelWidth = maximum $ map (\(x,y) -> length x) defns sep = if align == AlignRight then ": " else ": " labelAttr = maybe V.defAttr id attr -- cgit v1.2.3