From 4bfc7e7099c5cd356d49a93fea0c00f7de2aa920 Mon Sep 17 00:00:00 2001 From: Alexander Bondarenko <486682+dpwiz@users.noreply.github.com> Date: Sat, 11 Sep 2021 14:01:03 +0300 Subject: [PATCH] Add invisibleButton (#91) --- src/DearImGui.hs | 14 ++++++++++++++ src/DearImGui/Raw.hs | 19 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/DearImGui.hs b/src/DearImGui.hs index 9de17e7..6d40aa9 100644 --- a/src/DearImGui.hs +++ b/src/DearImGui.hs @@ -120,6 +120,7 @@ module DearImGui -- ** Main , button , smallButton + , invisibleButton , arrowButton , checkbox , progressBar @@ -416,6 +417,19 @@ smallButton label = liftIO do withCString label Raw.smallButton +-- | Flexible button behavior without the visuals. +-- +-- Frequently useful to build custom behaviors using the public api +-- (along with IsItemActive, IsItemHovered, etc). +-- +-- Wraps @ImGui::InvisibleButton()@. +invisibleButton :: MonadIO m => String -> ImVec2 -> ImGuiButtonFlags -> m Bool +invisibleButton label size flags = liftIO do + withCString label \labelPtr -> + with size \sizePtr -> + Raw.invisibleButton labelPtr sizePtr flags + + -- | Square button with an arrow shape. -- -- Wraps @ImGui::ArrowButton()@. diff --git a/src/DearImGui/Raw.hs b/src/DearImGui/Raw.hs index da06d53..91227a6 100644 --- a/src/DearImGui/Raw.hs +++ b/src/DearImGui/Raw.hs @@ -99,6 +99,7 @@ module DearImGui.Raw -- ** Main , button , smallButton + , invisibleButton , arrowButton , checkbox , progressBar @@ -478,6 +479,24 @@ smallButton labelPtr = liftIO do (0 /=) <$> [C.exp| bool { SmallButton($(char* labelPtr)) } |] +-- | Flexible button behavior without the visuals. +-- +-- Frequently useful to build custom behaviors using the public api +-- (along with IsItemActive, IsItemHovered, etc). +-- +-- Wraps @ImGui::InvisibleButton()@. +invisibleButton :: (MonadIO m) => CString -> Ptr ImVec2 -> ImGuiButtonFlags -> m Bool +invisibleButton labelPtr size flags = liftIO do + (0 /=) <$> [C.exp| + bool { + InvisibleButton( + $(char* labelPtr), + *$(ImVec2* size), + $(ImGuiButtonFlags flags) + ) + } + |] + -- | Square button with an arrow shape. -- -- Wraps @ImGui::ArrowButton()@.