From 0fb690d8328bfdd47e2e2efa99577c63b21e8d10 Mon Sep 17 00:00:00 2001 From: Ollie Charles Date: Sun, 24 Jan 2021 15:54:39 +0000 Subject: [PATCH] Wrap ImGui::ArrowButton() --- Main.hs | 2 ++ src/DearImGui.hs | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/Main.hs b/Main.hs index a9c7467..fe81714 100644 --- a/Main.hs +++ b/Main.hs @@ -51,6 +51,8 @@ loop w = do True -> putStrLn "Oh hi Mark" False -> return () + arrowButton "Arrow" ImGuiDirUp + end render diff --git a/src/DearImGui.hs b/src/DearImGui.hs index f79b8a5..84a1e23 100644 --- a/src/DearImGui.hs +++ b/src/DearImGui.hs @@ -1,6 +1,7 @@ {-# LANGUAGE BlockArguments #-} {-# LANGUAGE NamedFieldPuns #-} {-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE PatternSynonyms #-} {-# LANGUAGE QuasiQuotes #-} {-# LANGUAGE TemplateHaskell #-} @@ -53,6 +54,14 @@ module DearImGui -- ** Main , button , smallButton + , arrowButton + + -- * Types + , ImGuiDir + , pattern ImGuiDirLeft + , pattern ImGuiDirRight + , pattern ImGuiDirUp + , pattern ImGuiDirDown ) where @@ -278,3 +287,22 @@ button label = withCString label \labelPtr -> smallButton :: String -> IO Bool smallButton label = withCString label \labelPtr -> (1 ==) <$> [C.exp| bool { SmallButton($(char* labelPtr)) } |] + + +-- | Square button with an arrow shape. +-- +-- Wraps @ImGui::ArrowButton()@. +arrowButton :: String -> ImGuiDir -> IO Bool +arrowButton strId (ImGuiDir dir) = withCString strId \strIdPtr -> + (1 ==) <$> [C.exp| bool { ArrowButton($(char* strIdPtr), $(int dir)) } |] + + +-- | A cardinal direction. +newtype ImGuiDir = ImGuiDir CInt + + +pattern ImGuiDirLeft, ImGuiDirRight, ImGuiDirUp, ImGuiDirDown :: ImGuiDir +pattern ImGuiDirLeft = ImGuiDir 0 +pattern ImGuiDirRight = ImGuiDir 1 +pattern ImGuiDirUp = ImGuiDir 2 +pattern ImGuiDirDown = ImGuiDir 3