{-# OPTIONS_HADDOCK show-extensions #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE NoFieldSelectors #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE ExistentialQuantification #-}
-- | Types shared by tabular list widgets.
--
-- You don't have to import this module because modules for tabular list widgets re-export this module.
module Brick.Widgets.TabularList.Types (
-- * Tabular dimensions
  RowHdrWidth(..)
, ColWidth(..)
, ColHdrHeight(..)
, ListItemHeight(..)
-- * Shared rendering context
, Index(..)
, AvailWidth(..)
, WidthDeficit(..)
, ListFocused(..)
, Selected(..)
-- * Row header
, RowHdrCtxt(..)
, RowHdr(..)
, ColHdrRowHdr(..)
) where

-- base
import GHC.Generics (Generic)
-- brick
import Brick.Types
import Brick.Widgets.Center
import Brick.Widgets.Core

-- | Index of a tabular list component among the same kind of components
newtype Index = Ix Int deriving (Int -> Index
Index -> Int
Index -> [Index]
Index -> Index
Index -> Index -> [Index]
Index -> Index -> Index -> [Index]
(Index -> Index)
-> (Index -> Index)
-> (Int -> Index)
-> (Index -> Int)
-> (Index -> [Index])
-> (Index -> Index -> [Index])
-> (Index -> Index -> [Index])
-> (Index -> Index -> Index -> [Index])
-> Enum Index
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: Index -> Index
succ :: Index -> Index
$cpred :: Index -> Index
pred :: Index -> Index
$ctoEnum :: Int -> Index
toEnum :: Int -> Index
$cfromEnum :: Index -> Int
fromEnum :: Index -> Int
$cenumFrom :: Index -> [Index]
enumFrom :: Index -> [Index]
$cenumFromThen :: Index -> Index -> [Index]
enumFromThen :: Index -> Index -> [Index]
$cenumFromTo :: Index -> Index -> [Index]
enumFromTo :: Index -> Index -> [Index]
$cenumFromThenTo :: Index -> Index -> Index -> [Index]
enumFromThenTo :: Index -> Index -> Index -> [Index]
Enum, Index -> Index -> Bool
(Index -> Index -> Bool) -> (Index -> Index -> Bool) -> Eq Index
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Index -> Index -> Bool
== :: Index -> Index -> Bool
$c/= :: Index -> Index -> Bool
/= :: Index -> Index -> Bool
Eq, (forall x. Index -> Rep Index x)
-> (forall x. Rep Index x -> Index) -> Generic Index
forall x. Rep Index x -> Index
forall x. Index -> Rep Index x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Index -> Rep Index x
from :: forall x. Index -> Rep Index x
$cto :: forall x. Rep Index x -> Index
to :: forall x. Rep Index x -> Index
Generic, Int -> Index -> ShowS
[Index] -> ShowS
Index -> String
(Int -> Index -> ShowS)
-> (Index -> String) -> ([Index] -> ShowS) -> Show Index
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Index -> ShowS
showsPrec :: Int -> Index -> ShowS
$cshow :: Index -> String
show :: Index -> String
$cshowList :: [Index] -> ShowS
showList :: [Index] -> ShowS
Show)

-- | Width for row header
newtype RowHdrWidth = RowHdrW Int deriving (RowHdrWidth -> RowHdrWidth -> Bool
(RowHdrWidth -> RowHdrWidth -> Bool)
-> (RowHdrWidth -> RowHdrWidth -> Bool) -> Eq RowHdrWidth
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: RowHdrWidth -> RowHdrWidth -> Bool
== :: RowHdrWidth -> RowHdrWidth -> Bool
$c/= :: RowHdrWidth -> RowHdrWidth -> Bool
/= :: RowHdrWidth -> RowHdrWidth -> Bool
Eq, (forall x. RowHdrWidth -> Rep RowHdrWidth x)
-> (forall x. Rep RowHdrWidth x -> RowHdrWidth)
-> Generic RowHdrWidth
forall x. Rep RowHdrWidth x -> RowHdrWidth
forall x. RowHdrWidth -> Rep RowHdrWidth x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. RowHdrWidth -> Rep RowHdrWidth x
from :: forall x. RowHdrWidth -> Rep RowHdrWidth x
$cto :: forall x. Rep RowHdrWidth x -> RowHdrWidth
to :: forall x. Rep RowHdrWidth x -> RowHdrWidth
Generic, Int -> RowHdrWidth -> ShowS
[RowHdrWidth] -> ShowS
RowHdrWidth -> String
(Int -> RowHdrWidth -> ShowS)
-> (RowHdrWidth -> String)
-> ([RowHdrWidth] -> ShowS)
-> Show RowHdrWidth
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> RowHdrWidth -> ShowS
showsPrec :: Int -> RowHdrWidth -> ShowS
$cshow :: RowHdrWidth -> String
show :: RowHdrWidth -> String
$cshowList :: [RowHdrWidth] -> ShowS
showList :: [RowHdrWidth] -> ShowS
Show)

-- | Width of a column header or a row column
newtype ColWidth = ColW Int deriving (ColWidth -> ColWidth -> Bool
(ColWidth -> ColWidth -> Bool)
-> (ColWidth -> ColWidth -> Bool) -> Eq ColWidth
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ColWidth -> ColWidth -> Bool
== :: ColWidth -> ColWidth -> Bool
$c/= :: ColWidth -> ColWidth -> Bool
/= :: ColWidth -> ColWidth -> Bool
Eq, (forall x. ColWidth -> Rep ColWidth x)
-> (forall x. Rep ColWidth x -> ColWidth) -> Generic ColWidth
forall x. Rep ColWidth x -> ColWidth
forall x. ColWidth -> Rep ColWidth x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. ColWidth -> Rep ColWidth x
from :: forall x. ColWidth -> Rep ColWidth x
$cto :: forall x. Rep ColWidth x -> ColWidth
to :: forall x. Rep ColWidth x -> ColWidth
Generic, Int -> ColWidth -> ShowS
[ColWidth] -> ShowS
ColWidth -> String
(Int -> ColWidth -> ShowS)
-> (ColWidth -> String) -> ([ColWidth] -> ShowS) -> Show ColWidth
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ColWidth -> ShowS
showsPrec :: Int -> ColWidth -> ShowS
$cshow :: ColWidth -> String
show :: ColWidth -> String
$cshowList :: [ColWidth] -> ShowS
showList :: [ColWidth] -> ShowS
Show)

-- | Height for column headers and column header row header
newtype ColHdrHeight = ColHdrH Int deriving (ColHdrHeight -> ColHdrHeight -> Bool
(ColHdrHeight -> ColHdrHeight -> Bool)
-> (ColHdrHeight -> ColHdrHeight -> Bool) -> Eq ColHdrHeight
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ColHdrHeight -> ColHdrHeight -> Bool
== :: ColHdrHeight -> ColHdrHeight -> Bool
$c/= :: ColHdrHeight -> ColHdrHeight -> Bool
/= :: ColHdrHeight -> ColHdrHeight -> Bool
Eq, (forall x. ColHdrHeight -> Rep ColHdrHeight x)
-> (forall x. Rep ColHdrHeight x -> ColHdrHeight)
-> Generic ColHdrHeight
forall x. Rep ColHdrHeight x -> ColHdrHeight
forall x. ColHdrHeight -> Rep ColHdrHeight x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. ColHdrHeight -> Rep ColHdrHeight x
from :: forall x. ColHdrHeight -> Rep ColHdrHeight x
$cto :: forall x. Rep ColHdrHeight x -> ColHdrHeight
to :: forall x. Rep ColHdrHeight x -> ColHdrHeight
Generic, Int -> ColHdrHeight -> ShowS
[ColHdrHeight] -> ShowS
ColHdrHeight -> String
(Int -> ColHdrHeight -> ShowS)
-> (ColHdrHeight -> String)
-> ([ColHdrHeight] -> ShowS)
-> Show ColHdrHeight
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ColHdrHeight -> ShowS
showsPrec :: Int -> ColHdrHeight -> ShowS
$cshow :: ColHdrHeight -> String
show :: ColHdrHeight -> String
$cshowList :: [ColHdrHeight] -> ShowS
showList :: [ColHdrHeight] -> ShowS
Show)

-- | The fixed height for row headers and row columns.
--
-- If the height of row headers or row columns is not this height, then the list will look broken.
newtype ListItemHeight = LstItmH Int deriving (ListItemHeight -> ListItemHeight -> Bool
(ListItemHeight -> ListItemHeight -> Bool)
-> (ListItemHeight -> ListItemHeight -> Bool) -> Eq ListItemHeight
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ListItemHeight -> ListItemHeight -> Bool
== :: ListItemHeight -> ListItemHeight -> Bool
$c/= :: ListItemHeight -> ListItemHeight -> Bool
/= :: ListItemHeight -> ListItemHeight -> Bool
Eq, (forall x. ListItemHeight -> Rep ListItemHeight x)
-> (forall x. Rep ListItemHeight x -> ListItemHeight)
-> Generic ListItemHeight
forall x. Rep ListItemHeight x -> ListItemHeight
forall x. ListItemHeight -> Rep ListItemHeight x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. ListItemHeight -> Rep ListItemHeight x
from :: forall x. ListItemHeight -> Rep ListItemHeight x
$cto :: forall x. Rep ListItemHeight x -> ListItemHeight
to :: forall x. Rep ListItemHeight x -> ListItemHeight
Generic, Int -> ListItemHeight -> ShowS
[ListItemHeight] -> ShowS
ListItemHeight -> String
(Int -> ListItemHeight -> ShowS)
-> (ListItemHeight -> String)
-> ([ListItemHeight] -> ShowS)
-> Show ListItemHeight
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ListItemHeight -> ShowS
showsPrec :: Int -> ListItemHeight -> ShowS
$cshow :: ListItemHeight -> String
show :: ListItemHeight -> String
$cshowList :: [ListItemHeight] -> ShowS
showList :: [ListItemHeight] -> ShowS
Show)

-- | Available width
newtype AvailWidth = AvlW Int deriving (AvailWidth -> AvailWidth -> Bool
(AvailWidth -> AvailWidth -> Bool)
-> (AvailWidth -> AvailWidth -> Bool) -> Eq AvailWidth
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: AvailWidth -> AvailWidth -> Bool
== :: AvailWidth -> AvailWidth -> Bool
$c/= :: AvailWidth -> AvailWidth -> Bool
/= :: AvailWidth -> AvailWidth -> Bool
Eq, (forall x. AvailWidth -> Rep AvailWidth x)
-> (forall x. Rep AvailWidth x -> AvailWidth) -> Generic AvailWidth
forall x. Rep AvailWidth x -> AvailWidth
forall x. AvailWidth -> Rep AvailWidth x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. AvailWidth -> Rep AvailWidth x
from :: forall x. AvailWidth -> Rep AvailWidth x
$cto :: forall x. Rep AvailWidth x -> AvailWidth
to :: forall x. Rep AvailWidth x -> AvailWidth
Generic, Int -> AvailWidth -> ShowS
[AvailWidth] -> ShowS
AvailWidth -> String
(Int -> AvailWidth -> ShowS)
-> (AvailWidth -> String)
-> ([AvailWidth] -> ShowS)
-> Show AvailWidth
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> AvailWidth -> ShowS
showsPrec :: Int -> AvailWidth -> ShowS
$cshow :: AvailWidth -> String
show :: AvailWidth -> String
$cshowList :: [AvailWidth] -> ShowS
showList :: [AvailWidth] -> ShowS
Show)

-- | > widthDeficit = max 0 $ desiredColumnWidth - availableWidth
--
-- It is positive when a column is shrunk to the available width.
--
-- If you use fixed paddings to introduce gaps between columns, you may want to remove fixed paddings when width deficit
-- is positive because a column is not preceded or followed by other columns and its width is shrunk.
--
-- The following examples show how to remove gaps between columns when width deficit is positive.
--
-- @
-- 'padRight' ('Pad' $ if widthDeficit > 0 then 0 else 1) $ 'padLeft' 'Max' content
-- @
--
-- @
-- 'padLeft' ('Pad' $ if widthDeficit > 0 then 0 else 1) $ 'hCenter' content
-- @
newtype WidthDeficit = WdthD Int deriving (WidthDeficit -> WidthDeficit -> Bool
(WidthDeficit -> WidthDeficit -> Bool)
-> (WidthDeficit -> WidthDeficit -> Bool) -> Eq WidthDeficit
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: WidthDeficit -> WidthDeficit -> Bool
== :: WidthDeficit -> WidthDeficit -> Bool
$c/= :: WidthDeficit -> WidthDeficit -> Bool
/= :: WidthDeficit -> WidthDeficit -> Bool
Eq, (forall x. WidthDeficit -> Rep WidthDeficit x)
-> (forall x. Rep WidthDeficit x -> WidthDeficit)
-> Generic WidthDeficit
forall x. Rep WidthDeficit x -> WidthDeficit
forall x. WidthDeficit -> Rep WidthDeficit x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. WidthDeficit -> Rep WidthDeficit x
from :: forall x. WidthDeficit -> Rep WidthDeficit x
$cto :: forall x. Rep WidthDeficit x -> WidthDeficit
to :: forall x. Rep WidthDeficit x -> WidthDeficit
Generic, Int -> WidthDeficit -> ShowS
[WidthDeficit] -> ShowS
WidthDeficit -> String
(Int -> WidthDeficit -> ShowS)
-> (WidthDeficit -> String)
-> ([WidthDeficit] -> ShowS)
-> Show WidthDeficit
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> WidthDeficit -> ShowS
showsPrec :: Int -> WidthDeficit -> ShowS
$cshow :: WidthDeficit -> String
show :: WidthDeficit -> String
$cshowList :: [WidthDeficit] -> ShowS
showList :: [WidthDeficit] -> ShowS
Show)

-- | Whether the list is focused in an application
newtype ListFocused = LstFcs Bool deriving (ListFocused -> ListFocused -> Bool
(ListFocused -> ListFocused -> Bool)
-> (ListFocused -> ListFocused -> Bool) -> Eq ListFocused
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ListFocused -> ListFocused -> Bool
== :: ListFocused -> ListFocused -> Bool
$c/= :: ListFocused -> ListFocused -> Bool
/= :: ListFocused -> ListFocused -> Bool
Eq, (forall x. ListFocused -> Rep ListFocused x)
-> (forall x. Rep ListFocused x -> ListFocused)
-> Generic ListFocused
forall x. Rep ListFocused x -> ListFocused
forall x. ListFocused -> Rep ListFocused x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. ListFocused -> Rep ListFocused x
from :: forall x. ListFocused -> Rep ListFocused x
$cto :: forall x. Rep ListFocused x -> ListFocused
to :: forall x. Rep ListFocused x -> ListFocused
Generic, Int -> ListFocused -> ShowS
[ListFocused] -> ShowS
ListFocused -> String
(Int -> ListFocused -> ShowS)
-> (ListFocused -> String)
-> ([ListFocused] -> ShowS)
-> Show ListFocused
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ListFocused -> ShowS
showsPrec :: Int -> ListFocused -> ShowS
$cshow :: ListFocused -> String
show :: ListFocused -> String
$cshowList :: [ListFocused] -> ShowS
showList :: [ListFocused] -> ShowS
Show)

-- | Whether a tabular list component is selected
newtype Selected = Sel Bool deriving (Selected -> Selected -> Bool
(Selected -> Selected -> Bool)
-> (Selected -> Selected -> Bool) -> Eq Selected
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Selected -> Selected -> Bool
== :: Selected -> Selected -> Bool
$c/= :: Selected -> Selected -> Bool
/= :: Selected -> Selected -> Bool
Eq, (forall x. Selected -> Rep Selected x)
-> (forall x. Rep Selected x -> Selected) -> Generic Selected
forall x. Rep Selected x -> Selected
forall x. Selected -> Rep Selected x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Selected -> Rep Selected x
from :: forall x. Selected -> Rep Selected x
$cto :: forall x. Rep Selected x -> Selected
to :: forall x. Rep Selected x -> Selected
Generic, Int -> Selected -> ShowS
[Selected] -> ShowS
Selected -> String
(Int -> Selected -> ShowS)
-> (Selected -> String) -> ([Selected] -> ShowS) -> Show Selected
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Selected -> ShowS
showsPrec :: Int -> Selected -> ShowS
$cshow :: Selected -> String
show :: Selected -> String
$cshowList :: [Selected] -> ShowS
showList :: [Selected] -> ShowS
Show)

-- | Row header context
newtype RowHdrCtxt = RowHdrCtxt {
  RowHdrCtxt -> Selected
selected :: Selected
} deriving (RowHdrCtxt -> RowHdrCtxt -> Bool
(RowHdrCtxt -> RowHdrCtxt -> Bool)
-> (RowHdrCtxt -> RowHdrCtxt -> Bool) -> Eq RowHdrCtxt
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: RowHdrCtxt -> RowHdrCtxt -> Bool
== :: RowHdrCtxt -> RowHdrCtxt -> Bool
$c/= :: RowHdrCtxt -> RowHdrCtxt -> Bool
/= :: RowHdrCtxt -> RowHdrCtxt -> Bool
Eq, (forall x. RowHdrCtxt -> Rep RowHdrCtxt x)
-> (forall x. Rep RowHdrCtxt x -> RowHdrCtxt) -> Generic RowHdrCtxt
forall x. Rep RowHdrCtxt x -> RowHdrCtxt
forall x. RowHdrCtxt -> Rep RowHdrCtxt x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. RowHdrCtxt -> Rep RowHdrCtxt x
from :: forall x. RowHdrCtxt -> Rep RowHdrCtxt x
$cto :: forall x. Rep RowHdrCtxt x -> RowHdrCtxt
to :: forall x. Rep RowHdrCtxt x -> RowHdrCtxt
Generic, Int -> RowHdrCtxt -> ShowS
[RowHdrCtxt] -> ShowS
RowHdrCtxt -> String
(Int -> RowHdrCtxt -> ShowS)
-> (RowHdrCtxt -> String)
-> ([RowHdrCtxt] -> ShowS)
-> Show RowHdrCtxt
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> RowHdrCtxt -> ShowS
showsPrec :: Int -> RowHdrCtxt -> ShowS
$cshow :: RowHdrCtxt -> String
show :: RowHdrCtxt -> String
$cshowList :: [RowHdrCtxt] -> ShowS
showList :: [RowHdrCtxt] -> ShowS
Show)

-- | Row header
--
-- * [Type Variables]("Brick.Widgets.TabularList#g:TypeVariables")
-- * [Rendering]("Brick.Widgets.TabularList#g:Rendering")
--
-- Type Variables
--
-- * r - the type of row header
data RowHdr n e = forall r. RowHdr {
  ()
draw :: ListFocused -> WidthDeficit -> RowHdrCtxt -> r -> Widget n
  -- | Calculate row header width from visible row headers and the width available for a list row.
, ()
width :: AvailWidth -> [r] -> RowHdrWidth
  -- | Get a row header from a list row and row index.
, ()
toRH :: e -> Index -> r
}

-- | The renderer for column header row header.
--
-- If row headers and column headers exist and 'ColHdrRowHdr' doesn't exist, then column header row header is filled
-- with empty space. 'ColHdrRowHdr' merely allows you to customize column header row header.
newtype ColHdrRowHdr n = ColHdrRowHdr (ListFocused -> WidthDeficit -> Widget n) deriving (forall x. ColHdrRowHdr n -> Rep (ColHdrRowHdr n) x)
-> (forall x. Rep (ColHdrRowHdr n) x -> ColHdrRowHdr n)
-> Generic (ColHdrRowHdr n)
forall x. Rep (ColHdrRowHdr n) x -> ColHdrRowHdr n
forall x. ColHdrRowHdr n -> Rep (ColHdrRowHdr n) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall n x. Rep (ColHdrRowHdr n) x -> ColHdrRowHdr n
forall n x. ColHdrRowHdr n -> Rep (ColHdrRowHdr n) x
$cfrom :: forall n x. ColHdrRowHdr n -> Rep (ColHdrRowHdr n) x
from :: forall x. ColHdrRowHdr n -> Rep (ColHdrRowHdr n) x
$cto :: forall n x. Rep (ColHdrRowHdr n) x -> ColHdrRowHdr n
to :: forall x. Rep (ColHdrRowHdr n) x -> ColHdrRowHdr n
Generic