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

2
implot

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

View File

@ -29,6 +29,7 @@ module DearImGui.Plot
-- * Plot Creation -- * Plot Creation
, withPlot , withPlot
, setupAxisLimits
-- * TEST -- * TEST
, plotLine , plotLine
@ -50,6 +51,8 @@ import System.IO
-- dear-imgui -- dear-imgui
import DearImGui.Enums import DearImGui.Enums
import DearImGui.Structs import DearImGui.Structs
import DearImGui.Plot.Enums
import DearImGui.Plot.Structs
import qualified DearImGui.Raw as Raw import qualified DearImGui.Raw as Raw
import qualified DearImGui.Raw.Plot as Raw.Plot import qualified DearImGui.Raw.Plot as Raw.Plot
import qualified DearImGui.Raw.Font as Raw.Font 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.Storable as VS
import qualified Data.Vector.Unboxed as VU 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 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 withCString label \labelPtr -> do
withArray (map realToFrac xs) \xsPtr -> do withForeignPtr xsPtr $ \xsPtr' -> do
withArray (map realToFrac ys) \ysPtr -> do withForeignPtr ysPtr $ \ysPtr' -> do
Raw.Plot.plotLine labelPtr xsPtr ysPtr size -- 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 :: (MonadIO m) => String -> m () -> m ()
withPlot p a = Raw.Plot.beginPlot p >>= \case withPlot p a = Raw.Plot.beginPlot p >>= \case
False -> return () False -> return ()
True -> a >> Raw.Plot.endPlot True -> a >> Raw.Plot.endPlot
-- setNextPlotLimits :: MonadIO m => (Double, Double) -> (Double, Double) -> m () setupAxisLimits :: MonadIO m => (Double, Double) -> (Double, Double) -> Maybe Int -> m ()
-- setNextPlotLimits (minX, maxX) (minY, maxY) = liftIO $ do setupAxisLimits (minX, maxX) (minY, maxY) _ = liftIO $ do
-- Raw.Plot.setNextPlotLimits (minX', maxX') (minY', maxY') Raw.Plot.setupAxisLimits ImAxis_X1 minX' maxX' Nothing
-- where Raw.Plot.setupAxisLimits ImAxis_Y1 minY' maxY' Nothing
-- minX' = realToFrac minX where
-- maxX' = realToFrac maxX minX' = realToFrac minX
-- minY' = realToFrac minY maxX' = realToFrac maxX
-- maxY' = realToFrac maxY minY' = realToFrac minY
maxY' = realToFrac maxY

View File

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