Update StateVars only when its widget reports a change (#42)

This commit is contained in:
Alexander Bondarenko 2021-03-12 14:03:54 +03:00 committed by GitHub
parent ebd5286e1c
commit b0337eb084
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -163,6 +163,8 @@ module DearImGui
where where
-- base -- base
import Control.Monad
( when )
import Data.Bool import Data.Bool
import Data.Coerce import Data.Coerce
( coerce ) ( coerce )
@ -412,6 +414,7 @@ checkbox label ref = liftIO do
changed <- withCString label \labelPtr -> changed <- withCString label \labelPtr ->
(0 /=) <$> [C.exp| bool { Checkbox($(char* labelPtr), $(bool* boolPtr)) } |] (0 /=) <$> [C.exp| bool { Checkbox($(char* labelPtr), $(bool* boolPtr)) } |]
when changed do
newValue <- peek boolPtr newValue <- peek boolPtr
ref $=! (newValue == 1) ref $=! (newValue == 1)
@ -484,6 +487,7 @@ dragFloat desc ref speed minValue maxValue = liftIO do
changed <- withCString desc \descPtr -> changed <- withCString desc \descPtr ->
(0 /=) <$> [C.exp| bool { DragFloat( $(char* descPtr), $(float *floatPtr), $(float speed'), $(float min'), $(float max')) } |] (0 /=) <$> [C.exp| bool { DragFloat( $(char* descPtr), $(float *floatPtr), $(float speed'), $(float min'), $(float max')) } |]
when changed do
newValue <- peek floatPtr newValue <- peek floatPtr
ref $=! realToFrac newValue ref $=! realToFrac newValue
@ -503,6 +507,7 @@ dragFloat2 desc ref speed minValue maxValue = liftIO do
changed <- withCString desc \descPtr -> changed <- withCString desc \descPtr ->
(0 /=) <$> [C.exp| bool { DragFloat2( $(char* descPtr), $(float *floatPtr), $(float speed'), $(float min'), $(float max')) } |] (0 /=) <$> [C.exp| bool { DragFloat2( $(char* descPtr), $(float *floatPtr), $(float speed'), $(float min'), $(float max')) } |]
when changed do
[x', y'] <- peekArray 2 floatPtr [x', y'] <- peekArray 2 floatPtr
ref $=! (realToFrac x', realToFrac y') ref $=! (realToFrac x', realToFrac y')
@ -522,6 +527,7 @@ dragFloat3 desc ref speed minValue maxValue = liftIO do
changed <- withCString desc \descPtr -> changed <- withCString desc \descPtr ->
(0 /=) <$> [C.exp| bool { DragFloat3( $(char* descPtr), $(float *floatPtr), $(float speed'), $(float min'), $(float max')) } |] (0 /=) <$> [C.exp| bool { DragFloat3( $(char* descPtr), $(float *floatPtr), $(float speed'), $(float min'), $(float max')) } |]
when changed do
[x', y', z'] <- peekArray 3 floatPtr [x', y', z'] <- peekArray 3 floatPtr
ref $=! (realToFrac x', realToFrac y', realToFrac z') ref $=! (realToFrac x', realToFrac y', realToFrac z')
@ -541,6 +547,7 @@ dragFloat4 desc ref speed minValue maxValue = liftIO do
changed <- withCString desc \descPtr -> changed <- withCString desc \descPtr ->
(0 /=) <$> [C.exp| bool { DragFloat4( $(char* descPtr), $(float *floatPtr), $(float speed'), $(float min'), $(float max')) } |] (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 [x', y', z', u'] <- peekArray 4 floatPtr
ref $=! (realToFrac x', realToFrac y', realToFrac z', realToFrac u') ref $=! (realToFrac x', realToFrac y', realToFrac z', realToFrac u')
@ -560,6 +567,7 @@ sliderFloat desc ref minValue maxValue = liftIO do
changed <- withCString desc \descPtr -> changed <- withCString desc \descPtr ->
(0 /=) <$> [C.exp| bool { SliderFloat( $(char* descPtr), $(float *floatPtr), $(float min'), $(float max')) } |] (0 /=) <$> [C.exp| bool { SliderFloat( $(char* descPtr), $(float *floatPtr), $(float min'), $(float max')) } |]
when changed do
newValue <- peek floatPtr newValue <- peek floatPtr
ref $=! realToFrac newValue ref $=! realToFrac newValue
@ -578,6 +586,7 @@ sliderFloat2 desc ref minValue maxValue = liftIO do
changed <- withCString desc \descPtr -> changed <- withCString desc \descPtr ->
(0 /=) <$> [C.exp| bool { SliderFloat2( $(char* descPtr), $(float *floatPtr), $(float min'), $(float max')) } |] (0 /=) <$> [C.exp| bool { SliderFloat2( $(char* descPtr), $(float *floatPtr), $(float min'), $(float max')) } |]
when changed do
[x', y'] <- peekArray 2 floatPtr [x', y'] <- peekArray 2 floatPtr
ref $=! (realToFrac x', realToFrac y') ref $=! (realToFrac x', realToFrac y')
@ -596,6 +605,7 @@ sliderFloat3 desc ref minValue maxValue = liftIO do
changed <- withCString desc \descPtr -> changed <- withCString desc \descPtr ->
(0 /=) <$> [C.exp| bool { SliderFloat3( $(char* descPtr), $(float *floatPtr), $(float min'), $(float max')) } |] (0 /=) <$> [C.exp| bool { SliderFloat3( $(char* descPtr), $(float *floatPtr), $(float min'), $(float max')) } |]
when changed do
[x', y', z'] <- peekArray 3 floatPtr [x', y', z'] <- peekArray 3 floatPtr
ref $=! (realToFrac x', realToFrac y', realToFrac z') ref $=! (realToFrac x', realToFrac y', realToFrac z')
@ -614,6 +624,7 @@ sliderFloat4 desc ref minValue maxValue = liftIO do
changed <- withCString desc \descPtr -> changed <- withCString desc \descPtr ->
(0 /=) <$> [C.exp| bool { SliderFloat4( $(char* descPtr), $(float *floatPtr), $(float min'), $(float max')) } |] (0 /=) <$> [C.exp| bool { SliderFloat4( $(char* descPtr), $(float *floatPtr), $(float min'), $(float max')) } |]
when changed do
[x', y', z', u'] <- peekArray 4 floatPtr [x', y', z', u'] <- peekArray 4 floatPtr
ref $=! (realToFrac x', realToFrac y', realToFrac z', realToFrac u') ref $=! (realToFrac x', realToFrac y', realToFrac z', realToFrac u')
@ -648,6 +659,7 @@ colorPicker3 desc ref = liftIO do
changed <- withCString desc \descPtr -> changed <- withCString desc \descPtr ->
(0 /= ) <$> [C.exp| bool { ColorPicker3( $(char* descPtr), $(float *refPtr) ) } |] (0 /= ) <$> [C.exp| bool { ColorPicker3( $(char* descPtr), $(float *refPtr) ) } |]
when changed do
[x', y', z'] <- peekArray 3 refPtr [x', y', z'] <- peekArray 3 refPtr
ref $=! ImVec3 (realToFrac x') (realToFrac y') (realToFrac z') ref $=! ImVec3 (realToFrac x') (realToFrac y') (realToFrac z')
@ -664,6 +676,7 @@ colorButton desc ref = liftIO do
changed <- withCString desc \descPtr -> changed <- withCString desc \descPtr ->
(0 /=) <$> [C.exp| bool { ColorButton( $(char* descPtr), *$(ImVec4 *refPtr) ) } |] (0 /=) <$> [C.exp| bool { ColorButton( $(char* descPtr), *$(ImVec4 *refPtr) ) } |]
when changed do
newValue <- peek refPtr newValue <- peek refPtr
ref $=! newValue ref $=! newValue