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
|
2021-01-24 18:25:40 +00:00
|
|
|
import DearImGui.OpenGL
|
|
|
|
import DearImGui.SDL
|
|
|
|
import DearImGui.SDL.OpenGL
|
2021-01-24 15:27:03 +00:00
|
|
|
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
|
|
|
|
|
2021-01-25 09:11:46 +00:00
|
|
|
checked <- newIORef False
|
|
|
|
color <- newIORef $ ImVec3 1 0 0
|
2021-01-28 23:02:04 +00:00
|
|
|
slider <- newIORef (0.42, 0, 0.314)
|
2021-01-28 23:38:59 +00:00
|
|
|
r <- newIORef 4
|
2021-02-05 21:20:32 +00:00
|
|
|
selected <- newIORef 4
|
|
|
|
loop w checked color slider r selected
|
2021-01-24 15:27:03 +00:00
|
|
|
|
|
|
|
openGL2Shutdown
|
|
|
|
|
2021-01-28 23:38:59 +00:00
|
|
|
|
2021-02-05 21:20:32 +00:00
|
|
|
loop
|
|
|
|
:: Window
|
|
|
|
-> IORef Bool
|
|
|
|
-> IORef ImVec3
|
|
|
|
-> IORef (Float, Float, Float)
|
|
|
|
-> IORef Int
|
|
|
|
-> IORef Int
|
|
|
|
-> IO ()
|
|
|
|
loop w checked color slider r selected = do
|
2021-01-24 16:49:38 +00:00
|
|
|
quit <- pollEvents
|
2021-01-24 15:27:03 +00:00
|
|
|
|
|
|
|
openGL2NewFrame
|
|
|
|
sdl2NewFrame w
|
|
|
|
newFrame
|
|
|
|
|
|
|
|
-- showDemoWindow
|
|
|
|
-- showMetricsWindow
|
|
|
|
-- showAboutWindow
|
|
|
|
-- showUserGuide
|
|
|
|
|
|
|
|
begin "My Window"
|
|
|
|
text "Hello!"
|
|
|
|
|
2021-01-28 23:38:59 +00:00
|
|
|
listBox "Items" r [ "A", "B", "C" ]
|
|
|
|
|
2021-01-24 15:27:03 +00:00
|
|
|
button "Click me" >>= \case
|
2021-01-24 17:35:00 +00:00
|
|
|
True -> openPopup "Button Popup"
|
2021-01-24 15:27:03 +00:00
|
|
|
False -> return ()
|
|
|
|
|
2021-01-24 17:39:44 +00:00
|
|
|
isItemHovered >>= whenTrue do
|
|
|
|
beginTooltip
|
|
|
|
text "Tooltip?"
|
|
|
|
endTooltip
|
|
|
|
|
|
|
|
beginPopup "Button Popup" >>= whenTrue do
|
2021-01-24 17:35:00 +00:00
|
|
|
button "Close" >>= whenTrue closeCurrentPopup
|
|
|
|
endPopup
|
|
|
|
|
2021-01-24 16:58:52 +00:00
|
|
|
sameLine >> smallButton "Click me" >>= \case
|
2021-01-24 15:27:03 +00:00
|
|
|
True -> putStrLn "Oh hi Mark"
|
|
|
|
False -> return ()
|
|
|
|
|
2021-02-05 20:57:17 +00:00
|
|
|
sameLine >> arrowButton "Arrow" ImGuiDir_Up
|
2021-01-24 15:54:39 +00:00
|
|
|
|
2021-01-24 16:58:52 +00:00
|
|
|
sameLine >> checkbox "Check!" checked >>= \case
|
2021-01-24 15:56:14 +00:00
|
|
|
True -> readIORef checked >>= print
|
|
|
|
False -> return ()
|
|
|
|
|
2021-01-24 17:00:25 +00:00
|
|
|
separator
|
|
|
|
|
2021-01-28 23:10:58 +00:00
|
|
|
dragFloat3 "Slider" slider 0.1 0.0 1.0
|
2021-01-25 19:04:43 +00:00
|
|
|
|
2021-01-24 16:03:18 +00:00
|
|
|
progressBar 0.314 (Just "Pi")
|
|
|
|
|
2021-01-28 22:38:25 +00:00
|
|
|
beginChild "Child"
|
|
|
|
|
2021-01-24 16:14:51 +00:00
|
|
|
beginCombo "Label" "Preview" >>= whenTrue do
|
|
|
|
selectable "Testing 1"
|
|
|
|
selectable "Testing 2"
|
|
|
|
endCombo
|
|
|
|
|
2021-02-05 21:20:32 +00:00
|
|
|
combo "Simple" selected [ "1", "2", "3" ]
|
|
|
|
|
2021-01-28 22:38:25 +00:00
|
|
|
endChild
|
|
|
|
|
2021-01-24 20:23:58 +00:00
|
|
|
plotHistogram "A histogram" [ 10, 10, 20, 30, 90 ]
|
|
|
|
|
2021-01-25 09:11:46 +00:00
|
|
|
colorPicker3 "Test" color
|
2021-01-24 20:46:01 +00:00
|
|
|
|
2021-01-28 23:28:45 +00:00
|
|
|
treeNode "Tree Node 1" >>= whenTrue do
|
|
|
|
treeNode "Tree Node 2" >>= whenTrue do
|
|
|
|
treePop
|
|
|
|
|
|
|
|
treeNode "Tree Node 3" >>= whenTrue do
|
|
|
|
treePop
|
|
|
|
|
|
|
|
treePop
|
|
|
|
|
2021-01-24 16:49:28 +00:00
|
|
|
beginMainMenuBar >>= whenTrue do
|
|
|
|
beginMenu "Hello" >>= whenTrue do
|
|
|
|
menuItem "Hello"
|
|
|
|
endMenu
|
|
|
|
|
|
|
|
beginMenu "World" >>= whenTrue do
|
|
|
|
menuItem "World"
|
|
|
|
endMenu
|
|
|
|
|
|
|
|
endMainMenuBar
|
|
|
|
|
2021-01-24 15:27:03 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
render
|
|
|
|
|
|
|
|
glClear GL_COLOR_BUFFER_BIT
|
|
|
|
openGL2RenderDrawData =<< getDrawData
|
|
|
|
|
|
|
|
glSwapWindow w
|
|
|
|
|
2021-02-05 21:20:32 +00:00
|
|
|
if quit then return () else loop w checked color slider r selected
|
2021-01-24 16:49:38 +00:00
|
|
|
|
|
|
|
where
|
|
|
|
|
|
|
|
pollEvents = do
|
|
|
|
ev <- pollEventWithImGui
|
|
|
|
|
|
|
|
case ev of
|
|
|
|
Nothing -> return False
|
|
|
|
Just Event{ eventPayload } -> do
|
|
|
|
let isQuit = case eventPayload of
|
|
|
|
QuitEvent -> True
|
|
|
|
_ -> False
|
|
|
|
|
|
|
|
(isQuit ||) <$> pollEvents
|
2021-01-24 16:14:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
whenTrue :: IO () -> Bool -> IO ()
|
|
|
|
whenTrue io True = io
|
|
|
|
whenTrue io False = return ()
|