2{-# LANGUAGE ExplicitForAll #-}
3{-# LANGUAGE MultiParamTypeClasses #-}
4{-# LANGUAGE RecursiveDo #-}
5#ifdef USE_REFLEX_OPTIMIZER
6{-# OPTIONS_GHC -fplugin=Reflex.Optimizer #-}
9module Reflex.Widget.Basic where
11import Control.Monad.Fix (MonadFix)
15import Reflex.Adjustable.Class
16import Data.Patch.MapWithMove
19-- | Build sortable content in such a way that re-sorting it can cause minimal
20-- disruption to an existing context.
22-- Naively re-sorting a list of images would destroy every image and add them back
23-- in the new order. This framework is able to avoid that by preserving the
24-- identity of each image and simply moving it to the new location.
28-- > let sortByFst = buttonA $> comparing fst
29-- > sortBySnd = buttonB $> comparing snd
30-- > sortEvent = leftmost [sortByFst, sortBySnd]
32-- > (\k v -> text $ "\n" ++ show k ++ " " ++ v) -- show each element on a new line
33-- > (Map.fromList $ zip [0..] [(3, "a"), (2, "b"), (1, "c")])
35sortableList :: forall t m k v a. (MonadHold t m, MonadFix m, Adjustable t m, Ord k)
36 => (k -> v -> m a) -- ^ Function to render the content for each key/value pair
37 -> Map k v -- ^ The sortable list with an initial ordering determined by the @Map@ keys in ascending order
38 -> Event t (v -> v -> Ordering) -- ^ An event carrying a sort function for the list
40sortableList f m0 reSortFunc = do
41 rec let reSortPatch = attachWith (flip patchThatSortsMapWith) (currentIncremental m) reSortFunc
42 m <- holdIncremental m0 reSortPatch
43 (results, _) <- mapMapWithAdjustWithMove f m0 reSortPatch
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list