added options to selectable (#137)

This commit is contained in:
Nicole Dresselhaus 2022-03-10 16:17:42 +01:00 committed by GitHub
parent fc307a4d6e
commit f066d03017
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 6 deletions

View File

@ -190,6 +190,9 @@ module DearImGui
-- ** Selectables -- ** Selectables
, selectable , selectable
, selectableWith
, SelectableOptions(..)
, defSelectableOptions
-- ** List Boxes -- ** List Boxes
, listBox , listBox
@ -1284,10 +1287,25 @@ treePush label = liftIO do
withCString label Raw.treePush withCString label Raw.treePush
-- | Wraps @ImGui::Selectable()@. -- | Wraps @ImGui::Selectable()@ with default options.
selectable :: MonadIO m => String -> m Bool selectable :: MonadIO m => String -> m Bool
selectable label = liftIO do selectable = selectableWith defSelectableOptions
withCString label Raw.selectable
data SelectableOptions = SelectableOptions
{ selected :: Bool
, flags :: ImGuiSelectableFlags
, size :: ImVec2
} deriving Show
defSelectableOptions :: SelectableOptions
defSelectableOptions = SelectableOptions False (ImGuiSelectableFlags 0) (ImVec2 0 0)
-- | Wraps @ImGui::Selectable()@ with explicit options.
selectableWith :: MonadIO m => SelectableOptions -> String -> m Bool
selectableWith (SelectableOptions selected flags size) label = liftIO do
with size $ \sizePtr ->
withCString label $ \labelPtr ->
Raw.selectable labelPtr (bool 0 1 selected) flags sizePtr
listBox :: (MonadIO m, HasGetter ref Int, HasSetter ref Int) => String -> ref -> [String] -> m Bool listBox :: (MonadIO m, HasGetter ref Int, HasSetter ref Int) => String -> ref -> [String] -> m Bool

View File

@ -1086,10 +1086,17 @@ treePop = liftIO do
[C.exp| void { TreePop() } |] [C.exp| void { TreePop() } |]
-- -- | Wraps @ImGui::Selectable()@.
-- selectable :: (MonadIO m) => CString -> m Bool
-- selectable labelPtr = liftIO do
-- (0 /=) <$> [C.exp| bool { Selectable($(char* labelPtr)) } |]
-- | Wraps @ImGui::Selectable()@. -- | Wraps @ImGui::Selectable()@.
selectable :: (MonadIO m) => CString -> m Bool selectable :: (MonadIO m) => CString -> CBool -> ImGuiSelectableFlags -> Ptr ImVec2 -> m Bool
selectable labelPtr = liftIO do selectable labelPtr selected flags size = liftIO do
(0 /=) <$> [C.exp| bool { Selectable($(char* labelPtr)) } |] (0 /=) <$> [C.exp| bool { Selectable($(char* labelPtr), $(bool selected), $(ImGuiSelectableFlags flags), *$(ImVec2 *size)) } |]
-- | Wraps @ImGui::ListBox()@. -- | Wraps @ImGui::ListBox()@.