dear-imgui: Haskell bindings for Dear ImGui.

[ bsd3, graphics, library ] [ Propose Tags ]

The package supports multiple rendering backends. Set package flags according to your needs.


[Skip to Readme]

Flags

Manual Flags

NameDescriptionDefault
debug

Enable debug mode.

Disabled
opengl2

Enable OpenGL 2 backend.

Disabled
opengl3

Enable OpenGL 3 backend.

Enabled
vulkan

Enable Vulkan backend.

Disabled
sdl

Enable SDL backend.

Enabled
glfw

Enable GLFW backend.

Disabled
examples

Build executable examples.

Disabled
disable-obsolete

Don't define obsolete functionsenumsbehaviors. Consider enabling from time to time after updating to avoid using soon-to-be obsolete function/names.

Disabled
use-wchar32

Use 32-bit for ImWchar (default is 16-bit) to support unicode planes 1-16. (e.g. point beyond 0xFFFF like emoticons, dingbats, symbols, shapes, ancient languages, etc...)

Enabled

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info

Downloads

Maintainer's Corner

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 1.0.0, 1.0.1, 1.0.2, 1.1.0, 1.2.0, 1.2.1, 1.2.2, 1.3.0, 1.3.1, 1.4.0, 1.5.0, 2.0.0 (info)
Change log ChangeLog.md
Dependencies base (>=4.12 && <4.17), containers (>=0.6.2.1 && <0.7), dear-imgui, directory (>=1.3 && <1.4), filepath (>=1.4 && <1.5), gl, inline-c (>=0.9.0.0 && <0.10), inline-c-cpp, managed, megaparsec (>=9.0 && <9.3), parser-combinators (>=1.2.0 && <1.4), scientific (>=0.3.6.2 && <0.3.8), sdl2, StateVar, template-haskell (>=2.15 && <2.19), text (>=1.2.4 && <2.1), th-lift (>=0.7 && <0.9), transformers (>=0.5.6 && <0.6), unliftio, unordered-containers (>=0.2.11 && <0.3), vector [details]
License BSD-3-Clause
Author Oliver Charles
Maintainer ollie@ocharles.org.uk, aenor.realm@gmail.com
Category Graphics
Source repo head: git clone https://github.com/haskell-game/dear-imgui.hs
Uploaded by AlexanderBondarenko at 2022-05-15T20:38:42Z
Distributions NixOS:2.0.0
Executables vulkan, image, fonts, readme, glfw, test
Downloads 1017 total (29 in the last 30 days)
Rating 2.0 (votes: 1) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for dear-imgui-2.0.0

[back to package description]

Dear ImGui.hs

Dear ImGui is a bloat-free graphical user interface library for C++. It outputs optimized vertex buffers that you can render anytime in your 3D-pipeline enabled application. It is fast, portable, renderer agnostic and self-contained (no external dependencies).

This project contains Haskell bindings to the ImGui project. This allows you to rapidly put together graphical user interfaces in Haskell, with a particular focus to games and graphics intensive applications.

Getting Started

To get started, we'll build the following:

dear-imgui.hs can be used like a normal Haskell library. If you use Cabal, simply add dear-imgui to your build-depends. ImGui supports a variety of backends, and you will need to choose your backend at configuration time. Backends can be enabled using Cabal flags, and these can be set through the cabal.project file. For example, if you want to use a combination of SDL and OpenGL:

package dear-imgui
  flags: +sdl +opengl3

With this done, the following module is the "Hello, World!" of ImGui:

{-# language BlockArguments #-}
{-# language LambdaCase #-}
{-# language OverloadedStrings #-}

module Main ( main ) where

import Control.Exception
import Control.Monad.IO.Class
import Control.Monad.Managed
import DearImGui
import DearImGui.OpenGL2
import DearImGui.SDL
import DearImGui.SDL.OpenGL
import Graphics.GL
import SDL

main :: IO ()
main = do
  -- Initialize SDL
  initializeAll

  runManaged do
    -- Create a window using SDL. As we're using OpenGL, we need to enable OpenGL too.
    window <- do
      let title = "Hello, Dear ImGui!"
      let config = defaultWindow { windowGraphicsContext = OpenGLContext defaultOpenGL }
      managed $ bracket (createWindow title config) destroyWindow

    -- Create an OpenGL context
    glContext <- managed $ bracket (glCreateContext window) glDeleteContext

    -- Create an ImGui context
    _ <- managed $ bracket createContext destroyContext

    -- Initialize ImGui's SDL2 backend
    _ <- managed_ $ bracket_ (sdl2InitForOpenGL window glContext) sdl2Shutdown

    -- Initialize ImGui's OpenGL backend
    _ <- managed_ $ bracket_ openGL2Init openGL2Shutdown

    liftIO $ mainLoop window


mainLoop :: Window -> IO ()
mainLoop window = unlessQuit do
  -- Tell ImGui we're starting a new frame
  openGL2NewFrame
  sdl2NewFrame
  newFrame

  -- Build the GUI
  withWindowOpen "Hello, ImGui!" do
    -- Add a text widget
    text "Hello, ImGui!"

    -- Add a button widget, and call 'putStrLn' when it's clicked
    button "Clickety Click" >>= \case
      False -> return ()
      True  -> putStrLn "Ow!"

  -- Show the ImGui demo window
  showDemoWindow

  -- Render
  glClear GL_COLOR_BUFFER_BIT

  render
  openGL2RenderDrawData =<< getDrawData

  glSwapWindow window

  mainLoop window

  where
    -- Process the event loop
    unlessQuit action = do
      shouldQuit <- checkEvents
      if shouldQuit then pure () else action

    checkEvents = do
      pollEventWithImGui >>= \case
        Nothing ->
          return False
        Just event ->
          (isQuit event ||) <$> checkEvents

    isQuit event =
      SDL.eventPayload event == SDL.QuitEvent

Hacking

If you would like to help dear-imgui, here's how you can get started.

The best path to development is using Nix. Once you have Nix installed (either in your operating system, or by running NixOS), you can enter a development shell:

$ nix-shell

You should now be in a bash shell where you can run cabal build all, cabal run readme, etc.

If you experience any difficulties, please don't hesistate to raise an issue.

Getting Help

Feel free to raise bugs, questions and feature requests on the GitHub issue tracker.

We have a Matrix room at #dear-imgui.hs:ocharles.org.uk.