diff --git a/src/DearImGui.hs b/src/DearImGui.hs index 0f486ad..e4e15cc 100644 --- a/src/DearImGui.hs +++ b/src/DearImGui.hs @@ -190,6 +190,9 @@ module DearImGui -- ** Selectables , selectable + , selectableWith + , SelectableOptions(..) + , defSelectableOptions -- ** List Boxes , listBox @@ -1284,10 +1287,25 @@ treePush label = liftIO do withCString label Raw.treePush --- | Wraps @ImGui::Selectable()@. +-- | Wraps @ImGui::Selectable()@ with default options. selectable :: MonadIO m => String -> m Bool -selectable label = liftIO do - withCString label Raw.selectable +selectable = selectableWith defSelectableOptions + +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 diff --git a/src/DearImGui/Raw.hs b/src/DearImGui/Raw.hs index 11e1621..3743eb9 100644 --- a/src/DearImGui/Raw.hs +++ b/src/DearImGui/Raw.hs @@ -1086,10 +1086,17 @@ treePop = liftIO do [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()@. -selectable :: (MonadIO m) => CString -> m Bool -selectable labelPtr = liftIO do - (0 /=) <$> [C.exp| bool { Selectable($(char* labelPtr)) } |] +selectable :: (MonadIO m) => CString -> CBool -> ImGuiSelectableFlags -> Ptr ImVec2 -> m Bool +selectable labelPtr selected flags size = liftIO do + (0 /=) <$> [C.exp| bool { Selectable($(char* labelPtr), $(bool selected), $(ImGuiSelectableFlags flags), *$(ImVec2 *size)) } |] + -- | Wraps @ImGui::ListBox()@.