mirror of
				https://github.com/Drezil/dear-imgui.hs.git
				synced 2025-10-31 13:11:07 +01:00 
			
		
		
		
	
				
					committed by
					
						 GitHub
						GitHub
					
				
			
			
				
	
			
			
			
						parent
						
							f49e81c739
						
					
				
				
					commit
					d3a0396623
				
			| @@ -3,6 +3,7 @@ | |||||||
| ## [1.1.0] | ## [1.1.0] | ||||||
|  |  | ||||||
| - `imgui` updated to 1.84.2. | - `imgui` updated to 1.84.2. | ||||||
|  | - Added GLFW backend callbacks. | ||||||
|  |  | ||||||
| ## [1.0.2] | ## [1.0.2] | ||||||
|  |  | ||||||
|   | |||||||
| @@ -181,7 +181,8 @@ library | |||||||
|     exposed-modules: |     exposed-modules: | ||||||
|       DearImGui.GLFW |       DearImGui.GLFW | ||||||
|     build-depends: |     build-depends: | ||||||
|       GLFW-b |       GLFW-b, | ||||||
|  |       bindings-GLFW | ||||||
|     cxx-sources: |     cxx-sources: | ||||||
|       imgui/backends/imgui_impl_glfw.cpp |       imgui/backends/imgui_impl_glfw.cpp | ||||||
|  |  | ||||||
|   | |||||||
| @@ -19,9 +19,33 @@ module DearImGui.GLFW ( | |||||||
|     -- ** GLFW |     -- ** GLFW | ||||||
|     glfwNewFrame |     glfwNewFrame | ||||||
|   , glfwShutdown |   , glfwShutdown | ||||||
|  |  | ||||||
|  |     -- $callbacks | ||||||
|  |   , glfwWindowFocusCallback | ||||||
|  |   , glfwCursorEnterCallback | ||||||
|  |   , glfwMouseButtonCallback | ||||||
|  |   , glfwScrollCallback | ||||||
|  |   , glfwKeyCallback | ||||||
|  |   , glfwCharCallback | ||||||
|  |   , glfwMonitorCallback | ||||||
|   ) |   ) | ||||||
|   where |   where | ||||||
|  |  | ||||||
|  | -- base | ||||||
|  | import Foreign | ||||||
|  |   ( Ptr, castPtr ) | ||||||
|  | import Foreign.C.Types | ||||||
|  |   ( CInt, CDouble, CUInt ) | ||||||
|  | import Unsafe.Coerce (unsafeCoerce) | ||||||
|  |  | ||||||
|  | -- bindings-GLFW | ||||||
|  | import Bindings.GLFW | ||||||
|  |   ( C'GLFWmonitor, C'GLFWwindow ) | ||||||
|  |  | ||||||
|  | -- GLFW-b | ||||||
|  | import Graphics.UI.GLFW | ||||||
|  |   ( Monitor, Window ) | ||||||
|  |  | ||||||
| -- inline-c | -- inline-c | ||||||
| import qualified Language.C.Inline as C | import qualified Language.C.Inline as C | ||||||
|  |  | ||||||
| @@ -44,8 +68,121 @@ glfwNewFrame :: MonadIO m => m () | |||||||
| glfwNewFrame = liftIO do | glfwNewFrame = liftIO do | ||||||
|   [C.exp| void { ImGui_ImplGlfw_NewFrame(); } |] |   [C.exp| void { ImGui_ImplGlfw_NewFrame(); } |] | ||||||
|  |  | ||||||
|  | -- $callbacks | ||||||
|  | -- == GLFW callbacks | ||||||
|  | -- * When calling Init with @install_callbacks=true@: | ||||||
|  | --   GLFW callbacks will be installed for you. | ||||||
|  | --   They will call user's previously installed callbacks, if any. | ||||||
|  | -- * When calling Init with @install_callbacks=false@: | ||||||
|  | --   GLFW callbacks won't be installed. | ||||||
|  | --   You will need to call those function yourself from your own GLFW callbacks. | ||||||
|  |  | ||||||
| -- | Wraps @ImGui_ImplGlfw_Shutdown@. | -- | Wraps @ImGui_ImplGlfw_Shutdown@. | ||||||
| glfwShutdown :: MonadIO m => m () | glfwShutdown :: MonadIO m => m () | ||||||
| glfwShutdown = liftIO do | glfwShutdown = liftIO do | ||||||
|   [C.exp| void { ImGui_ImplGlfw_Shutdown(); } |] |   [C.exp| void { ImGui_ImplGlfw_Shutdown(); } |] | ||||||
|  |  | ||||||
|  | glfwWindowFocusCallback :: MonadIO m => Window -> CInt -> m () | ||||||
|  | glfwWindowFocusCallback window focused = liftIO do | ||||||
|  |   [C.exp| void { | ||||||
|  |     ImGui_ImplGlfw_WindowFocusCallback( | ||||||
|  |       static_cast<GLFWwindow *>( | ||||||
|  |         $(void * windowPtr) | ||||||
|  |       ), | ||||||
|  |       $(int focused) | ||||||
|  |     ); | ||||||
|  |   } |] | ||||||
|  |   where | ||||||
|  |     windowPtr = castPtr $ unWindow window | ||||||
|  |  | ||||||
|  | glfwCursorEnterCallback :: MonadIO m => Window -> CInt -> m () | ||||||
|  | glfwCursorEnterCallback window entered = liftIO do | ||||||
|  |   [C.exp| void { | ||||||
|  |     ImGui_ImplGlfw_CursorEnterCallback( | ||||||
|  |       static_cast<GLFWwindow *>( | ||||||
|  |         $(void * windowPtr) | ||||||
|  |       ), | ||||||
|  |       $(int entered) | ||||||
|  |     ); | ||||||
|  |   } |] | ||||||
|  |   where | ||||||
|  |     windowPtr = castPtr $ unWindow window | ||||||
|  |  | ||||||
|  | glfwMouseButtonCallback :: MonadIO m => Window -> CInt -> CInt -> CInt -> m () | ||||||
|  | glfwMouseButtonCallback window button action mods = liftIO do | ||||||
|  |   [C.exp| void { | ||||||
|  |     ImGui_ImplGlfw_MouseButtonCallback( | ||||||
|  |       static_cast<GLFWwindow *>( | ||||||
|  |         $(void * windowPtr) | ||||||
|  |       ), | ||||||
|  |       $(int button), | ||||||
|  |       $(int action), | ||||||
|  |       $(int mods) | ||||||
|  |     ); | ||||||
|  |   } |] | ||||||
|  |   where | ||||||
|  |     windowPtr = castPtr $ unWindow window | ||||||
|  |  | ||||||
|  | glfwScrollCallback :: MonadIO m => Window -> CDouble -> CDouble -> m () | ||||||
|  | glfwScrollCallback window xoffset yoffset = liftIO do | ||||||
|  |   [C.exp| void { | ||||||
|  |     ImGui_ImplGlfw_ScrollCallback( | ||||||
|  |       static_cast<GLFWwindow *>( | ||||||
|  |         $(void * windowPtr) | ||||||
|  |       ), | ||||||
|  |       $(double xoffset), | ||||||
|  |       $(double yoffset) | ||||||
|  |     ); | ||||||
|  |   } |] | ||||||
|  |   where | ||||||
|  |     windowPtr = castPtr $ unWindow window | ||||||
|  |  | ||||||
|  | glfwKeyCallback :: MonadIO m => Window -> CInt -> CInt -> CInt -> CInt -> m () | ||||||
|  | glfwKeyCallback window key scancode action mods = liftIO do | ||||||
|  |   [C.exp| void { | ||||||
|  |     ImGui_ImplGlfw_KeyCallback( | ||||||
|  |       static_cast<GLFWwindow *>( | ||||||
|  |         $(void * windowPtr) | ||||||
|  |       ), | ||||||
|  |       $(int key), | ||||||
|  |       $(int scancode), | ||||||
|  |       $(int action), | ||||||
|  |       $(int mods) | ||||||
|  |     ); | ||||||
|  |   } |] | ||||||
|  |   where | ||||||
|  |     windowPtr = castPtr $ unWindow window | ||||||
|  |  | ||||||
|  | glfwCharCallback :: MonadIO m => Window -> CUInt -> m () | ||||||
|  | glfwCharCallback window c = liftIO do | ||||||
|  |   [C.exp| void { | ||||||
|  |     ImGui_ImplGlfw_CharCallback( | ||||||
|  |       static_cast<GLFWwindow *>( | ||||||
|  |         $(void * windowPtr) | ||||||
|  |       ), | ||||||
|  |       $(unsigned int c) | ||||||
|  |     ); | ||||||
|  |   } |] | ||||||
|  |   where | ||||||
|  |     windowPtr = castPtr $ unWindow window | ||||||
|  |  | ||||||
|  | glfwMonitorCallback :: MonadIO m => Monitor -> CInt -> m () | ||||||
|  | glfwMonitorCallback monitor event = liftIO do | ||||||
|  |   [C.exp| void { | ||||||
|  |     ImGui_ImplGlfw_MonitorCallback( | ||||||
|  |       static_cast<GLFWmonitor *>( | ||||||
|  |         $(void * monitorPtr) | ||||||
|  |       ), | ||||||
|  |       $(int event) | ||||||
|  |     ); | ||||||
|  |   } |] | ||||||
|  |   where | ||||||
|  |     monitorPtr = castPtr $ unMonitor monitor | ||||||
|  |  | ||||||
|  | -- | Strip the unpublished newtype wrapper. | ||||||
|  | unWindow :: Window -> Ptr C'GLFWwindow | ||||||
|  | unWindow = unsafeCoerce | ||||||
|  |  | ||||||
|  | -- | Strip the unpublished newtype wrapper. | ||||||
|  | unMonitor :: Monitor -> Ptr C'GLFWmonitor | ||||||
|  | unMonitor = unsafeCoerce | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user