From ecab9d37a249dc253ee0b79fefcfc641de43dc5f Mon Sep 17 00:00:00 2001 From: Oliver Charles Date: Sun, 24 Jan 2021 20:23:58 +0000 Subject: [PATCH] Basic wrapper for plotHistogram --- Main.hs | 2 ++ src/DearImGui.hs | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/Main.hs b/Main.hs index fe57abf..554acd4 100644 --- a/Main.hs +++ b/Main.hs @@ -78,6 +78,8 @@ loop w checked = do selectable "Testing 2" endCombo + plotHistogram "A histogram" [ 10, 10, 20, 30, 90 ] + beginMainMenuBar >>= whenTrue do beginMenu "Hello" >>= whenTrue do menuItem "Hello" diff --git a/src/DearImGui.hs b/src/DearImGui.hs index f1caf51..2a50e63 100644 --- a/src/DearImGui.hs +++ b/src/DearImGui.hs @@ -65,6 +65,9 @@ module DearImGui -- ** Selectables , selectable + -- * Data Plotting + , plotHistogram + -- ** Menus , beginMenuBar , endMenuBar @@ -371,6 +374,15 @@ selectable label = liftIO do (1 == ) <$> [C.exp| bool { Selectable($(char* labelPtr)) } |] +-- | Wraps @ImGui::PlotHistogram()@. +plotHistogram :: MonadIO m => String -> [CFloat] -> m () +plotHistogram label values = liftIO $ + withArrayLen values \len valuesPtr -> + withCString label \labelPtr -> do + let c'len = fromIntegral len + [C.exp| void { PlotHistogram($(char* labelPtr), $(float* valuesPtr), $(int c'len)) } |] + + -- | Append to menu-bar of current window (requires 'ImGuiWindowFlagsMenuBar' -- flag set on parent window). --