The Crystal Programming Language Forum

Announcing a GUI library – bindings to Dear ImGui

Dear ImGui is a library for immediate-mode graphical interfaces – rendering a UI and handling user input. Typically it’s used to add a debugging UI to an existing graphical project, like a video game, but also works fine on its own.

I have finished the project to make Crystal bindings to it. The usage feels quite idiomatic in Crystal but also close to the original C++ library.

A code example would be…

@f = 0.6f32
@buf = ImGui::TextBuffer.new(100)
# ...
ImGui.text("Hello, world %d", 123)
if ImGui.button("Save")
  p! @buf.to_s, @f  # Executed when the button gets clicked
end
ImGui.input_text("string", @buf)
ImGui.slider_float("float", pointerof(@f), 0.0, 1.0)

image

(see how it might fit into a full program)


There is also a companion project to make it easily usable with SFML / CrSFML:

It’s also possible to use it with any other “backend”, just that some “wiring” is required first.
I’d be glad to collaborate if someone wants to work on SDL integration, for example.

12 Likes

Nice! I love seeing more movement on GUI options for Crystal. :slight_smile:

I’m excited to try this out!

1 Like