haskell-game / dear-imgui.hs

Haskell bindings to Dear ImGui, an immediate mode GUI toolkit
BSD 3-Clause "New" or "Revised" License
142 stars 31 forks source link

Separate valueRef and rangeRef for sliderScalar #142

Closed gilgamec closed 2 years ago

gilgamec commented 2 years ago

The sliderScalar function takes three scalar values: the slider setting, which must be read and updated, and the low and high values of the range, which only need to be read. However, the type used for both is

(HasSetter ref a, HasGetter ref a) => ref

This means that we have to create (e.g.) IORef containers for the bounds, instead of just passing pure lo. This isn't an enormous problem -- we can just create new IORefs before calling sliderScalar and they'lll be GCed after the call -- but it's one more thing to remember, and the range references don't need the extra power.

I therefore suggest that the references work the same as in sliderScalarN, separating valueRef from rangeRef. The new signature of sliderScalar would thus be

sliderScalar
  :: (HasSetter valueRef a, HasGetter valueRef a, HasGetter rangeRef a, Storable a, MonadIO m)
  => String -> ImGuiDataType -> valueRef -> rangeRef -> rangeRef -> String -> ImGuiSliderFlags -> m Bool

In fact, I think that the signature is the only change that would have to be made.