Skip to content

kojix2/uing

Repository files navigation

UIng

test

UIng is yet another Crystal binding for libui-ng or libui-dev.

Windows Mac Linux

🔶 Installation

⇩ Downloading Binaries

crystal run download.cr

The libui project does not distribute pre-compiled binaries.
Therefore, this project uses the following sources to obtain binaries:

OS Binary Source
MacOS / Linux Builds from the kojix2/libui-ng repository (pre-build branch)
Windows Pre-built binaries distributed with libui-dev

Windows

  • MinGW (mingw-w64-crystal) is recommended for Windows. UCRT / Clang is not supported because libui-dev is built with MinGW64.
  • MSVC (x86_64-msvc) is not recommended but can be used with some limitations. Make sure rc.exe is in the PATH.
# Add the path to the Windows Kits
$env:Path += ";C:\Program Files (x86)\Windows Kits\10\bin\10.0.22621.0\x64"

See: https://crystal-lang.org/install/#windows

🔶 Usage

The Control gallery example uses a high-level API.

crystal build examples/control_gallery.cr
./control_gallery

For more details, see examples.

The middle-level API is reasonably well-implemented, allowing users to access most of libui's functionality. Please start by using this level.

Binding Levels

Level Defined in Example Description
Low-Level src/uing/lib_ui/lib_ui.cr UIng::LibUI.new_button, etc. Direct bindings to the libui.
Middle-Level src/uing.cr UIng.button_text, etc. Handles memory management.
High-Level src/uing/*.cr button.on_clicked { }, etc. Custom API or macros.
  • At the middle level, memory management tasks such as string deallocation are handled.
  • The high-level API implementation is limited; the Control module provides a method_missing macro to handle undefined methods.

Hide Console Window on Windows

MinGW

crystal build examples/basic_window.cr --link-flags "-mwindows"

MSVC

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

Note: The program will crash if you attempt to output to the console.

🔶 Closures and Their Limitations

🚧

🔶 Development

Additional Rules

  • UIng::LibUI is a module dedicated to bindings.
  • Use crystal_lib to generate low-level bindings (manual modifications required).
  • Passing a Proc to a C function: Official Documentation.

🔶 Windows Compatibility

ComCtl32 Version Issues

  • libui-ng's msg_box implementation relies on TaskDialog.
  • TaskDialog requires ComCtl32.dll version 6.
  • There are other dependencies on version 6 besides TaskDialog.
  • The standard ComCtl32 is version 5, so a manifest file is necessary.
  • For MSVC the link flag specifies the manuf.
  • For MinGW, comctl32.res is generated when download.cr is run.

Debugging

  • MinGW version of gdb can be used for debugging.

🔶 Contributing

You can contribute to this project by:

  • ☑ Forking this repository
  • ☑ Reporting bugs
  • ☑ Fixing bugs and submitting pull requests
  • ☑ Improving documentation
  • ☑ Suggesting or adding new features

🔶 License

This project is licensed under the MIT License.

Releases

No releases published

Packages

No packages published