dear-imgui.hs/Main.hs

75 lines
1.6 KiB
Haskell
Raw Normal View History

2021-01-24 15:27:03 +00:00
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
module Main (main) where
2021-01-24 15:56:14 +00:00
import Data.IORef
2021-01-24 15:27:03 +00:00
import DearImGui
import Control.Exception
import Graphics.GL
import SDL
main :: IO ()
main = do
initializeAll
bracket (createWindow "Hello, Dear ImGui!" defaultWindow { windowGraphicsContext = OpenGLContext defaultOpenGL }) destroyWindow \w ->
bracket (glCreateContext w) glDeleteContext \glContext ->
bracket createContext destroyContext \_imguiContext ->
bracket_ (sdl2InitForOpenGL w glContext) sdl2Shutdown $
bracket_ openGL2Init openGL2Shutdown do
checkVersion
styleColorsLight
openGL2Init
2021-01-24 15:56:14 +00:00
newIORef False >>= loop w
2021-01-24 15:27:03 +00:00
openGL2Shutdown
2021-01-24 15:56:14 +00:00
loop :: Window -> IORef Bool -> IO ()
loop w checked = do
2021-01-24 15:27:03 +00:00
ev <- pollEventWithImGui
openGL2NewFrame
sdl2NewFrame w
newFrame
-- showDemoWindow
-- showMetricsWindow
-- showAboutWindow
-- showUserGuide
begin "My Window"
text "Hello!"
button "Click me" >>= \case
True -> putStrLn "Oh hi Mark"
False -> return ()
smallButton "Click me" >>= \case
True -> putStrLn "Oh hi Mark"
False -> return ()
2021-01-24 15:54:39 +00:00
arrowButton "Arrow" ImGuiDirUp
2021-01-24 15:56:14 +00:00
checkbox "Check!" checked >>= \case
True -> readIORef checked >>= print
False -> return ()
2021-01-24 15:27:03 +00:00
end
render
glClear GL_COLOR_BUFFER_BIT
openGL2RenderDrawData =<< getDrawData
glSwapWindow w
case ev of
2021-01-24 15:56:14 +00:00
Nothing -> loop w checked
2021-01-24 15:27:03 +00:00
Just Event{ eventPayload } -> case eventPayload of
QuitEvent -> return ()
2021-01-24 15:56:14 +00:00
_ -> loop w checked