UIng

test Lines of Code Ask DeepWiki

UIng is a Crystal binding for libui-ng.

libui-ng uses the native APIs of each platform: Win32 API, Direct2D, and DirectWrite on Windows; Cocoa (AppKit) on macOS; and GTK+ 3.10+ and Pango on Linux/Unix. You get windows, buttons, text boxes, menus, dialogs, drawing areas, and other standard widgets with the look and feel of each OS. The binary size is small.

Windows Mac Linux

Quick Start

Clone the repository and try the examples:

git clone https://github.com/kojix2/uing
cd uing
crystal run download.cr
crystal run examples/control_gallery.cr

Windows MSVC Setup

For Windows users using MSVC, use Developer Command Prompt or add Windows Kits path:

$env:Path += ";C:\Program Files (x86)\Windows Kits\10\bin\10.0.22621.0\x64"

Installation

Add the dependency to your shard.yml:

dependencies:
  uing:
    github: kojix2/uing

The required libui-ng binary is automatically downloaded from the kojix2/libui-ng GitHub Releases via postinstall.

Supported Platforms

Usage

require "uing"

UIng.init

window = UIng::Window.new("Hello World", 300, 200)
window.on_closing do
  UIng.quit
  true
end

button = UIng::Button.new("Click me")
button.on_clicked do
  UIng.msg_box(window, "Info", "Button clicked!")
end

window.set_child(button)
window.show

UIng.main
UIng.uninit

DSL style

require "uing"

UIng.init do
  UIng::Window.new("Hello World", 300, 200) { |win|
    on_closing { UIng.quit; true }
    set_child {
      UIng::Button.new("Click me") {
        on_clicked {
          UIng.msg_box(win, "Info", "Button clicked!")
        }
      }
    }
    show
  }

  UIng.main
end

Note: The DSL style is implemented using Crystal's with ... yield syntax internally.

Examples

The examples/control_gallery.cr script shows most of the available controls and features in one window.
You can run it with:

crystal run examples/control_gallery.cr

For more examples, see the examples directory.

API Levels

Level Defined in Example Description
High-Level src/uing/*.cr button.on_clicked { }, etc. Object-oriented API
Low-Level src/uing/lib_ui/lib_ui.cr UIng::LibUI.new_button, etc. Direct bindings to libui

Memory Safety

Windows Setup

Hide Console Window

MinGW:

crystal build app.cr --link-flags "-mwindows"

MSVC:

crystal build app.cr --link-flags=/SUBSYSTEM:WINDOWS

Closures in Low-Level Contexts

Development

Note:
This project was developed with the assistance of generative AI.
While kojix2 prefers Vibe Coding, this library is not a product of Vibe Coding. it has been created with a good amount of manual work and human review.

Contributing

License

MIT License

Gallery

This gallery shows screenshots of example on three platforms (Ubuntu, Windows, macOS).
Images are automatically generated and stored in the screenshots branch.

Control

Control Ubuntu Windows macOS
Button basic_button-ubuntu basic_button-windows basic_button-macos
CheckBox basic_checkbox-ubuntu basic_checkbox-windows basic_checkbox-macos
ColorButton basic_color_button-ubuntu basic_color_button-windows basic_color_button-macos
Combobox basic_combobox-ubuntu basic_combobox-windows basic_combobox-macos
DateTimePicker basic_date_time_picker-ubuntu basic_date_time_picker-windows basic_date_time_picker-macos
EditableCombobox basic_editable_combobox-ubuntu basic_editable_combobox-windows basic_editable_combobox-macos
Entry basic_entry-ubuntu basic_entry-windows basic_entry-macos
FontButton basic_font_button-ubuntu basic_font_button-windows basic_font_button-macos
Label basic_label-ubuntu basic_label-windows basic_label-macos
MultilineEntry basic_multiline_entry-ubuntu basic_multiline_entry-windows basic_multiline_entry-macos
Progressbar basic_progressbar-ubuntu basic_progressbar-windows basic_progressbar-macos
RadioButtons basic_radio_buttons-ubuntu basic_radio_buttons-windows basic_radio_buttons-macos
Separator basic_separator-ubuntu basic_separator-windows basic_separator-macos
Slider basic_slider-ubuntu basic_slider-windows basic_slider-macos
Spinbox basic_spinbox-ubuntu basic_spinbox-windows basic_spinbox-macos
Tab basic_tab-ubuntu basic_tab-windows basic_tab-macos

Table

Example Ubuntu Windows macOS
basic_table basic_table-ubuntu basic_table-windows basic_table-macos
advanced_table advanced_table-ubuntu advanced_table-windows advanced_table-macos

Area

Example Ubuntu Windows macOS
basic_area basic_area-ubuntu basic_area-windows basic_area-macos
spirograph spirograph-ubuntu spirograph-windows spirograph-macos