ui: register: wide-char-aware layout

This commit is contained in:
Simon Michael 2015-10-10 12:26:17 -07:00
parent 3b40edba9c
commit bcc22a0367

View File

@ -124,8 +124,8 @@ drawRegisterScreen AppState{ -- aopts=_uopts@UIOpts{cliopts_=_copts@CliOpts{repo
whitespacewidth = 10 -- inter-column whitespace, fixed width whitespacewidth = 10 -- inter-column whitespace, fixed width
minnonamtcolswidth = datewidth + 2 + 2 -- date column plus at least 2 for desc and accts minnonamtcolswidth = datewidth + 2 + 2 -- date column plus at least 2 for desc and accts
maxamtswidth = max 0 (totalwidth - minnonamtcolswidth - whitespacewidth) maxamtswidth = max 0 (totalwidth - minnonamtcolswidth - whitespacewidth)
maxchangewidthseen = maximum' $ map (length . fourth5) displayitems maxchangewidthseen = maximum' $ map (strWidth . fourth5) displayitems
maxbalwidthseen = maximum' $ map (length . fifth5) displayitems maxbalwidthseen = maximum' $ map (strWidth . fifth5) displayitems
changewidthproportion = fromIntegral maxchangewidthseen / fromIntegral (maxchangewidthseen + maxbalwidthseen) changewidthproportion = fromIntegral maxchangewidthseen / fromIntegral (maxchangewidthseen + maxbalwidthseen)
maxchangewidth = round $ changewidthproportion * fromIntegral maxamtswidth maxchangewidth = round $ changewidthproportion * fromIntegral maxamtswidth
maxbalwidth = maxamtswidth - maxchangewidth maxbalwidth = maxamtswidth - maxchangewidth
@ -138,8 +138,8 @@ drawRegisterScreen AppState{ -- aopts=_uopts@UIOpts{cliopts_=_copts@CliOpts{repo
-- trace (show (totalwidth, datewidth, changewidth, balwidth, whitespacewidth)) $ -- trace (show (totalwidth, datewidth, changewidth, balwidth, whitespacewidth)) $
max 0 (totalwidth - datewidth - changewidth - balwidth - whitespacewidth) max 0 (totalwidth - datewidth - changewidth - balwidth - whitespacewidth)
-- allocating proportionally. -- allocating proportionally.
-- descwidth' = maximum' $ map (length . second5) displayitems -- descwidth' = maximum' $ map (strWidth . second5) displayitems
-- acctswidth' = maximum' $ map (length . third5) displayitems -- acctswidth' = maximum' $ map (strWidth . third5) displayitems
-- descwidthproportion = (descwidth' + acctswidth') / descwidth' -- descwidthproportion = (descwidth' + acctswidth') / descwidth'
-- maxdescwidth = min (maxdescacctswidth - 7) (maxdescacctswidth / descwidthproportion) -- maxdescwidth = min (maxdescacctswidth - 7) (maxdescacctswidth / descwidthproportion)
-- maxacctswidth = maxdescacctswidth - maxdescwidth -- maxacctswidth = maxdescacctswidth - maxdescwidth
@ -164,15 +164,15 @@ drawRegisterItem :: (Int,Int,Int,Int,Int) -> Bool -> (String,String,String,Strin
drawRegisterItem (datewidth,descwidth,acctswidth,changewidth,balwidth) selected (date,desc,accts,change,bal) = drawRegisterItem (datewidth,descwidth,acctswidth,changewidth,balwidth) selected (date,desc,accts,change,bal) =
Widget Greedy Fixed $ do Widget Greedy Fixed $ do
render $ render $
str (padright datewidth $ elideRight datewidth date) <+> str (fitString (Just datewidth) (Just datewidth) True True date) <+>
str " " <+> str " " <+>
str (padright descwidth $ elideRight descwidth desc) <+> str (fitString (Just descwidth) (Just descwidth) True True desc) <+>
str " " <+> str " " <+>
str (padright acctswidth $ elideLeft acctswidth $ accts) <+> str (fitString (Just acctswidth) (Just acctswidth) True True accts) <+>
str " " <+> str " " <+>
withAttr changeattr (str (padleft changewidth $ elideLeft changewidth change)) <+> withAttr changeattr (str (fitString (Just changewidth) (Just changewidth) True False change)) <+>
str " " <+> str " " <+>
withAttr balattr (str (padleft balwidth $ elideLeft balwidth bal)) withAttr balattr (str (fitString (Just balwidth) (Just balwidth) True False bal))
where where
changeattr | '-' `elem` change = sel $ "list" <> "amount" <> "decrease" changeattr | '-' `elem` change = sel $ "list" <> "amount" <> "decrease"
| otherwise = sel $ "list" <> "amount" <> "increase" | otherwise = sel $ "list" <> "amount" <> "increase"