From bf2f6be8700b749d16b9f24f5f8f5a3b50eb6710 Mon Sep 17 00:00:00 2001 From: Jonathan Daugherty Date: Fri, 22 Jul 2022 16:07:00 -0700 Subject: [PATCH] Move Padding type from Brick.Types to Brick.Widgets.Core --- programs/CacheDemo.hs | 5 +++-- programs/CroppingDemo.hs | 2 +- programs/FileBrowserDemo.hs | 3 ++- programs/MouseDemo.hs | 2 +- programs/PaddingDemo.hs | 2 +- programs/ViewportScrollbarsDemo.hs | 5 +++-- src/Brick/Types.hs | 7 ------- src/Brick/Widgets/Core.hs | 7 +++++++ 8 files changed, 18 insertions(+), 15 deletions(-) diff --git a/programs/CacheDemo.hs b/programs/CacheDemo.hs index f2506c1..d84872d 100644 --- a/programs/CacheDemo.hs +++ b/programs/CacheDemo.hs @@ -17,7 +17,8 @@ import Brick.Types , BrickEvent(..) ) import Brick.Widgets.Core - ( vBox + ( Padding(..) + , vBox , padTopBottom , withDefAttr , cached @@ -51,7 +52,7 @@ drawUi i = [ui] , padTopBottom 1 $ cached ExpensiveWidget $ withDefAttr emphAttr $ str $ "This widget is cached (state = " <> show i <> ")" - , padBottom (T.Pad 1) $ + , padBottom (Pad 1) $ withDefAttr emphAttr $ str $ "This widget is not cached (state = " <> show i <> ")" , hCenter $ str "Press 'i' to invalidate the cache," , str "'+' to change the state value, and" diff --git a/programs/CroppingDemo.hs b/programs/CroppingDemo.hs index a5ff63d..e8fc139 100644 --- a/programs/CroppingDemo.hs +++ b/programs/CroppingDemo.hs @@ -4,7 +4,6 @@ module Main where import Brick.Main (App(..), neverShowCursor, resizeOrQuit, defaultMain) import Brick.Types ( Widget - , Padding(..) ) import Brick.Widgets.Core ( vBox @@ -20,6 +19,7 @@ import Brick.Widgets.Core , cropRightTo , cropTopTo , cropBottomTo + , Padding(..) ) import Brick.Widgets.Border (border) import Brick.AttrMap (attrMap) diff --git a/programs/FileBrowserDemo.hs b/programs/FileBrowserDemo.hs index eb59c20..11a58ec 100644 --- a/programs/FileBrowserDemo.hs +++ b/programs/FileBrowserDemo.hs @@ -28,6 +28,7 @@ import Brick.Widgets.Core ( vBox, (<=>), padTop , hLimit, vLimit, txt , withDefAttr, emptyWidget + , Padding(..) ) import qualified Brick.Widgets.FileBrowser as FB import qualified Brick.AttrMap as A @@ -45,7 +46,7 @@ drawUI b = [center $ ui <=> help] hLimit 50 $ borderWithLabel (txt "Choose a file") $ FB.renderFileBrowser True b - help = padTop (T.Pad 1) $ + help = padTop (Pad 1) $ vBox [ case FB.fileBrowserException b of Nothing -> emptyWidget Just e -> hCenter $ withDefAttr errorAttr $ diff --git a/programs/MouseDemo.hs b/programs/MouseDemo.hs index fd6e4f5..179dcb7 100644 --- a/programs/MouseDemo.hs +++ b/programs/MouseDemo.hs @@ -45,7 +45,7 @@ drawUi st = buttonLayer :: St -> Widget Name buttonLayer st = C.vCenterLayer $ - C.hCenterLayer (padBottom (T.Pad 1) $ str "Click a button:") <=> + C.hCenterLayer (padBottom (Pad 1) $ str "Click a button:") <=> C.hCenterLayer (hBox $ padLeftRight 1 <$> buttons) <=> C.hCenterLayer (padTopBottom 1 $ str "Or enter text and then click in this editor:") <=> C.hCenterLayer (vLimit 3 $ hLimit 50 $ E.renderEditor (str . unlines) True (st^.edit)) diff --git a/programs/PaddingDemo.hs b/programs/PaddingDemo.hs index 25a7466..2c3730b 100644 --- a/programs/PaddingDemo.hs +++ b/programs/PaddingDemo.hs @@ -4,7 +4,6 @@ module Main where import Brick.Main (App(..), neverShowCursor, resizeOrQuit, defaultMain) import Brick.Types ( Widget - , Padding(..) ) import Brick.Widgets.Core ( vBox @@ -17,6 +16,7 @@ import Brick.Widgets.Core , padBottom , padTopBottom , padLeftRight + , Padding(..) ) import qualified Brick.Widgets.Border as B import qualified Brick.Widgets.Center as C diff --git a/programs/ViewportScrollbarsDemo.hs b/programs/ViewportScrollbarsDemo.hs index b082d35..b514066 100644 --- a/programs/ViewportScrollbarsDemo.hs +++ b/programs/ViewportScrollbarsDemo.hs @@ -29,7 +29,8 @@ import Brick.AttrMap , attrMap ) import Brick.Widgets.Core - ( hLimit + ( Padding(..) + , hLimit , vLimit , padRight , hBox @@ -72,7 +73,7 @@ drawUi st = [ui] , C.hCenter (str "Last clicked scroll bar element:") , str $ show $ _lastClickedElement st ]) - pair = hBox [ padRight (T.Pad 5) $ + pair = hBox [ padRight (Pad 5) $ B.border $ withClickableHScrollBars SBClick $ withHScrollBars OnBottom $ diff --git a/src/Brick/Types.hs b/src/Brick/Types.hs index e223eb4..ff174fb 100644 --- a/src/Brick/Types.hs +++ b/src/Brick/Types.hs @@ -84,7 +84,6 @@ module Brick.Types -- * Miscellaneous , Size(..) - , Padding(..) , Direction(..) -- * Renderer internals (for benchmarking) @@ -113,12 +112,6 @@ import Brick.Types.Internal import Brick.Types.EventM import Brick.AttrMap (AttrName, attrMapLookup) --- | The type of padding. -data Padding = Pad Int - -- ^ Pad by the specified number of rows or columns. - | Max - -- ^ Pad up to the number of available rows or columns. - -- | Given a state value and an 'EventM' that mutates that state, run -- the specified action and return both the resulting modified state and -- the result of the action itself. diff --git a/src/Brick/Widgets/Core.hs b/src/Brick/Widgets/Core.hs index daabed5..6d80dc9 100644 --- a/src/Brick/Widgets/Core.hs +++ b/src/Brick/Widgets/Core.hs @@ -22,6 +22,7 @@ module Brick.Widgets.Core , hyperlink -- * Padding + , Padding(..) , padLeft , padRight , padTop @@ -375,6 +376,12 @@ hyperlink url p = let attr = (c^.attrL) `V.withURL` url withReaderT (ctxAttrMapL %~ setDefaultAttr attr) (render p) +-- | The type of padding. +data Padding = Pad Int + -- ^ Pad by the specified number of rows or columns. + | Max + -- ^ Pad up to the number of available rows or columns. + -- | Pad the specified widget on the left. If max padding is used, this -- grows greedily horizontally; otherwise it defers to the padded -- widget.