Skip to content

Commit f066d03

Browse files
authored
added options to selectable (#137)
1 parent fc307a4 commit f066d03

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

src/DearImGui.hs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,9 @@ module DearImGui
190190

191191
-- ** Selectables
192192
, selectable
193+
, selectableWith
194+
, SelectableOptions(..)
195+
, defSelectableOptions
193196

194197
-- ** List Boxes
195198
, listBox
@@ -1284,10 +1287,25 @@ treePush label = liftIO do
12841287
withCString label Raw.treePush
12851288

12861289

1287-
-- | Wraps @ImGui::Selectable()@.
1290+
-- | Wraps @ImGui::Selectable()@ with default options.
12881291
selectable :: MonadIO m => String -> m Bool
1289-
selectable label = liftIO do
1290-
withCString label Raw.selectable
1292+
selectable = selectableWith defSelectableOptions
1293+
1294+
data SelectableOptions = SelectableOptions
1295+
{ selected :: Bool
1296+
, flags :: ImGuiSelectableFlags
1297+
, size :: ImVec2
1298+
} deriving Show
1299+
1300+
defSelectableOptions :: SelectableOptions
1301+
defSelectableOptions = SelectableOptions False (ImGuiSelectableFlags 0) (ImVec2 0 0)
1302+
1303+
-- | Wraps @ImGui::Selectable()@ with explicit options.
1304+
selectableWith :: MonadIO m => SelectableOptions -> String -> m Bool
1305+
selectableWith (SelectableOptions selected flags size) label = liftIO do
1306+
with size $ \sizePtr ->
1307+
withCString label $ \labelPtr ->
1308+
Raw.selectable labelPtr (bool 0 1 selected) flags sizePtr
12911309

12921310

12931311
listBox :: (MonadIO m, HasGetter ref Int, HasSetter ref Int) => String -> ref -> [String] -> m Bool

src/DearImGui/Raw.hs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,10 +1086,17 @@ treePop = liftIO do
10861086
[C.exp| void { TreePop() } |]
10871087

10881088

1089+
-- -- | Wraps @ImGui::Selectable()@.
1090+
-- selectable :: (MonadIO m) => CString -> m Bool
1091+
-- selectable labelPtr = liftIO do
1092+
-- (0 /=) <$> [C.exp| bool { Selectable($(char* labelPtr)) } |]
1093+
1094+
10891095
-- | Wraps @ImGui::Selectable()@.
1090-
selectable :: (MonadIO m) => CString -> m Bool
1091-
selectable labelPtr = liftIO do
1092-
(0 /=) <$> [C.exp| bool { Selectable($(char* labelPtr)) } |]
1096+
selectable :: (MonadIO m) => CString -> CBool -> ImGuiSelectableFlags -> Ptr ImVec2 -> m Bool
1097+
selectable labelPtr selected flags size = liftIO do
1098+
(0 /=) <$> [C.exp| bool { Selectable($(char* labelPtr), $(bool selected), $(ImGuiSelectableFlags flags), *$(ImVec2 *size)) } |]
1099+
10931100

10941101

10951102
-- | Wraps @ImGui::ListBox()@.

0 commit comments

Comments
 (0)