Wrap ImGui::Checkbox()

This commit is contained in:
Ollie Charles
2021-01-24 15:56:14 +00:00
parent 0fb690d832
commit 90d96ad938
3 changed files with 30 additions and 7 deletions

View File

@ -1,4 +1,5 @@
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PatternSynonyms #-}
@ -55,6 +56,7 @@ module DearImGui
, button
, smallButton
, arrowButton
, checkbox
-- * Types
, ImGuiDir
@ -65,9 +67,11 @@ module DearImGui
)
where
import Data.Bool
import Data.StateVar
import Control.Monad ( when )
import Foreign
import Foreign.C.String
import Foreign.C
import qualified Language.C.Inline as C
import qualified Language.C.Inline.Cpp as Cpp
import SDL
@ -297,6 +301,20 @@ arrowButton strId (ImGuiDir dir) = withCString strId \strIdPtr ->
(1 ==) <$> [C.exp| bool { ArrowButton($(char* strIdPtr), $(int dir)) } |]
-- | Wraps @ImGui::Checkbox()@.
checkbox :: (HasSetter ref Bool, HasGetter ref Bool) => String -> ref -> IO Bool
checkbox label ref = do
currentValue <- get ref
with (bool 0 1 currentValue :: CBool) \boolPtr -> do
changed <- withCString label \labelPtr ->
(1 ==) <$> [C.exp| bool { Checkbox($(char* labelPtr), $(bool* boolPtr)) } |]
newValue <- peek boolPtr
ref $=! (newValue == 1)
return changed
-- | A cardinal direction.
newtype ImGuiDir = ImGuiDir CInt