Decouple selection section inventory position

This commit is contained in:
2024-10-24 14:55:51 +01:00
parent 81f4f38166
commit 388064895f
17 changed files with 304 additions and 261 deletions
+9 -12
View File
@@ -3,7 +3,7 @@ module Dodge.SelectionSections (
ssLookupDown,
ssLookupGT,
ssSetCursor,
setFirstPosSelectionSections,
-- setFirstPosSelectionSections,
selSecYint,
selSecSelSize,
inverseSelSecYint,
@@ -31,10 +31,10 @@ scrollSelectionSections yi sss msel
| yi > 0 = foldr ($) msel $ replicate yi (ssScrollUsing ssLookupUp sss)
| otherwise = foldr ($) msel $ replicate (negate yi) (ssScrollUsing ssLookupDown sss)
setFirstPosSelectionSections :: SelectionSections a -> SelectionSections a
setFirstPosSelectionSections sss = fromMaybe sss $ do
(i, j, _) <- ssLookupMin sss
return $ sss & sssExtra . sssSelPos ?~ (i, j)
--setFirstPosSelectionSections :: SelectionSections a -> SelectionSections a
--setFirstPosSelectionSections sss = fromMaybe sss $ do
-- (i, j, _) <- ssLookupMin sss
-- return $ sss & sssExtra . sssSelPos ?~ (i, j)
ssScrollUsing ::
(Int -> Int -> SelectionSections a -> Maybe (Int, Int, SelectionItem a)) ->
@@ -66,14 +66,11 @@ ssScrollMinOnFail f sss msel = fmap (\(i, j, _) -> (i, j)) $ l <|> ssLookupMin s
ssSetCursor ::
(SelectionSections a -> Maybe (Int, Int, SelectionItem a)) ->
SelectionSections a ->
SelectionSections a
ssSetCursor f sss = fromMaybe sss $ do
Maybe (Int,Int) ->
Maybe (Int,Int)
ssSetCursor f sss msel = fromMaybe msel $ do
(i, j, _) <- f sss
return $
sss
& sssExtra . sssSelPos ?~ (i, j)
-- & sssSections . ix i . ssCursor ?~ SectionCursor j j (_siHeight si) (_siColor si)
return $ Just (i, j)
ssLookupMax :: SelectionSections a -> Maybe (Int, Int, SelectionItem a)
ssLookupMax sss = do