mirror of
https://github.com/Drezil/dear-imgui.hs.git
synced 2025-07-12 07:49:56 +02:00
Wrap @ImGui::ColorPicker3()@
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
{-# LANGUAGE BlockArguments #-}
|
||||
{-# LANGUAGE DuplicateRecordFields #-}
|
||||
{-# LANGUAGE FlexibleContexts #-}
|
||||
{-# LANGUAGE NamedFieldPuns #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
@ -63,6 +64,7 @@ module DearImGui
|
||||
, endCombo
|
||||
|
||||
-- * Color Editor/Picker
|
||||
, colorPicker3
|
||||
, colorButton
|
||||
|
||||
-- ** Selectables
|
||||
@ -100,6 +102,7 @@ module DearImGui
|
||||
, pattern ImGuiDirRight
|
||||
, pattern ImGuiDirUp
|
||||
, pattern ImGuiDirDown
|
||||
, ImVec3(..)
|
||||
, ImVec4(..)
|
||||
)
|
||||
where
|
||||
@ -374,6 +377,20 @@ endCombo = liftIO do
|
||||
[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 ->
|
||||
(1 == ) <$> [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.
|
||||
--
|
||||
-- | Wraps @ImGui::ColorButton()@.
|
||||
|
@ -1,3 +1,4 @@
|
||||
{-# language DuplicateRecordFields #-}
|
||||
{-# language NamedFieldPuns #-}
|
||||
{-# language OverloadedStrings #-}
|
||||
{-# language TemplateHaskell #-}
|
||||
@ -10,6 +11,26 @@ import qualified Data.Map.Strict as Map
|
||||
import Foreign
|
||||
|
||||
|
||||
data ImVec3 = ImVec3 { x, y, z :: {-# unpack #-} !Float }
|
||||
|
||||
|
||||
instance Storable ImVec3 where
|
||||
sizeOf ~ImVec3{x, y, z} = sizeOf x + sizeOf y + sizeOf z
|
||||
|
||||
alignment _ = 0
|
||||
|
||||
poke ptr ImVec3{ x, y, z } = do
|
||||
poke (castPtr ptr `plusPtr` (sizeOf x * 0)) x
|
||||
poke (castPtr ptr `plusPtr` (sizeOf x * 1)) y
|
||||
poke (castPtr ptr `plusPtr` (sizeOf x * 2)) z
|
||||
|
||||
peek ptr = do
|
||||
x <- peek (castPtr ptr )
|
||||
y <- peek (castPtr ptr `plusPtr` (sizeOf x * 1))
|
||||
z <- peek (castPtr ptr `plusPtr` (sizeOf x * 2))
|
||||
return ImVec3{ x, y, z }
|
||||
|
||||
|
||||
data ImVec4 = ImVec4 { x, y, z, w :: {-# unpack #-} !Float }
|
||||
|
||||
|
||||
@ -35,6 +56,7 @@ instance Storable ImVec4 where
|
||||
imguiContext :: Context
|
||||
imguiContext = mempty
|
||||
{ ctxTypesTable = Map.fromList
|
||||
[ ( TypeName "ImVec4", [t| ImVec4 |] )
|
||||
[ ( TypeName "ImVec3", [t| ImVec3 |] )
|
||||
, ( TypeName "ImVec4", [t| ImVec4 |] )
|
||||
]
|
||||
}
|
||||
|
Reference in New Issue
Block a user