Implement ImGui::SliderFloat2,3,4 (#22)

This commit is contained in:
Ollie Charles 2021-01-28 23:02:04 +00:00 committed by GitHub
parent 63bb63a32e
commit f24a4b78ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 78 additions and 19 deletions

View File

@ -28,12 +28,12 @@ main = do
checked <- newIORef False checked <- newIORef False
color <- newIORef $ ImVec3 1 0 0 color <- newIORef $ ImVec3 1 0 0
slider <- newIORef 0.42 slider <- newIORef (0.42, 0, 0.314)
loop w checked color slider loop w checked color slider
openGL2Shutdown openGL2Shutdown
loop :: Window -> IORef Bool -> IORef ImVec3 -> IORef Float -> IO () loop :: Window -> IORef Bool -> IORef ImVec3 -> IORef (Float, Float, Float) -> IO ()
loop w checked color slider = do loop w checked color slider = do
quit <- pollEvents quit <- pollEvents
@ -74,7 +74,7 @@ loop w checked color slider = do
separator separator
sliderFloat "Slider" slider 0.0 1.0 sliderFloat3 "Slider" slider 0.0 1.0
progressBar 0.314 (Just "Pi") progressBar 0.314 (Just "Pi")

View File

@ -63,13 +63,16 @@ module DearImGui
, progressBar , progressBar
, bullet , bullet
-- ** Slider
, sliderFloat
-- ** Combo Box -- ** Combo Box
, beginCombo , beginCombo
, endCombo , endCombo
-- ** Slider
, sliderFloat
, sliderFloat2
, sliderFloat3
, sliderFloat4
-- * Color Editor/Picker -- * Color Editor/Picker
, colorPicker3 , colorPicker3
, colorButton , colorButton
@ -397,19 +400,6 @@ endCombo = liftIO do
[C.exp| void { EndCombo() } |] [C.exp| void { EndCombo() } |]
-- | Wraps @ImGui::ColorPicker3()@.
colorPicker3 :: (MonadIO m, HasSetter ref ImVec3, HasGetter ref ImVec3) => String -> ref -> m Bool
colorPicker3 desc ref = liftIO do
ImVec3{x, y, z} <- get ref
withArray (realToFrac <$> [x, y, z]) \refPtr -> do
changed <- withCString desc \descPtr ->
(0 /= ) <$> [C.exp| bool { ColorPicker3( $(char* descPtr), $(float *refPtr) ) } |]
[x', y', z'] <- peekArray 3 refPtr
ref $=! ImVec3 (realToFrac x') (realToFrac y') (realToFrac z')
return changed
-- | Wraps @ImGui::SliderFloat()@ -- | Wraps @ImGui::SliderFloat()@
sliderFloat :: (MonadIO m, HasSetter ref Float, HasGetter ref Float) => String -> ref -> Float -> Float -> m Bool sliderFloat :: (MonadIO m, HasSetter ref Float, HasGetter ref Float) => String -> ref -> Float -> Float -> m Bool
sliderFloat desc ref minValue maxValue = liftIO do sliderFloat desc ref minValue maxValue = liftIO do
@ -427,6 +417,75 @@ sliderFloat desc ref minValue maxValue = liftIO do
min' = realToFrac minValue min' = realToFrac minValue
max' = realToFrac maxValue max' = realToFrac maxValue
-- | Wraps @ImGui::SliderFloat2()@
sliderFloat2 :: (MonadIO m, HasSetter ref (Float, Float), HasGetter ref (Float, Float)) => String -> ref -> Float -> Float -> m Bool
sliderFloat2 desc ref minValue maxValue = liftIO do
(x, y) <- get ref
withArray [ realToFrac x, realToFrac y ] \floatPtr -> do
changed <- withCString desc \descPtr ->
(0 /=) <$> [C.exp| bool { SliderFloat2( $(char* descPtr), $(float *floatPtr), $(float min'), $(float max')) } |]
[x', y'] <- peekArray 2 floatPtr
ref $=! (realToFrac x', realToFrac y')
return changed
where
min', max' :: CFloat
min' = realToFrac minValue
max' = realToFrac maxValue
-- | Wraps @ImGui::SliderFloat3()@
sliderFloat3 :: (MonadIO m, HasSetter ref (Float, Float, Float), HasGetter ref (Float, Float, Float)) => String -> ref -> Float -> Float -> m Bool
sliderFloat3 desc ref minValue maxValue = liftIO do
(x, y, z) <- get ref
withArray [ realToFrac x, realToFrac y, realToFrac z ] \floatPtr -> do
changed <- withCString desc \descPtr ->
(0 /=) <$> [C.exp| bool { SliderFloat3( $(char* descPtr), $(float *floatPtr), $(float min'), $(float max')) } |]
[x', y', z'] <- peekArray 3 floatPtr
ref $=! (realToFrac x', realToFrac y', realToFrac z')
return changed
where
min', max' :: CFloat
min' = realToFrac minValue
max' = realToFrac maxValue
-- | Wraps @ImGui::SliderFloat4()@
sliderFloat4 :: (MonadIO m, HasSetter ref (Float, Float, Float, Float), HasGetter ref (Float, Float, Float, Float)) => String -> ref -> Float -> Float -> m Bool
sliderFloat4 desc ref minValue maxValue = liftIO do
(x, y, z, u) <- get ref
withArray [ realToFrac x, realToFrac y, realToFrac z, realToFrac u ] \floatPtr -> do
changed <- withCString desc \descPtr ->
(0 /=) <$> [C.exp| bool { SliderFloat4( $(char* descPtr), $(float *floatPtr), $(float min'), $(float max')) } |]
[x', y', z', u'] <- peekArray 4 floatPtr
ref $=! (realToFrac x', realToFrac y', realToFrac z', realToFrac u')
return changed
where
min', max' :: CFloat
min' = realToFrac minValue
max' = realToFrac maxValue
-- | Wraps @ImGui::ColorPicker3()@.
colorPicker3 :: (MonadIO m, HasSetter ref ImVec3, HasGetter ref ImVec3) => String -> ref -> m Bool
colorPicker3 desc ref = liftIO do
ImVec3{x, y, z} <- get ref
withArray (realToFrac <$> [x, y, z]) \refPtr -> do
changed <- withCString desc \descPtr ->
(0 /= ) <$> [C.exp| bool { ColorPicker3( $(char* descPtr), $(float *refPtr) ) } |]
[x', y', z'] <- peekArray 3 refPtr
ref $=! ImVec3 (realToFrac x') (realToFrac y') (realToFrac z')
return changed
-- | Display a color square/button, hover for details, return true when pressed. -- | Display a color square/button, hover for details, return true when pressed.
-- --
-- Wraps @ImGui::ColorButton()@. -- Wraps @ImGui::ColorButton()@.