Skip to content

Commit 5a1f5c7

Browse files
committed
Wrap ImGui::ProgressBar()
1 parent 1bd51ab commit 5a1f5c7

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

Main.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ loop w checked = do
5858
True -> readIORef checked >>= print
5959
False -> return ()
6060

61+
progressBar 0.314 (Just "Pi")
62+
6163
end
6264

6365
render

src/DearImGui.hs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ module DearImGui
5757
, smallButton
5858
, arrowButton
5959
, checkbox
60+
, progressBar
6061
, bullet
6162

6263
-- * Types
@@ -316,6 +317,14 @@ checkbox label ref = do
316317
return changed
317318

318319

320+
progressBar :: Float -> Maybe String -> IO ()
321+
progressBar progress overlay = withCStringOrNull overlay \overlayPtr ->
322+
[C.exp| void { ProgressBar($(float c'progress), ImVec2(-FLT_MIN, 0), $(char* overlayPtr)) } |]
323+
where
324+
c'progress :: CFloat
325+
c'progress = realToFrac progress
326+
327+
319328
-- | Draw a small circle + keep the cursor on the same line. Advance cursor x
320329
-- position by 'getTreeNodeToLabelSpacing', same distance that 'treeNode' uses.
321330
bullet :: IO ()
@@ -331,3 +340,8 @@ pattern ImGuiDirLeft = ImGuiDir 0
331340
pattern ImGuiDirRight = ImGuiDir 1
332341
pattern ImGuiDirUp = ImGuiDir 2
333342
pattern ImGuiDirDown = ImGuiDir 3
343+
344+
345+
withCStringOrNull :: Maybe String -> (Ptr CChar -> IO a) -> IO a
346+
withCStringOrNull Nothing k = k nullPtr
347+
withCStringOrNull (Just s) k = withCString s k

0 commit comments

Comments
 (0)