Add 8-way cardinal/intercardinal datatype

This commit is contained in:
2024-10-18 12:39:46 +01:00
parent d256bc0443
commit 8b6f5529ff
12 changed files with 267 additions and 157 deletions
+21 -14
View File
@@ -6,9 +6,12 @@ module Dodge.SelectionSections (
setFirstPosSelectionSections,
selSecYint,
selSecSelSize,
inverseSelSecYint,
posSelSecYint,
inverseSelNumPos,
) where
import Control.Monad
import qualified Control.Foldl as L
import Dodge.ScreenPos
import Geometry.Data
@@ -130,8 +133,8 @@ selSecSelSize :: Int -> Int -> SelectionSections a -> Maybe Int
selSecSelSize i j sss = fmap length $ sss ^? sssSections . ix i . ssItems . ix j . siPictures
-- need to check that the vertical gap is correctly put in here
posSelSecYint :: Configuration -> ListDisplayParams -> Point2 -> Int
posSelSecYint cfig ldp (V2 _ y) = floor $ (y0 - y) / (20 / ldp ^. ldpScale + ldp ^. ldpVerticalGap)
posSelSecYint :: Configuration -> ListDisplayParams -> Float -> Int
posSelSecYint cfig ldp y = floor $ (y0 - y) / (20 / ldp ^. ldpScale + ldp ^. ldpVerticalGap)
where
V2 _ y0 = screenPosAbs cfig (ldp ^. ldpPos)
@@ -159,16 +162,20 @@ inverseSelSecYint yint sss = do
let ls = L.postscan (L.premap _siHeight L.sum) (_ssItems ss)
j <- L.fold (L.findIndex (\x -> x - _ssOffset ss > yint)) ls
return (i,j)
--
-- ss <- sss ^? sssSections . ix i
-- return . (secpos +)
-- . subtract (ss ^. ssOffset)
-- . sum
-- . fmap _siHeight
-- . fst
-- $ IM.split j (ss ^. ssItems)
-- where
-- secpos = sum . fmap (length . _ssShownItems) . fst $ IM.split i $ sss ^. sssSections
inverseSelSecYintXPosCheck :: Configuration -> ListDisplayParams
-> Float -> Int -> SelectionSections a -> Maybe (Int,Int)
inverseSelSecYintXPosCheck cfig ldp x yint sss = do
((i,ss),othersss) <- IM.minViewWithKey (_sssSections 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
if l <= yint
then inverseSelSecYint (yint - l) (sss & sssSections .~ 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)
inverseSelNumPos ::
Configuration ->
@@ -176,8 +183,8 @@ inverseSelNumPos ::
SelectionSections a ->
Point2 ->
Maybe (Int,Int)
inverseSelNumPos cfig ldp sss pos = --Just (0,posSelSecYint cfig ldp pos)
inverseSelSecYint (posSelSecYint cfig ldp pos) sss
inverseSelNumPos cfig ldp sss (V2 x y) =
inverseSelSecYintXPosCheck cfig ldp x (posSelSecYint cfig ldp y) sss
--getIthPos :: Int -> IM.IntMap (SelectionItem a) -> Int
--getIthPos i sm = sum . fmap _siHeight . fst $ IM.split i sm