Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling GetIO, GetStyle and GetStyleColorVec4 #16

Open
sheaf opened this issue Jan 27, 2021 · 1 comment
Open

Handling GetIO, GetStyle and GetStyleColorVec4 #16

sheaf opened this issue Jan 27, 2021 · 1 comment
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@sheaf
Copy link
Contributor

sheaf commented Jan 27, 2021

These 3 functions return a reference.

GetStyleColorVec4 seems to just be used to pass a reference to PushStyleColor, so I don't think we need to do anything special.

On the other hand, GetIO and GetStyle allow the user to change internal ImGui settings by mutating the state. So I think we might want a slightly different API. For instance, we could have:

data ImGuiIO = ImGuiIOHandle ( Ptr ImGuiIO )
data ImGuiStyle = ImGuiStyleHandle ( Ptr ImGuiStyle )

getIO :: MonadIO m => m ImGuiIO
getStyle :: MonadIO m => m ImGuiStyle

and then an interface for getting/setting fields:

data ImGuiIOFieldName
  = ConfigFlags
  | BackendFlags
  | DisplaySize
  | DeltaTime
  ...

data ImGuiStyleFieldName
  = Alpha
  | WindowPadding
  | WindowRounding
  ...


class HasImGuiIOField ( name :: ImGuiIOFieldName ) ( a :: Type ) | name -> a where
  getIOField :: ImGuiIO -> m a
  setIOField :: ImGuiIO -> a -> m ()

class ImGuiStyleField ( name :: ImGuiStyleFieldName ) ( a :: Type ) | name -> a where
  getStyleField :: ImGuiStyle -> m a
  setStyleField :: ImGuiStyle -> a -> m ()


instance HasImGuiIOField 'ConfigFlags  ImGuiConfigFlags
instance HasImGuiIOField 'BackendFlags ImGuiBackendFlags
instance HasImGuiIOField 'DisplaySize ImVec4
instance HasImGuiIOField 'DeltaTime Float

instance HasImGuiStyleField 'Alpha Float
instance HasImGuiStyleField 'WindowPadding ImVec2
instance HasImGuiStyleField 'WindowRounding Float

This would definitely be an improvement in usability over manually mutating fields through the reference.
Another upside is that it avoids us having to actually define the ImGuiIO and ImGuiStyle structs proper: we can just implement whatever get/set operations we want. I think this is particularly relevant with the function pointers in the ImGuiIO struct like GetClipboardTextFn, SetClipboardTextFn, where it seems much more appropriate to have a HasImGuiIOField instance for 'ClipboardTextFn as opposed to requiring the user to manage two different function pointers.

@dpwiz dpwiz added enhancement New feature or request help wanted Extra attention is needed labels Apr 18, 2021
@Swarthe
Copy link
Contributor

Swarthe commented Feb 15, 2024

I would be willing to help with this! Is it alright if I make a beta implementation of your proposal?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants