Skip to content

Commit ecab9d3

Browse files
committed
Basic wrapper for plotHistogram
1 parent ff989ba commit ecab9d3

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

Main.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ loop w checked = do
7878
selectable "Testing 2"
7979
endCombo
8080

81+
plotHistogram "A histogram" [ 10, 10, 20, 30, 90 ]
82+
8183
beginMainMenuBar >>= whenTrue do
8284
beginMenu "Hello" >>= whenTrue do
8385
menuItem "Hello"

src/DearImGui.hs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ module DearImGui
6565
-- ** Selectables
6666
, selectable
6767

68+
-- * Data Plotting
69+
, plotHistogram
70+
6871
-- ** Menus
6972
, beginMenuBar
7073
, endMenuBar
@@ -371,6 +374,15 @@ selectable label = liftIO do
371374
(1 == ) <$> [C.exp| bool { Selectable($(char* labelPtr)) } |]
372375

373376

377+
-- | Wraps @ImGui::PlotHistogram()@.
378+
plotHistogram :: MonadIO m => String -> [CFloat] -> m ()
379+
plotHistogram label values = liftIO $
380+
withArrayLen values \len valuesPtr ->
381+
withCString label \labelPtr -> do
382+
let c'len = fromIntegral len
383+
[C.exp| void { PlotHistogram($(char* labelPtr), $(float* valuesPtr), $(int c'len)) } |]
384+
385+
374386
-- | Append to menu-bar of current window (requires 'ImGuiWindowFlagsMenuBar'
375387
-- flag set on parent window).
376388
--

0 commit comments

Comments
 (0)