Wrap ImGui::BeginCombo(), EndCombo(), Selectable()

This commit is contained in:
Ollie Charles 2021-01-24 16:14:51 +00:00
parent 5a1f5c78ec
commit aa681fb77d
2 changed files with 43 additions and 0 deletions

10
Main.hs
View File

@ -60,6 +60,11 @@ loop w checked = do
progressBar 0.314 (Just "Pi") progressBar 0.314 (Just "Pi")
beginCombo "Label" "Preview" >>= whenTrue do
selectable "Testing 1"
selectable "Testing 2"
endCombo
end end
render render
@ -74,3 +79,8 @@ loop w checked = do
Just Event{ eventPayload } -> case eventPayload of Just Event{ eventPayload } -> case eventPayload of
QuitEvent -> return () QuitEvent -> return ()
_ -> loop w checked _ -> loop w checked
whenTrue :: IO () -> Bool -> IO ()
whenTrue io True = io
whenTrue io False = return ()

View File

@ -60,6 +60,13 @@ module DearImGui
, progressBar , progressBar
, bullet , bullet
-- ** Combo Box
, beginCombo
, endCombo
-- ** Selectables
, selectable
-- * Types -- * Types
, ImGuiDir , ImGuiDir
, pattern ImGuiDirLeft , pattern ImGuiDirLeft
@ -331,6 +338,32 @@ bullet :: IO ()
bullet = [C.exp| void { Bullet() } |] bullet = [C.exp| void { Bullet() } |]
-- | Begin creating a combo box with a given label and preview value.
--
-- Returns 'True' if the combo box is open. In this state, you should populate
-- the contents of the combo box - for example, by calling 'selectable'.
--
-- Wraps @ImGui::BeginCombo()@.
beginCombo :: String -> String -> IO Bool
beginCombo label previewValue =
withCString label \labelPtr ->
withCString previewValue \previewValuePtr ->
(1 ==) <$> [C.exp| bool { BeginCombo($(char* labelPtr), $(char* previewValuePtr)) } |]
-- | Only call 'endCombo' if 'beginCombon' returns 'True'!
--
-- Wraps @ImGui::EndCombo()@.
endCombo :: IO ()
endCombo = [C.exp| void { EndCombo() } |]
-- | Wraps @ImGui::Selectable()@.
selectable :: String -> IO Bool
selectable label = withCString label \labelPtr ->
(1 == ) <$> [C.exp| bool { Selectable($(char* labelPtr)) } |]
-- | A cardinal direction. -- | A cardinal direction.
newtype ImGuiDir = ImGuiDir CInt newtype ImGuiDir = ImGuiDir CInt