added setupAxis and changed plotLine to storable Vector

This commit is contained in:
Nicole Dresselhaus 2022-08-08 08:36:41 +02:00
parent f3d5b63b54
commit 2b3810f792
5 changed files with 30 additions and 22 deletions

@ -1 +1 @@
Subproject commit 8d332a49ea551973805678303128091d1007efd7
Subproject commit cf166acda9c207f59e57799875570b6529cf42fc

View File

@ -51,8 +51,7 @@ library
src
default-language:
Haskell2010
ghc-options:
-Wall -static -dynamic-too
ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wpartial-fields -Wredundant-constraints -Wderiving-defaults -Wmissing-deriving-strategies -static -dynamic-too
install-includes:
implot/implot.h
implot/implot_internal.h
@ -84,7 +83,7 @@ library
build-depends: base
, StateVar
, containers
, dear-imgui == 2.0.0
, dear-imgui == 2.1.0
, inline-c
, inline-c-cpp
, managed

2
implot

@ -1 +1 @@
Subproject commit 7a470b2e174584d1d62ea5ebe713fea9c18beb6c
Subproject commit e80e42e8b4136ddb84ccfe04fa28d0c745828952

View File

@ -29,6 +29,7 @@ module DearImGui.Plot
-- * Plot Creation
, withPlot
, setupAxisLimits
-- * TEST
, plotLine
@ -50,6 +51,8 @@ import System.IO
-- dear-imgui
import DearImGui.Enums
import DearImGui.Structs
import DearImGui.Plot.Enums
import DearImGui.Plot.Structs
import qualified DearImGui.Raw as Raw
import qualified DearImGui.Raw.Plot as Raw.Plot
import qualified DearImGui.Raw.Font as Raw.Font
@ -75,24 +78,28 @@ import qualified Data.Vector as V
import qualified Data.Vector.Storable as VS
import qualified Data.Vector.Unboxed as VU
plotLine :: (MonadIO m) => String -> [Float] -> [Float] -> m ()
plotLine :: (MonadIO m) => String -> VS.Vector Float -> VS.Vector Float -> m ()
plotLine label xs ys = liftIO $ do
let size = fromIntegral $ length xs
let (xsPtr, xsLen) = VS.unsafeToForeignPtr0 xs
(ysPtr, ysLen) = VS.unsafeToForeignPtr0 ys
when (xsLen /= ysLen) $ error $ "Vectors have not equal length: x " <> show xsLen <> " /= y " <> show ysLen
withCString label \labelPtr -> do
withArray (map realToFrac xs) \xsPtr -> do
withArray (map realToFrac ys) \ysPtr -> do
Raw.Plot.plotLine labelPtr xsPtr ysPtr size
withForeignPtr xsPtr $ \xsPtr' -> do
withForeignPtr ysPtr $ \ysPtr' -> do
-- CFloat = CFloat Float -> ptr-cast is no problem
Raw.Plot.plotLine labelPtr (castPtr xsPtr') (castPtr ysPtr') (fromIntegral xsLen)
withPlot :: (MonadIO m) => String -> m () -> m ()
withPlot p a = Raw.Plot.beginPlot p >>= \case
False -> return ()
True -> a >> Raw.Plot.endPlot
-- setNextPlotLimits :: MonadIO m => (Double, Double) -> (Double, Double) -> m ()
-- setNextPlotLimits (minX, maxX) (minY, maxY) = liftIO $ do
-- Raw.Plot.setNextPlotLimits (minX', maxX') (minY', maxY')
-- where
-- minX' = realToFrac minX
-- maxX' = realToFrac maxX
-- minY' = realToFrac minY
-- maxY' = realToFrac maxY
setupAxisLimits :: MonadIO m => (Double, Double) -> (Double, Double) -> Maybe Int -> m ()
setupAxisLimits (minX, maxX) (minY, maxY) _ = liftIO $ do
Raw.Plot.setupAxisLimits ImAxis_X1 minX' maxX' Nothing
Raw.Plot.setupAxisLimits ImAxis_Y1 minY' maxY' Nothing
where
minX' = realToFrac minX
maxX' = realToFrac maxX
minY' = realToFrac minY
maxY' = realToFrac maxY

View File

@ -27,7 +27,7 @@ module DearImGui.Raw.Plot
, endPlot
, plotLine
-- , setNextPlotLimits
, setupAxisLimits
) where
-- base
@ -103,6 +103,8 @@ plotLine :: MonadIO m => CString -> Ptr CFloat -> Ptr CFloat -> CInt -> m ()
plotLine label xsPtr ysPtr size = liftIO do
[C.exp| void { PlotLine( $(char* label), $(float *xsPtr), $(float *ysPtr), $(int size) ) } |]
-- setNextPlotLimits :: MonadIO m => (CDouble, CDouble) -> (CDouble, CDouble) -> m ()
-- setNextPlotLimits (minX, maxX) (minY, maxY) = liftIO do
-- [C.exp| void { SetNextPlotLimits( $(double minX), $(double maxX), $(double minY), $(double maxY) ) } |]
setupAxisLimits :: MonadIO m => ImAxis -> CDouble -> CDouble -> Maybe ImPlotCond -> m ()
setupAxisLimits (ImAxis axis) minA maxA (Just (ImPlotCond cond)) = liftIO do
[C.exp| void { SetupAxisLimits( $(int axis), $(double minA), $(double maxA), $(int cond) ) } |]
setupAxisLimits (ImAxis axis) minA maxA Nothing = liftIO do
[C.exp| void { SetupAxisLimits( $(int axis), $(double minA), $(double maxA) ) } |]