brick 0.39 → 0.40
raw patch · 4 files changed
+49/−5 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Brick.Widgets.Core: hLimitPercent :: Int -> Widget n -> Widget n
+ Brick.Widgets.Core: vLimitPercent :: Int -> Widget n -> Widget n
- Brick.Widgets.Dialog: dialogButtonsL :: forall a_a12ep a_a12f6. Lens (Dialog a_a12ep) (Dialog a_a12f6) [(String, a_a12ep)] [(String, a_a12f6)]
+ Brick.Widgets.Dialog: dialogButtonsL :: forall a_a12D7 a_a12DO. Lens (Dialog a_a12D7) (Dialog a_a12DO) [(String, a_a12D7)] [(String, a_a12DO)]
- Brick.Widgets.Dialog: dialogSelectedIndexL :: forall a_a12ep. Lens' (Dialog a_a12ep) (Maybe Int)
+ Brick.Widgets.Dialog: dialogSelectedIndexL :: forall a_a12D7. Lens' (Dialog a_a12D7) (Maybe Int)
- Brick.Widgets.Dialog: dialogTitleL :: forall a_a12ep. Lens' (Dialog a_a12ep) (Maybe String)
+ Brick.Widgets.Dialog: dialogTitleL :: forall a_a12D7. Lens' (Dialog a_a12D7) (Maybe String)
- Brick.Widgets.Dialog: dialogWidthL :: forall a_a12ep. Lens' (Dialog a_a12ep) Int
+ Brick.Widgets.Dialog: dialogWidthL :: forall a_a12D7. Lens' (Dialog a_a12D7) Int
- Brick.Widgets.Edit: editContentsL :: forall t_aXRq n_aXRr t_aXSa. Lens (Editor t_aXRq n_aXRr) (Editor t_aXSa n_aXRr) (TextZipper t_aXRq) (TextZipper t_aXSa)
+ Brick.Widgets.Edit: editContentsL :: forall t_aYg8 n_aYg9 t_aYgS. Lens (Editor t_aYg8 n_aYg9) (Editor t_aYgS n_aYg9) (TextZipper t_aYg8) (TextZipper t_aYgS)
- Brick.Widgets.List: listElementsL :: forall n_a16L8 e_a16L9 e_a16UQ. Lens (List n_a16L8 e_a16L9) (List n_a16L8 e_a16UQ) (Vector e_a16L9) (Vector e_a16UQ)
+ Brick.Widgets.List: listElementsL :: forall n_a179Q e_a179R e_a17jy. Lens (List n_a179Q e_a179R) (List n_a179Q e_a17jy) (Vector e_a179R) (Vector e_a17jy)
- Brick.Widgets.List: listItemHeightL :: forall n_a16L8 e_a16L9. Lens' (List n_a16L8 e_a16L9) Int
+ Brick.Widgets.List: listItemHeightL :: forall n_a179Q e_a179R. Lens' (List n_a179Q e_a179R) Int
- Brick.Widgets.List: listNameL :: forall n_a16L8 e_a16L9 n_a16UR. Lens (List n_a16L8 e_a16L9) (List n_a16UR e_a16L9) n_a16L8 n_a16UR
+ Brick.Widgets.List: listNameL :: forall n_a179Q e_a179R n_a17jz. Lens (List n_a179Q e_a179R) (List n_a17jz e_a179R) n_a179Q n_a17jz
- Brick.Widgets.List: listSelectedL :: forall n_a16L8 e_a16L9. Lens' (List n_a16L8 e_a16L9) (Maybe Int)
+ Brick.Widgets.List: listSelectedL :: forall n_a179Q e_a179R. Lens' (List n_a179Q e_a179R) (Maybe Int)
Files
- CHANGELOG.md +9/−0
- brick.cabal +1/−1
- programs/FillDemo.hs +5/−2
- src/Brick/Widgets/Core.hs +34/−2
CHANGELOG.md view
@@ -2,6 +2,15 @@ Brick changelog --------------- +0.40+----++New features:+ * Brick.Widgets.Core: added new functions `hLimitPercent` and+ `vLimitPercent`. These behave similarly to `hLimit` and `vLimit`+ except that instead of taking absolute numbers of columns or rows,+ they take percentages. (Thanks Roman Joost)+ 0.39 ----
brick.cabal view
@@ -1,5 +1,5 @@ name: brick-version: 0.39+version: 0.40 synopsis: A declarative terminal user interface library description: Write terminal applications painlessly with 'brick'! You write an
programs/FillDemo.hs view
@@ -1,10 +1,13 @@ module Main where import Brick+import Brick.Widgets.Border ui :: Widget ()-ui = vBox [ str "This text is at the top."- , fill ' '+ui = vBox [ vLimitPercent 20 $ vBox [ str "This text is at the top."+ , fill ' '+ , hBorder+ ] , str "This text is at the bottom." ]
src/Brick/Widgets/Core.hs view
@@ -38,7 +38,9 @@ -- * Limits , hLimit+ , hLimitPercent , vLimit+ , vLimitPercent , setAvailableSize -- * Attribute management@@ -757,16 +759,46 @@ hLimit :: Int -> Widget n -> Widget n hLimit w p = Widget Fixed (vSize p) $- withReaderT (& availWidthL %~ (min w)) $ render $ cropToContext p+ withReaderT (availWidthL %~ (min w)) $ render $ cropToContext p -- | Limit the space available to the specified widget to the specified+-- percentage of available width, as a value between 0 and 100+-- inclusive. Values outside the valid range will be clamped to the+-- range endpoints. This is important for constraining the horizontal+-- growth of otherwise-greedy widgets. This is non-greedy horizontally+-- and defers to the limited widget vertically.+hLimitPercent :: Int -> Widget n -> Widget n+hLimitPercent w' p =+ Widget Fixed (vSize p) $ do+ let w = clamp 0 100 w'+ ctx <- getContext+ let usableWidth = ctx^.availWidthL+ widgetWidth = round (toRational usableWidth * (toRational w / 100))+ withReaderT (availWidthL %~ (min widgetWidth)) $ render $ cropToContext p++-- | Limit the space available to the specified widget to the specified -- number of rows. This is important for constraining the vertical -- growth of otherwise-greedy widgets. This is non-greedy vertically and -- defers to the limited widget horizontally. vLimit :: Int -> Widget n -> Widget n vLimit h p = Widget (hSize p) Fixed $- withReaderT (& availHeightL %~ (min h)) $ render $ cropToContext p+ withReaderT (availHeightL %~ (min h)) $ render $ cropToContext p++-- | Limit the space available to the specified widget to the specified+-- percentage of available height, as a value between 0 and 100+-- inclusive. Values outside the valid range will be clamped to the+-- range endpoints. This is important for constraining the vertical+-- growth of otherwise-greedy widgets. This is non-greedy vertically and+-- defers to the limited widget horizontally.+vLimitPercent :: Int -> Widget n -> Widget n+vLimitPercent h' p =+ Widget (vSize p) Fixed $ do+ let h = clamp 0 100 h'+ ctx <- getContext+ let usableHeight = ctx^.availHeightL+ widgetHeight = round (toRational usableHeight * (toRational h / 100))+ withReaderT (availHeightL %~ (min widgetHeight)) $ render $ cropToContext p -- | Set the rendering context height and width for this widget. This -- is useful for relaxing the rendering size constraints on e.g. layer