mirror of
https://github.com/Drezil/dear-imgui.hs.git
synced 2024-11-22 16:57:00 +00:00
Wrap ImGui::SliderFloat() (#9)
Co-authored-by: Ollie Charles <ollie@ocharles.org.uk>
This commit is contained in:
parent
3185bf5e90
commit
2fbe257c24
11
Main.hs
11
Main.hs
@ -28,12 +28,13 @@ main = do
|
|||||||
|
|
||||||
checked <- newIORef False
|
checked <- newIORef False
|
||||||
color <- newIORef $ ImVec3 1 0 0
|
color <- newIORef $ ImVec3 1 0 0
|
||||||
loop w checked color
|
slider <- newIORef 0.42
|
||||||
|
loop w checked color slider
|
||||||
|
|
||||||
openGL2Shutdown
|
openGL2Shutdown
|
||||||
|
|
||||||
loop :: Window -> IORef Bool -> IORef ImVec3 -> IO ()
|
loop :: Window -> IORef Bool -> IORef ImVec3 -> IORef Float -> IO ()
|
||||||
loop w checked color = do
|
loop w checked color slider = do
|
||||||
quit <- pollEvents
|
quit <- pollEvents
|
||||||
|
|
||||||
openGL2NewFrame
|
openGL2NewFrame
|
||||||
@ -73,6 +74,8 @@ loop w checked color = do
|
|||||||
|
|
||||||
separator
|
separator
|
||||||
|
|
||||||
|
sliderFloat "Slider" slider 0.0 1.0
|
||||||
|
|
||||||
progressBar 0.314 (Just "Pi")
|
progressBar 0.314 (Just "Pi")
|
||||||
|
|
||||||
beginCombo "Label" "Preview" >>= whenTrue do
|
beginCombo "Label" "Preview" >>= whenTrue do
|
||||||
@ -104,7 +107,7 @@ loop w checked color = do
|
|||||||
|
|
||||||
glSwapWindow w
|
glSwapWindow w
|
||||||
|
|
||||||
if quit then return () else loop w checked color
|
if quit then return () else loop w checked color slider
|
||||||
|
|
||||||
where
|
where
|
||||||
|
|
||||||
|
@ -59,6 +59,9 @@ module DearImGui
|
|||||||
, progressBar
|
, progressBar
|
||||||
, bullet
|
, bullet
|
||||||
|
|
||||||
|
-- ** Slider
|
||||||
|
, sliderFloat
|
||||||
|
|
||||||
-- ** Combo Box
|
-- ** Combo Box
|
||||||
, beginCombo
|
, beginCombo
|
||||||
, endCombo
|
, endCombo
|
||||||
@ -390,6 +393,22 @@ colorPicker3 desc ref = liftIO do
|
|||||||
|
|
||||||
return changed
|
return changed
|
||||||
|
|
||||||
|
-- | Wraps @ImGui::SliderFloat()@
|
||||||
|
sliderFloat :: (MonadIO m, HasSetter ref Float, HasGetter ref Float) => String -> ref -> Float -> Float -> m Bool
|
||||||
|
sliderFloat desc ref minValue maxValue = liftIO do
|
||||||
|
currentValue <- get ref
|
||||||
|
with (realToFrac currentValue) \floatPtr -> do
|
||||||
|
changed <- withCString desc \descPtr ->
|
||||||
|
(1 ==) <$> [C.exp| bool { SliderFloat( $(char* descPtr), $(float *floatPtr), $(float min'), $(float max')) } |]
|
||||||
|
|
||||||
|
newValue <- peek floatPtr
|
||||||
|
ref $=! realToFrac newValue
|
||||||
|
|
||||||
|
return changed
|
||||||
|
where
|
||||||
|
min', max' :: CFloat
|
||||||
|
min' = realToFrac minValue
|
||||||
|
max' = realToFrac maxValue
|
||||||
|
|
||||||
-- | Display a color square/button, hover for details, return true when pressed.
|
-- | Display a color square/button, hover for details, return true when pressed.
|
||||||
--
|
--
|
||||||
|
Loading…
Reference in New Issue
Block a user