Description
Haskell implementation of GListModel interface from gi-gio.
Description
Please see the README at: https://git.coop/akshay/gi-gio-hs-list-model#gi-gio-hs-list-model
README.md
gi-gio-hs-list-model
This library implements the GListModelInterface
which is required for using ListView
. The library can be used in two ways:
- use the provided
SeqStore
which uses aSeq
underneath to store the list, or - implement functions required for
CustomStoreImpl
in the waySeqStore
does.
Example use of SeqStore
with ListView
data Person = Person { name :: Text, age :: Int }
mkListView :: IO Gtk.ListView
mkListView workChan messageViewStore = do
factory <- new Gtk.SignalListItemFactory [ On #setup createEmptyItem
, On #bind populateItem
]
model <- seqStoreNew [ Person "Faizal Khan" 30
, Person "Ramadhir Singh" 60
]
selection <- new Gtk.SingleSelection [#model := model]
new Gtk.ListView [ #model := selection, #factory := factory]
createEmptyItem :: Gtk.ListItem -> IO ()
createEmptyItem listItem = do
label <- new Gtk.Label []
set listItem [#child := label]
populateItem :: Gtk.ListItem -> IO ()
populateItem listItem = do
item <- fromJust <$> get listItem #item
person <- fromJust <$> CustomStoreItem.fromObject @Person storeItem
child <- fromJust <$> get convListItem #child
label <- fromJust <$> Gtk.castTo Gtk.Label child
set label [ #label := name person <> ", " <> Text.pack (show (age person)) ]