Skip to content

Commit d227561

Browse files
authored
Return Bool when appropriate (#11)
I also updated the main functions to use (/=0) instead of (==1).
1 parent e4b75e3 commit d227561

File tree

3 files changed

+21
-21
lines changed

3 files changed

+21
-21
lines changed

src/DearImGui.hs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ styleColorsClassic = liftIO do
265265
begin :: MonadIO m => String -> m Bool
266266
begin name = liftIO do
267267
withCString name \namePtr ->
268-
(1 ==) <$> [C.exp| bool { ImGui::Begin($(char* namePtr)) } |]
268+
(0 /=) <$> [C.exp| bool { ImGui::Begin($(char* namePtr)) } |]
269269

270270

271271
-- | Pop window from the stack.
@@ -308,7 +308,7 @@ text t = liftIO do
308308
button :: MonadIO m => String -> m Bool
309309
button label = liftIO do
310310
withCString label \labelPtr ->
311-
(1 ==) <$> [C.exp| bool { Button($(char* labelPtr)) } |]
311+
(0 /=) <$> [C.exp| bool { Button($(char* labelPtr)) } |]
312312

313313

314314
-- | Button with @FramePadding=(0,0)@ to easily embed within text.
@@ -317,7 +317,7 @@ button label = liftIO do
317317
smallButton :: MonadIO m => String -> m Bool
318318
smallButton label = liftIO do
319319
withCString label \labelPtr ->
320-
(1 ==) <$> [C.exp| bool { SmallButton($(char* labelPtr)) } |]
320+
(0 /=) <$> [C.exp| bool { SmallButton($(char* labelPtr)) } |]
321321

322322

323323
-- | Square button with an arrow shape.
@@ -326,7 +326,7 @@ smallButton label = liftIO do
326326
arrowButton :: MonadIO m => String -> ImGuiDir -> m Bool
327327
arrowButton strId (ImGuiDir dir) = liftIO do
328328
withCString strId \strIdPtr ->
329-
(1 ==) <$> [C.exp| bool { ArrowButton($(char* strIdPtr), $(int dir)) } |]
329+
(0 /=) <$> [C.exp| bool { ArrowButton($(char* strIdPtr), $(int dir)) } |]
330330

331331

332332
-- | Wraps @ImGui::Checkbox()@.
@@ -335,7 +335,7 @@ checkbox label ref = liftIO do
335335
currentValue <- get ref
336336
with (bool 0 1 currentValue :: CBool) \boolPtr -> do
337337
changed <- withCString label \labelPtr ->
338-
(1 ==) <$> [C.exp| bool { Checkbox($(char* labelPtr), $(bool* boolPtr)) } |]
338+
(0 /=) <$> [C.exp| bool { Checkbox($(char* labelPtr), $(bool* boolPtr)) } |]
339339

340340
newValue <- peek boolPtr
341341
ref $=! (newValue == 1)
@@ -369,7 +369,7 @@ beginCombo :: MonadIO m => String -> String -> m Bool
369369
beginCombo label previewValue = liftIO $
370370
withCString label \labelPtr ->
371371
withCString previewValue \previewValuePtr ->
372-
(1 ==) <$> [C.exp| bool { BeginCombo($(char* labelPtr), $(char* previewValuePtr)) } |]
372+
(0 /=) <$> [C.exp| bool { BeginCombo($(char* labelPtr), $(char* previewValuePtr)) } |]
373373

374374

375375
-- | Only call 'endCombo' if 'beginCombon' returns 'True'!
@@ -386,7 +386,7 @@ colorPicker3 desc ref = liftIO do
386386
ImVec3{x, y, z} <- get ref
387387
withArray (realToFrac <$> [x, y, z]) \refPtr -> do
388388
changed <- withCString desc \descPtr ->
389-
(1 == ) <$> [C.exp| bool { ColorPicker3( $(char* descPtr), $(float *refPtr) ) } |]
389+
(0 /= ) <$> [C.exp| bool { ColorPicker3( $(char* descPtr), $(float *refPtr) ) } |]
390390

391391
[x', y', z'] <- peekArray 3 refPtr
392392
ref $=! ImVec3 (realToFrac x') (realToFrac y') (realToFrac z')
@@ -399,7 +399,7 @@ sliderFloat desc ref minValue maxValue = liftIO do
399399
currentValue <- get ref
400400
with (realToFrac currentValue) \floatPtr -> do
401401
changed <- withCString desc \descPtr ->
402-
(1 ==) <$> [C.exp| bool { SliderFloat( $(char* descPtr), $(float *floatPtr), $(float min'), $(float max')) } |]
402+
(0 /=) <$> [C.exp| bool { SliderFloat( $(char* descPtr), $(float *floatPtr), $(float min'), $(float max')) } |]
403403

404404
newValue <- peek floatPtr
405405
ref $=! realToFrac newValue
@@ -418,7 +418,7 @@ colorButton desc ref = liftIO do
418418
currentValue <- get ref
419419
with currentValue \refPtr -> do
420420
changed <- withCString desc \descPtr ->
421-
(1 == ) <$> [C.exp| bool { ColorButton( $(char* descPtr), *$(ImVec4 *refPtr) ) } |]
421+
(0 /=) <$> [C.exp| bool { ColorButton( $(char* descPtr), *$(ImVec4 *refPtr) ) } |]
422422

423423
newValue <- peek refPtr
424424
ref $=! newValue
@@ -430,7 +430,7 @@ colorButton desc ref = liftIO do
430430
selectable :: MonadIO m => String -> m Bool
431431
selectable label = liftIO do
432432
withCString label \labelPtr ->
433-
(1 == ) <$> [C.exp| bool { Selectable($(char* labelPtr)) } |]
433+
(0 /=) <$> [C.exp| bool { Selectable($(char* labelPtr)) } |]
434434

435435

436436
-- | Wraps @ImGui::PlotHistogram()@.
@@ -448,7 +448,7 @@ plotHistogram label values = liftIO $
448448
-- Wraps @ImGui::BeginMenuBar()@.
449449
beginMenuBar :: MonadIO m => m Bool
450450
beginMenuBar = liftIO do
451-
(1 == ) <$> [C.exp| bool { BeginMenuBar() } |]
451+
(0 /=) <$> [C.exp| bool { BeginMenuBar() } |]
452452

453453

454454
-- | Only call 'endMenuBar' if 'beginMenuBar' returns true!
@@ -464,7 +464,7 @@ endMenuBar = liftIO do
464464
-- Wraps @ImGui::BeginMainMenuBar()@.
465465
beginMainMenuBar :: MonadIO m => m Bool
466466
beginMainMenuBar = liftIO do
467-
(1 == ) <$> [C.exp| bool { BeginMainMenuBar() } |]
467+
(0 /=) <$> [C.exp| bool { BeginMainMenuBar() } |]
468468

469469

470470
-- | Only call 'endMainMenuBar' if 'beginMainMenuBar' returns true!
@@ -481,7 +481,7 @@ endMainMenuBar = liftIO do
481481
beginMenu :: MonadIO m => String -> m Bool
482482
beginMenu label = liftIO do
483483
withCString label \labelPtr ->
484-
(1 == ) <$> [C.exp| bool { BeginMenu($(char* labelPtr)) } |]
484+
(0 /=) <$> [C.exp| bool { BeginMenu($(char* labelPtr)) } |]
485485

486486

487487
-- | Only call 'endMenu' if 'beginMenu' returns true!
@@ -499,7 +499,7 @@ endMenu = liftIO do
499499
menuItem :: MonadIO m => String -> m Bool
500500
menuItem label = liftIO do
501501
withCString label \labelPtr ->
502-
(1 ==) <$> [C.exp| bool { MenuItem($(char* labelPtr)) } |]
502+
(0 /=) <$> [C.exp| bool { MenuItem($(char* labelPtr)) } |]
503503

504504

505505
-- | Begin/append a tooltip window to create full-featured tooltip (with any
@@ -523,7 +523,7 @@ endTooltip = liftIO do
523523
beginPopup :: MonadIO m => String -> m Bool
524524
beginPopup popupId = liftIO do
525525
withCString popupId \popupIdPtr ->
526-
(1 ==) <$> [C.exp| bool { BeginPopup($(char* popupIdPtr)) } |]
526+
(0 /=) <$> [C.exp| bool { BeginPopup($(char* popupIdPtr)) } |]
527527

528528

529529
-- | Returns 'True' if the modal is open, and you can start outputting to it.
@@ -532,7 +532,7 @@ beginPopup popupId = liftIO do
532532
beginPopupModal :: MonadIO m => String -> m Bool
533533
beginPopupModal popupId = liftIO do
534534
withCString popupId \popupIdPtr ->
535-
(1 ==) <$> [C.exp| bool { BeginPopupModal($(char* popupIdPtr)) } |]
535+
(0 /=) <$> [C.exp| bool { BeginPopupModal($(char* popupIdPtr)) } |]
536536

537537

538538
-- | Only call 'endPopup' if 'beginPopup' or 'beginPopupModal' returns 'True'!
@@ -565,7 +565,7 @@ closeCurrentPopup = liftIO do
565565
-- Wraps @ImGui::IsItemHovered()@
566566
isItemHovered :: MonadIO m => m Bool
567567
isItemHovered = liftIO do
568-
(1 ==) <$> [C.exp| bool { IsItemHovered() } |]
568+
(0 /=) <$> [C.exp| bool { IsItemHovered() } |]
569569

570570

571571
-- | A cardinal direction.

src/DearImGui/OpenGL.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ Cpp.using "namespace ImGui"
4242

4343

4444
-- | Wraps @ImGui_ImplOpenGL2_Init@.
45-
openGL2Init :: MonadIO m => m ()
45+
openGL2Init :: MonadIO m => m Bool
4646
openGL2Init = liftIO do
47-
[C.exp| void { ImGui_ImplOpenGL2_Init(); } |]
47+
( 0 /= ) <$> [C.exp| bool { ImGui_ImplOpenGL2_Init() } |]
4848

4949

5050
-- | Wraps @ImGui_ImplOpenGL2_Shutdown@.

src/DearImGui/SDL/OpenGL.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ Cpp.using "namespace ImGui"
4949

5050

5151
-- | Wraps @ImGui_ImplSDL2_InitForOpenGL@.
52-
sdl2InitForOpenGL :: MonadIO m => Window -> GLContext -> m ()
52+
sdl2InitForOpenGL :: MonadIO m => Window -> GLContext -> m Bool
5353
sdl2InitForOpenGL (Window windowPtr) glContext = liftIO do
54-
[C.exp| void { ImGui_ImplSDL2_InitForOpenGL((SDL_Window*)$(void* windowPtr), $(void* glContextPtr)); } |]
54+
( 0 /= ) <$> [C.exp| bool { ImGui_ImplSDL2_InitForOpenGL((SDL_Window*)$(void* windowPtr), $(void* glContextPtr)) } |]
5555
where
5656
glContextPtr :: Ptr ()
5757
glContextPtr = unsafeCoerce glContext

0 commit comments

Comments
 (0)