2 Commits

Author SHA1 Message Date
78bb5ecb8d Wrap ImGuiIO.iniFilename 2021-01-27 09:34:56 +00:00
397cea7bd9 Add Cachix (#14) 2021-01-27 09:08:33 +00:00
5 changed files with 39 additions and 24 deletions

View File

@ -13,4 +13,9 @@ jobs:
with: with:
nix_path: nixpkgs=channel:nixos-unstable nix_path: nixpkgs=channel:nixos-unstable
- run: nix-build -A hsPkgs.dear-imgui.components.exes --option trusted-public-keys "hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ= iohk.cachix.org-1:DpRUyj7h7V830dp/i6Nti+NEO2/nhblbov/8MW7Rqoo= cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=" --option substituters "https://hydra.iohk.io https://iohk.cachix.org https://cache.nixos.org/" - uses: cachix/cachix-action@v8
with:
name: hs-dear-imgui
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
- run: nix-build -A hsPkgs.dear-imgui.components.exes

View File

@ -5,6 +5,7 @@
module Main (main) where module Main (main) where
import Data.StateVar
import Data.IORef import Data.IORef
import DearImGui import DearImGui
import DearImGui.OpenGL import DearImGui.OpenGL
@ -23,6 +24,11 @@ main = do
bracket createContext destroyContext \_imguiContext -> bracket createContext destroyContext \_imguiContext ->
bracket_ (sdl2InitForOpenGL w glContext) sdl2Shutdown $ bracket_ (sdl2InitForOpenGL w glContext) sdl2Shutdown $
bracket_ openGL2Init openGL2Shutdown do bracket_ openGL2Init openGL2Shutdown do
iniFilename $= Just "imgui_state.ini"
putStr "State stored in: "
get iniFilename >>= print
checkVersion checkVersion
styleColorsLight styleColorsLight

View File

@ -120,7 +120,7 @@ library
executable test executable test
main-is: Main.hs main-is: Main.hs
default-language: Haskell2010 default-language: Haskell2010
build-depends: base, sdl2, gl, dear-imgui build-depends: base, sdl2, gl, dear-imgui, StateVar
ghc-options: -Wall ghc-options: -Wall

View File

@ -1,6 +1,7 @@
{-# LANGUAGE BlockArguments #-} {-# LANGUAGE BlockArguments #-}
{-# LANGUAGE DuplicateRecordFields #-} {-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NamedFieldPuns #-} {-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PatternSynonyms #-} {-# LANGUAGE PatternSynonyms #-}
@ -18,8 +19,6 @@ module DearImGui
Context(..) Context(..)
, createContext , createContext
, destroyContext , destroyContext
, getCurrentContext
, setCurrentContext
-- * Main -- * Main
, newFrame , newFrame
@ -29,6 +28,9 @@ module DearImGui
, getDrawData , getDrawData
, checkVersion , checkVersion
-- ** @ImGUIIO@
, iniFilename
-- * Demo, Debug, Information -- * Demo, Debug, Information
, showDemoWindow , showDemoWindow
, showMetricsWindow , showMetricsWindow
@ -128,7 +130,7 @@ import qualified Language.C.Inline.Cpp as Cpp
-- StateVar -- StateVar
import Data.StateVar import Data.StateVar
( HasGetter(get), HasSetter, ($=!) ) ( HasGetter(get), HasSetter, StateVar(..), ($=!) )
-- transformers -- transformers
import Control.Monad.IO.Class import Control.Monad.IO.Class
@ -141,31 +143,19 @@ Cpp.using "namespace ImGui"
-- | Wraps @ImGuiContext*@. -- | Wraps @ImGuiContext*@.
newtype Context = Context (Ptr ImGuiContext) newtype Context = Context (Ptr ())
-- | Wraps @ImGui::CreateContext()@. -- | Wraps @ImGui::CreateContext()@.
createContext :: MonadIO m => m Context createContext :: MonadIO m => m Context
createContext = liftIO do createContext = liftIO do
Context <$> [C.exp| ImGuiContext* { CreateContext() } |] Context <$> [C.exp| void* { CreateContext() } |]
-- | Wraps @ImGui::DestroyContext()@. -- | Wraps @ImGui::DestroyContext()@.
destroyContext :: MonadIO m => Context -> m () destroyContext :: MonadIO m => Context -> m ()
destroyContext (Context contextPtr) = liftIO do destroyContext (Context contextPtr) = liftIO do
[C.exp| void { DestroyContext($(ImGuiContext* contextPtr)); } |] [C.exp| void { DestroyContext((ImGuiContext*)$(void* contextPtr)); } |]
-- | Wraps @ImGui::GetCurrentContext()@.
getCurrentContext :: MonadIO m => m Context
getCurrentContext = liftIO do
Context <$> [C.exp| ImGuiContext* { GetCurrentContext() } |]
-- | Wraps @ImGui::SetCurrentContext()@.
setCurrentContext :: MonadIO m => Context -> m ()
setCurrentContext (Context contextPtr) = liftIO do
[C.exp| void { SetCurrentContext($(ImGuiContext* contextPtr)) } |]
-- | Start a new Dear ImGui frame, you can submit any command from this point -- | Start a new Dear ImGui frame, you can submit any command from this point
@ -210,6 +200,24 @@ checkVersion = liftIO do
[C.exp| void { IMGUI_CHECKVERSION(); } |] [C.exp| void { IMGUI_CHECKVERSION(); } |]
-- | Path to @.ini@ file. Set to 'Nothing' to disable automatic .ini
-- loading/saving, if e.g. you want to manually load/save from memory.
iniFilename :: StateVar (Maybe String)
iniFilename = StateVar getter setter
where
getter = do
cStr <- [C.exp| const char* { GetIO().IniFilename } |]
if cStr == nullPtr then return Nothing else Just <$> peekCString cStr
setter = \case
Nothing ->
[C.block| void { GetIO().IniFilename = $(char* nullPtr); } |]
Just str -> do
strPtr <- newCString str
[C.block| void { GetIO().IniFilename = $(char* strPtr); } |]
-- | Create demo window. Demonstrate most ImGui features. Call this to learn -- | Create demo window. Demonstrate most ImGui features. Call this to learn
-- about the library! Try to make it always available in your application! -- about the library! Try to make it always available in your application!
showDemoWindow :: MonadIO m => m () showDemoWindow :: MonadIO m => m ()

View File

@ -53,14 +53,10 @@ instance Storable ImVec4 where
return ImVec4{ x, y, z, w } return ImVec4{ x, y, z, w }
data ImGuiContext
imguiContext :: Context imguiContext :: Context
imguiContext = mempty imguiContext = mempty
{ ctxTypesTable = Map.fromList { ctxTypesTable = Map.fromList
[ ( TypeName "ImVec3", [t| ImVec3 |] ) [ ( TypeName "ImVec3", [t| ImVec3 |] )
, ( TypeName "ImVec4", [t| ImVec4 |] ) , ( TypeName "ImVec4", [t| ImVec4 |] )
, ( TypeName "ImGuiContext", [t| ImGuiContext |])
] ]
} }