mirror of
https://github.com/Drezil/dear-imgui.hs.git
synced 2025-07-06 04:58:48 +02:00
Add tab bar functions (#30)
This commit is contained in:
25
Main.hs
25
Main.hs
@ -5,6 +5,7 @@
|
||||
|
||||
module Main (main) where
|
||||
|
||||
import Control.Monad
|
||||
import Data.IORef
|
||||
import DearImGui
|
||||
import DearImGui.OpenGL
|
||||
@ -33,7 +34,9 @@ main = do
|
||||
pos <- newIORef $ ImVec2 64 64
|
||||
size' <- newIORef $ ImVec2 512 512
|
||||
selected <- newIORef 4
|
||||
loop w checked color slider r pos size' selected
|
||||
tab1 <- newIORef True
|
||||
tab2 <- newIORef True
|
||||
loop w checked color slider r pos size' selected tab1 tab2
|
||||
|
||||
openGL2Shutdown
|
||||
|
||||
@ -47,8 +50,10 @@ loop
|
||||
-> IORef ImVec2
|
||||
-> IORef ImVec2
|
||||
-> IORef Int
|
||||
-> IORef Bool
|
||||
-> IORef Bool
|
||||
-> IO ()
|
||||
loop w checked color slider r pos size' selected = do
|
||||
loop w checked color slider r pos size' selected tab1Ref tab2Ref = do
|
||||
quit <- pollEvents
|
||||
|
||||
openGL2NewFrame
|
||||
@ -70,8 +75,22 @@ loop w checked color slider r pos size' selected = do
|
||||
setNextWindowBgAlpha 0.42
|
||||
|
||||
begin "My Window"
|
||||
|
||||
text "Hello!"
|
||||
|
||||
beginTabBar "My tab bar" ImGuiTabBarFlags_Reorderable >>= whenTrue do
|
||||
beginTabItem "Tab 1" tab1Ref ImGuiTabBarFlags_None >>= whenTrue do
|
||||
text "Tab 1 is currently selected."
|
||||
endTabItem
|
||||
beginTabItem "Tab 2" tab2Ref ImGuiTabBarFlags_None >>= whenTrue do
|
||||
text "Tab 2 is selected now."
|
||||
endTabItem
|
||||
reOpen <- tabItemButton "ReopenTabs" ImGuiTabItemFlags_Trailing
|
||||
when reOpen do
|
||||
writeIORef tab1Ref True
|
||||
writeIORef tab2Ref True
|
||||
endTabBar
|
||||
|
||||
listBox "Items" r [ "A", "B", "C" ]
|
||||
|
||||
button "Click me" >>= \case
|
||||
@ -147,7 +166,7 @@ loop w checked color slider r pos size' selected = do
|
||||
|
||||
glSwapWindow w
|
||||
|
||||
if quit then return () else loop w checked color slider r pos size' selected
|
||||
if quit then return () else loop w checked color slider r pos size' selected tab1Ref tab2Ref
|
||||
|
||||
where
|
||||
|
||||
|
Reference in New Issue
Block a user