From 04755d48f1e784afbf892e77d4f151d1936e353e Mon Sep 17 00:00:00 2001 From: Jonathan Daugherty Date: Sat, 23 Jan 2016 16:03:58 -0800 Subject: [PATCH] Core: make fixed padding take precedence over padded widgets (fixes #42) Prior to this commit, padding a widget meant that if there was room after rendering the widget, the specified amount of padding would be added. This meant that under tight layout constraints padding would disappear before a padded widget would. This is often a desirable outcome but it also led to unexpected behavior when adding padding to a widget that grows greedily: fixed padding would never show up because it was placed in a box adjacent to the widget in question, and boxes always render greedy children before fixed ones. As a result fixed padding would disappear under these conditions. Instead, in the case of fixed padding, since we often intend to *guarantee* that padding is present, all of the padding combinators have been modified so that when the padded widget is rendered with fixed padding in the amount V, the widget is given V fewer rows/columns when it is rendered so that the padding always has room. --- src/Brick/Widgets/Core.hs | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/Brick/Widgets/Core.hs b/src/Brick/Widgets/Core.hs index 0eb3354..1d8ac78 100644 --- a/src/Brick/Widgets/Core.hs +++ b/src/Brick/Widgets/Core.hs @@ -153,7 +153,11 @@ padLeft padding p = Max -> (id, Greedy) Pad i -> (hLimit i, hSize p) in Widget sz (vSize p) $ do - result <- render p + c <- getContext + let lim = case padding of + Max -> c^.availWidthL + Pad i -> c^.availWidthL - i + result <- render $ hLimit lim p render $ (f $ vLimit (result^.imageL.to V.imageHeight) $ fill ' ') <+> (Widget Fixed Fixed $ return result) @@ -166,7 +170,11 @@ padRight padding p = Max -> (id, Greedy) Pad i -> (hLimit i, hSize p) in Widget sz (vSize p) $ do - result <- render p + c <- getContext + let lim = case padding of + Max -> c^.availWidthL + Pad i -> c^.availWidthL - i + result <- render $ hLimit lim p render $ (Widget Fixed Fixed $ return result) <+> (f $ vLimit (result^.imageL.to V.imageHeight) $ fill ' ') @@ -178,7 +186,11 @@ padTop padding p = Max -> (id, Greedy) Pad i -> (vLimit i, vSize p) in Widget (hSize p) sz $ do - result <- render p + c <- getContext + let lim = case padding of + Max -> c^.availHeightL + Pad i -> c^.availHeightL - i + result <- render $ vLimit lim p render $ (f $ hLimit (result^.imageL.to V.imageWidth) $ fill ' ') <=> (Widget Fixed Fixed $ return result) @@ -191,7 +203,11 @@ padBottom padding p = Max -> (id, Greedy) Pad i -> (vLimit i, vSize p) in Widget (hSize p) sz $ do - result <- render p + c <- getContext + let lim = case padding of + Max -> c^.availHeightL + Pad i -> c^.availHeightL - i + result <- render $ vLimit lim p render $ (Widget Fixed Fixed $ return result) <=> (f $ hLimit (result^.imageL.to V.imageWidth) $ fill ' ')