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

Add compile-time config #115

Closed dpwiz closed 2 years ago

dpwiz commented 2 years ago

https://github.com/ocornut/imgui/blob/master/imconfig.h

A) You may edit imconfig.h (and not overwrite it when updating Dear ImGui, or maintain a patch/rebased branch with your modifications to it) B) or '#define IMGUI_USER_CONFIG "my_imgui_config.h"' in your project and then add directives in your own file without touching this template.

chekoopa commented 2 years ago

I've found a few ways of implementation.

We could incorporate some of these options through flags. It is definitely global, yet AFAIK only acceptable for boolean options. I don't know how to send string values through Cabal configuration.

flag wchar32
  description:
    Use 32-bit integers to represent Unicode characters.
  default:
    False
  manual:
    True

if flag(wchar32)
  cxx-options: -DIMGUI_USE_WCHAR32
  1. We could embed these defines right into the code. Writing defines into C-blocks is very dirty (and useless) approach, so we have C.verbatim. I'm afraid that it won't work globally (IMGUI_USER_CONFIG is used under #pragma once somewhere in the library code)...
C.verbatim "#define IM_ASSERT(_EXPR) ((void)(_EXPR))"
  1. ...But! If we somehow guess the name of the output file corresponding to DearImGui.Config module, set it as IMGUI_USER_CONFIG in Cabal configuration, we could use ifdef and verbatims... But seems impossible, and still, no string options.
dpwiz commented 2 years ago

Alternatively, we can turn on full unicode support globally.

This looks like a right thing to do by default. Optimisations can follow later.

dpwiz commented 2 years ago
  1. kinda works, if prone to becoming stale.