Skip to content

Commit aa681fb

Browse files
committed
Wrap ImGui::BeginCombo(), EndCombo(), Selectable()
1 parent 5a1f5c7 commit aa681fb

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

Main.hs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ loop w checked = do
6060

6161
progressBar 0.314 (Just "Pi")
6262

63+
beginCombo "Label" "Preview" >>= whenTrue do
64+
selectable "Testing 1"
65+
selectable "Testing 2"
66+
endCombo
67+
6368
end
6469

6570
render
@@ -74,3 +79,8 @@ loop w checked = do
7479
Just Event{ eventPayload } -> case eventPayload of
7580
QuitEvent -> return ()
7681
_ -> loop w checked
82+
83+
84+
whenTrue :: IO () -> Bool -> IO ()
85+
whenTrue io True = io
86+
whenTrue io False = return ()

src/DearImGui.hs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ module DearImGui
6060
, progressBar
6161
, bullet
6262

63+
-- ** Combo Box
64+
, beginCombo
65+
, endCombo
66+
67+
-- ** Selectables
68+
, selectable
69+
6370
-- * Types
6471
, ImGuiDir
6572
, pattern ImGuiDirLeft
@@ -331,6 +338,32 @@ bullet :: IO ()
331338
bullet = [C.exp| void { Bullet() } |]
332339

333340

341+
-- | Begin creating a combo box with a given label and preview value.
342+
--
343+
-- Returns 'True' if the combo box is open. In this state, you should populate
344+
-- the contents of the combo box - for example, by calling 'selectable'.
345+
--
346+
-- Wraps @ImGui::BeginCombo()@.
347+
beginCombo :: String -> String -> IO Bool
348+
beginCombo label previewValue =
349+
withCString label \labelPtr ->
350+
withCString previewValue \previewValuePtr ->
351+
(1 ==) <$> [C.exp| bool { BeginCombo($(char* labelPtr), $(char* previewValuePtr)) } |]
352+
353+
354+
-- | Only call 'endCombo' if 'beginCombon' returns 'True'!
355+
--
356+
-- Wraps @ImGui::EndCombo()@.
357+
endCombo :: IO ()
358+
endCombo = [C.exp| void { EndCombo() } |]
359+
360+
361+
-- | Wraps @ImGui::Selectable()@.
362+
selectable :: String -> IO Bool
363+
selectable label = withCString label \labelPtr ->
364+
(1 == ) <$> [C.exp| bool { Selectable($(char* labelPtr)) } |]
365+
366+
334367
-- | A cardinal direction.
335368
newtype ImGuiDir = ImGuiDir CInt
336369

0 commit comments

Comments
 (0)