mirror of
				https://github.com/Drezil/dear-imgui.hs.git
				synced 2025-10-29 20:21:47 +01:00 
			
		
		
		
	Update StateVars only when its widget reports a change (#42)
This commit is contained in:
		
				
					committed by
					
						 GitHub
						GitHub
					
				
			
			
				
	
			
			
			
						parent
						
							ebd5286e1c
						
					
				
				
					commit
					b0337eb084
				
			| @@ -163,6 +163,8 @@ module DearImGui | ||||
|   where | ||||
|  | ||||
| -- base | ||||
| import Control.Monad | ||||
|   ( when ) | ||||
| import Data.Bool | ||||
| import Data.Coerce  | ||||
|   ( coerce ) | ||||
| @@ -412,6 +414,7 @@ checkbox label ref = liftIO do | ||||
|     changed <- withCString label \labelPtr -> | ||||
|       (0 /=) <$> [C.exp| bool { Checkbox($(char* labelPtr), $(bool* boolPtr)) } |] | ||||
|  | ||||
|     when changed do | ||||
|       newValue <- peek boolPtr | ||||
|       ref $=! (newValue == 1) | ||||
|  | ||||
| @@ -484,6 +487,7 @@ dragFloat desc ref speed minValue maxValue = liftIO do | ||||
|     changed <- withCString desc \descPtr -> | ||||
|       (0 /=) <$> [C.exp| bool { DragFloat( $(char* descPtr), $(float *floatPtr), $(float speed'), $(float min'), $(float max')) } |] | ||||
|  | ||||
|     when changed do | ||||
|       newValue <- peek floatPtr | ||||
|       ref $=! realToFrac newValue | ||||
|  | ||||
| @@ -503,6 +507,7 @@ dragFloat2 desc ref speed minValue maxValue = liftIO do | ||||
|     changed <- withCString desc \descPtr -> | ||||
|       (0 /=) <$> [C.exp| bool { DragFloat2( $(char* descPtr), $(float *floatPtr), $(float speed'), $(float min'), $(float max')) } |] | ||||
|  | ||||
|     when changed do | ||||
|       [x', y'] <- peekArray 2 floatPtr | ||||
|       ref $=! (realToFrac x', realToFrac y') | ||||
|  | ||||
| @@ -522,6 +527,7 @@ dragFloat3 desc ref speed minValue maxValue = liftIO do | ||||
|     changed <- withCString desc \descPtr -> | ||||
|       (0 /=) <$> [C.exp| bool { DragFloat3( $(char* descPtr), $(float *floatPtr), $(float speed'), $(float min'), $(float max')) } |] | ||||
|  | ||||
|     when changed do | ||||
|       [x', y', z'] <- peekArray 3 floatPtr | ||||
|       ref $=! (realToFrac x', realToFrac y', realToFrac z') | ||||
|  | ||||
| @@ -541,6 +547,7 @@ dragFloat4 desc ref speed minValue maxValue = liftIO do | ||||
|     changed <- withCString desc \descPtr -> | ||||
|       (0 /=) <$> [C.exp| bool { DragFloat4( $(char* descPtr), $(float *floatPtr), $(float speed'), $(float min'), $(float max')) } |] | ||||
|  | ||||
|     when changed do | ||||
|       [x', y', z', u'] <- peekArray 4 floatPtr | ||||
|       ref $=! (realToFrac x', realToFrac y', realToFrac z', realToFrac u') | ||||
|  | ||||
| @@ -560,6 +567,7 @@ sliderFloat desc ref minValue maxValue = liftIO do | ||||
|     changed <- withCString desc \descPtr -> | ||||
|       (0 /=) <$> [C.exp| bool { SliderFloat( $(char* descPtr), $(float *floatPtr), $(float min'), $(float max')) } |] | ||||
|  | ||||
|     when changed do | ||||
|       newValue <- peek floatPtr | ||||
|       ref $=! realToFrac newValue | ||||
|  | ||||
| @@ -578,6 +586,7 @@ sliderFloat2 desc ref minValue maxValue = liftIO do | ||||
|     changed <- withCString desc \descPtr -> | ||||
|       (0 /=) <$> [C.exp| bool { SliderFloat2( $(char* descPtr), $(float *floatPtr), $(float min'), $(float max')) } |] | ||||
|  | ||||
|     when changed do | ||||
|       [x', y'] <- peekArray 2 floatPtr | ||||
|       ref $=! (realToFrac x', realToFrac y') | ||||
|  | ||||
| @@ -596,6 +605,7 @@ sliderFloat3 desc ref minValue maxValue = liftIO do | ||||
|     changed <- withCString desc \descPtr -> | ||||
|       (0 /=) <$> [C.exp| bool { SliderFloat3( $(char* descPtr), $(float *floatPtr), $(float min'), $(float max')) } |] | ||||
|  | ||||
|     when changed do | ||||
|       [x', y', z'] <- peekArray 3 floatPtr | ||||
|       ref $=! (realToFrac x', realToFrac y', realToFrac z') | ||||
|  | ||||
| @@ -614,6 +624,7 @@ sliderFloat4 desc ref minValue maxValue = liftIO do | ||||
|     changed <- withCString desc \descPtr -> | ||||
|       (0 /=) <$> [C.exp| bool { SliderFloat4( $(char* descPtr), $(float *floatPtr), $(float min'), $(float max')) } |] | ||||
|  | ||||
|     when changed do | ||||
|       [x', y', z', u'] <- peekArray 4 floatPtr | ||||
|       ref $=! (realToFrac x', realToFrac y', realToFrac z', realToFrac u') | ||||
|  | ||||
| @@ -648,6 +659,7 @@ colorPicker3 desc ref = liftIO do | ||||
|     changed <- withCString desc \descPtr -> | ||||
|       (0 /= ) <$> [C.exp| bool { ColorPicker3( $(char* descPtr), $(float *refPtr) ) } |] | ||||
|  | ||||
|     when changed do | ||||
|       [x', y', z'] <- peekArray 3 refPtr | ||||
|       ref $=! ImVec3 (realToFrac x') (realToFrac y') (realToFrac z') | ||||
|  | ||||
| @@ -664,6 +676,7 @@ colorButton desc ref = liftIO do | ||||
|     changed <- withCString desc \descPtr -> | ||||
|       (0 /=) <$> [C.exp| bool { ColorButton( $(char* descPtr), *$(ImVec4 *refPtr) ) } |] | ||||
|  | ||||
|     when changed do | ||||
|       newValue <- peek refPtr | ||||
|       ref $=! newValue | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user