Improve x position check over selection items

This commit is contained in:
2024-11-25 10:03:19 +00:00
parent 9e0f0536e2
commit 2299ec374c
4 changed files with 85 additions and 138 deletions
-8
View File
@@ -303,11 +303,3 @@ scrollAugNextInSection w =
doscroll he = fromMaybe he $ do
sss <- he ^? diSections
return $ he & diSelection %~ nextInSectionSS sss
--selectedCloseItem :: World -> Maybe FloorItem
--selectedCloseItem w = do
-- i <-
-- you w ^? crManipulation . manObject . ispCloseItem
-- <|> fmap fst (IM.lookupMin =<< w ^? hud . hudElement . diSections . ix 3 . ssItems)
-- flitid <- w ^? hud . closeItems . ix i . unNInt
-- w ^? cWorld . lWorld . floorItems . unNIntMap . ix flitid
+10 -51
View File
@@ -2,17 +2,12 @@ module Dodge.SelectionSections (
scrollSelectionSections,
nextInSectionSS,
ssLookupDown,
ssLookupGT,
ssTryLookup,
ssSetCursor,
-- setFirstPosSelectionSections,
selSecYint,
selSecSelSize,
inverseSelSecYint,
posSelSecYint,
inverseSelNumPos,
inverseSelBoundaryUp,
inverseSelBoundaryDown,
) where
import Control.Applicative
@@ -78,12 +73,6 @@ ssSetCursor f sss msel = fromMaybe msel $ do
(i, j, _) <- f sss
return $ Just (i, j)
ssTryLookup :: Maybe (Int,Int) -> IM.IntMap (SelectionSection a) -> Maybe (Int, Int, SelectionItem a)
ssTryLookup msel sss = fromMaybe (ssLookupMin sss) $ do
(i,j) <- msel
itm <- sss ^? ix i . ssItems . ix j
return $ Just (i,j,itm)
ssLookupMax :: IM.IntMap (SelectionSection a) -> Maybe (Int, Int, SelectionItem a)
ssLookupMax sss = do
(i, _) <- IM.lookupMax sss
@@ -211,25 +200,21 @@ inverseSelSecYint yint sss = do
(j,_) <- L.fold (L.find (\(_,x) -> x - _ssOffset ss > yint)) $ IM.toList ls
return (i, j)
inverseSelSecYintXPosCheck ::
inverseSelSecYintXPosCheck ::
Configuration ->
ListDisplayParams ->
Float ->
Int ->
IM.IntMap (SelectionSection a) ->
Maybe (Int, Int)
inverseSelSecYintXPosCheck cfig ldp x yint sss = do
((i, ss), othersss) <- IM.minViewWithKey sss
let l = length $ _ssShownItems ss
V2 x0 _ = screenPosAbs cfig (ldp ^. ldpPos)
guard (x - x0 < 150) -- HACK, should determine selection item width and offset below
guard (x > x0)
if l <= yint
then inverseSelSecYint (yint - l) othersss
else do
let ls = L.postscan (L.premap _siHeight L.sum) (_ssItems ss)
j <- L.fold (L.findIndex (\val -> val - _ssOffset ss > yint)) ls
return (i, j)
Maybe (Int,Int)
inverseSelSecYintXPosCheck cfig ldp x yint sss = do
(i,j) <- inverseSelSecYint yint sss
let V2 x0 _ = screenPosAbs cfig (ldp ^. ldpPos)
sindent <- sss ^? ix i . ssIndent
itindent <- sss ^? ix i . ssItems . ix j . siOffX
let x1 = x0 + _ldpScale ldp * 10 * fromIntegral (sindent + itindent)
guard $ x - x1 < 150 && x > x1
return (i,j)
inverseSelNumPos ::
Configuration ->
@@ -240,31 +225,5 @@ inverseSelNumPos ::
inverseSelNumPos cfig ldp sss (V2 x y) =
inverseSelSecYintXPosCheck cfig ldp x (posSelSecYint cfig ldp y) sss
inverseSelBoundaryUp ::
Configuration ->
ListDisplayParams ->
IM.IntMap (SelectionSection a) ->
Point2 ->
Maybe (Int, Int)
inverseSelBoundaryUp cfig ldp sss (V2 _ y) = do
sel <- inverseSelSecYint (posSelSecYint cfig ldp y) sss
let mselup = inverseSelSecYint (posSelSecYint cfig ldp y - 1) sss
if Just sel == mselup
then return $ sel & _2 +~ 1
else return sel
inverseSelBoundaryDown ::
Configuration ->
ListDisplayParams ->
IM.IntMap (SelectionSection a) ->
Point2 ->
Maybe (Int, Int)
inverseSelBoundaryDown cfig ldp sss (V2 _ y) = do
sel <- inverseSelSecYint (posSelSecYint cfig ldp y) sss
let mseldown = inverseSelSecYint (posSelSecYint cfig ldp y + 1) sss
if Just sel == mseldown
then return $ sel & _2 -~ 1
else return sel
--getIthPos :: Int -> IM.IntMap (SelectionItem a) -> Int
--getIthPos i sm = sum . fmap _siHeight . fst $ IM.split i sm