mirror of
				https://github.com/Drezil/dear-imgui.hs.git
				synced 2025-11-04 07:01:06 +01:00 
			
		
		
		
	Wrap ImGui::BeginCombo(), EndCombo(), Selectable()
This commit is contained in:
		
							
								
								
									
										10
									
								
								Main.hs
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								Main.hs
									
									
									
									
									
								
							@@ -60,6 +60,11 @@ loop w checked = do
 | 
			
		||||
 | 
			
		||||
  progressBar 0.314 (Just "Pi")
 | 
			
		||||
 | 
			
		||||
  beginCombo "Label" "Preview" >>= whenTrue do
 | 
			
		||||
    selectable "Testing 1"
 | 
			
		||||
    selectable "Testing 2"
 | 
			
		||||
    endCombo
 | 
			
		||||
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  render
 | 
			
		||||
@@ -74,3 +79,8 @@ loop w checked = do
 | 
			
		||||
    Just Event{ eventPayload } -> case eventPayload of
 | 
			
		||||
      QuitEvent -> return ()
 | 
			
		||||
      _         -> loop w checked
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
whenTrue :: IO () -> Bool -> IO ()
 | 
			
		||||
whenTrue io True  = io
 | 
			
		||||
whenTrue io False = return ()
 | 
			
		||||
 
 | 
			
		||||
@@ -60,6 +60,13 @@ module DearImGui
 | 
			
		||||
  , progressBar
 | 
			
		||||
  , bullet
 | 
			
		||||
 | 
			
		||||
    -- ** Combo Box
 | 
			
		||||
  , beginCombo
 | 
			
		||||
  , endCombo
 | 
			
		||||
 | 
			
		||||
    -- ** Selectables
 | 
			
		||||
  , selectable
 | 
			
		||||
 | 
			
		||||
    -- * Types
 | 
			
		||||
  , ImGuiDir
 | 
			
		||||
  , pattern ImGuiDirLeft
 | 
			
		||||
@@ -331,6 +338,32 @@ bullet :: IO ()
 | 
			
		||||
bullet = [C.exp| void { Bullet() } |]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
-- | Begin creating a combo box with a given label and preview value.
 | 
			
		||||
--
 | 
			
		||||
-- Returns 'True' if the combo box is open. In this state, you should populate
 | 
			
		||||
-- the contents of the combo box - for example, by calling 'selectable'.
 | 
			
		||||
--
 | 
			
		||||
-- Wraps @ImGui::BeginCombo()@.
 | 
			
		||||
beginCombo :: String -> String -> IO Bool
 | 
			
		||||
beginCombo label previewValue =
 | 
			
		||||
  withCString label        \labelPtr ->
 | 
			
		||||
  withCString previewValue \previewValuePtr ->
 | 
			
		||||
  (1 ==) <$> [C.exp| bool { BeginCombo($(char* labelPtr), $(char* previewValuePtr)) } |]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
-- | Only call 'endCombo' if 'beginCombon' returns 'True'!
 | 
			
		||||
--
 | 
			
		||||
-- Wraps @ImGui::EndCombo()@.
 | 
			
		||||
endCombo :: IO ()
 | 
			
		||||
endCombo = [C.exp| void { EndCombo() } |]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
-- | Wraps @ImGui::Selectable()@.
 | 
			
		||||
selectable :: String -> IO Bool
 | 
			
		||||
selectable label = withCString label \labelPtr ->
 | 
			
		||||
  (1 == ) <$> [C.exp| bool { Selectable($(char* labelPtr)) } |]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
-- | A cardinal direction.
 | 
			
		||||
newtype ImGuiDir      = ImGuiDir CInt
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user