mirror of
				https://github.com/Drezil/dear-implot.hs.git
				synced 2025-11-04 15:11:06 +01:00 
			
		
		
		
	added setupAxis and changed plotLine to storable Vector
This commit is contained in:
		 Submodule dear-imgui.hs updated: 8d332a49ea...cf166acda9
									
								
							@@ -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
									
									
									
									
									
								
							
							
								
								
								
								
								
							
						
						
									
										2
									
								
								implot
									
									
									
									
									
								
							 Submodule implot updated: 7a470b2e17...e80e42e8b4
									
								
							@@ -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
 | 
			
		||||
 
 | 
			
		||||
@@ -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) ) } |]
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user