From 5a1f5c78ecb213b596acdb80224444179f2f5e67 Mon Sep 17 00:00:00 2001 From: Ollie Charles Date: Sun, 24 Jan 2021 16:03:18 +0000 Subject: [PATCH] Wrap ImGui::ProgressBar() --- Main.hs | 2 ++ src/DearImGui.hs | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/Main.hs b/Main.hs index 305adb0..a610669 100644 --- a/Main.hs +++ b/Main.hs @@ -58,6 +58,8 @@ loop w checked = do True -> readIORef checked >>= print False -> return () + progressBar 0.314 (Just "Pi") + end render diff --git a/src/DearImGui.hs b/src/DearImGui.hs index bbc9e6a..4045860 100644 --- a/src/DearImGui.hs +++ b/src/DearImGui.hs @@ -57,6 +57,7 @@ module DearImGui , smallButton , arrowButton , checkbox + , progressBar , bullet -- * Types @@ -316,6 +317,14 @@ checkbox label ref = do return changed +progressBar :: Float -> Maybe String -> IO () +progressBar progress overlay = withCStringOrNull overlay \overlayPtr -> + [C.exp| void { ProgressBar($(float c'progress), ImVec2(-FLT_MIN, 0), $(char* overlayPtr)) } |] + where + c'progress :: CFloat + c'progress = realToFrac progress + + -- | Draw a small circle + keep the cursor on the same line. Advance cursor x -- position by 'getTreeNodeToLabelSpacing', same distance that 'treeNode' uses. bullet :: IO () @@ -331,3 +340,8 @@ pattern ImGuiDirLeft = ImGuiDir 0 pattern ImGuiDirRight = ImGuiDir 1 pattern ImGuiDirUp = ImGuiDir 2 pattern ImGuiDirDown = ImGuiDir 3 + + +withCStringOrNull :: Maybe String -> (Ptr CChar -> IO a) -> IO a +withCStringOrNull Nothing k = k nullPtr +withCStringOrNull (Just s) k = withCString s k