mirror of
https://github.com/Drezil/dear-imgui.hs.git
synced 2024-11-22 16:57:00 +00:00
Add combo to wrap ImGUI::Combo() (#28)
Co-authored-by: Oliver Charles <ollie@ocharles.org.uk>
This commit is contained in:
parent
895f5c1926
commit
643d2ea5b7
18
Main.hs
18
Main.hs
@ -30,13 +30,21 @@ main = do
|
||||
color <- newIORef $ ImVec3 1 0 0
|
||||
slider <- newIORef (0.42, 0, 0.314)
|
||||
r <- newIORef 4
|
||||
loop w checked color slider r
|
||||
selected <- newIORef 4
|
||||
loop w checked color slider r selected
|
||||
|
||||
openGL2Shutdown
|
||||
|
||||
|
||||
loop :: Window -> IORef Bool -> IORef ImVec3 -> IORef (Float, Float, Float) -> IORef Int -> IO ()
|
||||
loop w checked color slider r = do
|
||||
loop
|
||||
:: Window
|
||||
-> IORef Bool
|
||||
-> IORef ImVec3
|
||||
-> IORef (Float, Float, Float)
|
||||
-> IORef Int
|
||||
-> IORef Int
|
||||
-> IO ()
|
||||
loop w checked color slider r selected = do
|
||||
quit <- pollEvents
|
||||
|
||||
openGL2NewFrame
|
||||
@ -89,6 +97,8 @@ loop w checked color slider r = do
|
||||
selectable "Testing 2"
|
||||
endCombo
|
||||
|
||||
combo "Simple" selected [ "1", "2", "3" ]
|
||||
|
||||
endChild
|
||||
|
||||
plotHistogram "A histogram" [ 10, 10, 20, 30, 90 ]
|
||||
@ -124,7 +134,7 @@ loop w checked color slider r = do
|
||||
|
||||
glSwapWindow w
|
||||
|
||||
if quit then return () else loop w checked color slider r
|
||||
if quit then return () else loop w checked color slider r selected
|
||||
|
||||
where
|
||||
|
||||
|
@ -67,6 +67,7 @@ module DearImGui
|
||||
-- ** Combo Box
|
||||
, beginCombo
|
||||
, endCombo
|
||||
, combo
|
||||
|
||||
-- ** Drag Sliders
|
||||
, dragFloat
|
||||
@ -416,6 +417,27 @@ endCombo = liftIO do
|
||||
[C.exp| void { EndCombo() } |]
|
||||
|
||||
|
||||
-- Wraps @ImGui::Combo()@.
|
||||
combo :: (MonadIO m, HasGetter ref Int, HasSetter ref Int) => String -> ref -> [String] -> m Bool
|
||||
combo label selectedIndex items = liftIO $ Managed.with m return
|
||||
where
|
||||
m = do
|
||||
i <- get selectedIndex
|
||||
|
||||
cStrings <- traverse (\str -> Managed.managed (withCString str)) items
|
||||
labelPtr <- Managed.managed $ withCString label
|
||||
iPtr <- Managed.managed $ with (fromIntegral i)
|
||||
|
||||
liftIO $ withArrayLen cStrings \len itemsPtr -> do
|
||||
let len' = fromIntegral len
|
||||
[C.exp| bool { Combo($(char* labelPtr), $(int* iPtr), $(char** itemsPtr), $(int len')) }|] >>= \case
|
||||
0 -> return False
|
||||
_ -> do
|
||||
i' <- peek iPtr
|
||||
selectedIndex $=! fromIntegral i'
|
||||
return True
|
||||
|
||||
|
||||
-- | Wraps @ImGui::DragFloat()@
|
||||
dragFloat :: (MonadIO m, HasSetter ref Float, HasGetter ref Float) => String -> ref -> Float -> Float -> Float -> m Bool
|
||||
dragFloat desc ref speed minValue maxValue = liftIO do
|
||||
|
Loading…
Reference in New Issue
Block a user