{"id":13877926,"url":"https://github.com/kojix2/LibUI","last_synced_at":"2025-07-16T13:32:51.621Z","repository":{"id":43721340,"uuid":"318790851","full_name":"kojix2/LibUI","owner":"kojix2","description":"A portable GUI library for Ruby","archived":false,"fork":false,"pushed_at":"2024-10-28T16:31:01.000Z","size":543,"stargazers_count":205,"open_issues_count":15,"forks_count":10,"subscribers_count":7,"default_branch":"main","last_synced_at":"2024-11-21T09:11:02.623Z","etag":null,"topics":["libui","ruby"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kojix2.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"ko_fi":"kojix2"}},"created_at":"2020-12-05T13:07:04.000Z","updated_at":"2024-11-16T01:35:22.000Z","dependencies_parsed_at":"2023-11-08T05:47:08.963Z","dependency_job_id":"b9c022b6-4f1c-4b61-af67-a0fabab5dfd0","html_url":"https://github.com/kojix2/LibUI","commit_stats":{"total_commits":277,"total_committers":6,"mean_commits":"46.166666666666664","dds":"0.018050541516245522","last_synced_commit":"84ba520f664a1f8cf140dbf642e9be2f35c54aa6"},"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kojix2%2FLibUI","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kojix2%2FLibUI/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kojix2%2FLibUI/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kojix2%2FLibUI/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kojix2","download_url":"https://codeload.github.com/kojix2/LibUI/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226134226,"owners_count":17578778,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["libui","ruby"],"created_at":"2024-08-06T08:01:35.074Z","updated_at":"2025-07-16T13:32:51.604Z","avatar_url":"https://github.com/kojix2.png","language":"Ruby","readme":"# LibUI\n\n[![test](https://github.com/kojix2/LibUI/actions/workflows/test.yml/badge.svg)](https://github.com/kojix2/LibUI/actions/workflows/test.yml)\n[![Gem Version](https://badge.fury.io/rb/libui.svg)](https://badge.fury.io/rb/libui)\n\u003ca href=\"https://github.com/AndyObtiva/glimmer-dsl-libui\"\u003e\u003cimg alt=\"glimmer-dsl-libui\" src=\"https://github.com/AndyObtiva/glimmer/blob/master/images/glimmer-logo-hi-res.svg\" width=\"50\" height=\"50\" align=\"right\"\u003e\u003c/a\u003e\n[![Pre-build](https://github.com/kojix2/libui-ng/actions/workflows/pre-build.yml/badge.svg?branch=pre-build)](https://github.com/kojix2/libui-ng/actions/workflows/pre-build.yml)\n[![Lines of Code](https://img.shields.io/endpoint?url=https%3A%2F%2Ftokei.kojix2.net%2Fbadge%2Fgithub%2Fkojix2%2FLibUI%2Flines)](https://tokei.kojix2.net/github/kojix2/LibUI)\n\nLibUI is a Ruby wrapper for libui family.\n\n:rocket: [libui-ng](https://github.com/libui-ng/libui-ng) - A cross-platform portable GUI library\n\n:wrench: [libui-dev](https://github.com/petabyt/libui-dev) - Native UI library for C - with some extras \n\n:radio_button: [libui](https://github.com/andlabs/libui) - Original version by andlabs.\n\n## Installation\n\nIt is recommended to use libui-ng, via the --pre commandline flag:\n\n```sh\ngem install libui --pre # libui-ng; this will fetch libui-0.1.3.pre-x86_64-linux.gem\n```\n\nIf for some reason you would like to install the slightly older libui-0.1.2.gem release, issue:\n\n```sh\ngem install libui\n```\n\n- The gem package includes the libui-ng shared library for Windows, Mac, and Linux.\n  - Namely `libui.dll`, `libui.dylib`, or `libui.so`.\n- No dependencies required.\n  - The libui gem uses the standard Ruby library [Fiddle](https://github.com/ruby/fiddle) to call C functions.\n\n| Windows                                                                                                          | Mac                                                                                                              | Linux                                                                                                            |\n| ---------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------- |\n| \u003cimg src=\"https://user-images.githubusercontent.com/5798442/103118046-900ea780-46b0-11eb-81fc-32626762e4df.png\"\u003e | \u003cimg src=\"https://user-images.githubusercontent.com/5798442/103118059-99980f80-46b0-11eb-9d12-324ec4d297c9.png\"\u003e | \u003cimg src=\"https://user-images.githubusercontent.com/5798442/103118068-a0bf1d80-46b0-11eb-8c5c-3bdcc3dcfb26.png\"\u003e |\n\nNotes:\n\n- If you are using the 32-bit (x86) version of Ruby, you need to download the 32-bit (x86) native dll. See the [Development](#development) section.\n- On Windows, libui may not work due to missing DLLs. In that case, you need to install [Visual C++ Redistributable](https://docs.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist). See ([#48](https://github.com/kojix2/LibUI/issues/48))\n- Users with [Raspberry Pi](https://www.raspberrypi.com/) or other platforms will need to compile the C libui library. See the [Development](#development) section.\n\n## Usage\n\n```ruby\nrequire 'libui'\n\nUI = LibUI\n\nUI.init\n\nmain_window = UI.new_window('hello world', 200, 100, 1)\n\nbutton = UI.new_button('Button')\n\nUI.button_on_clicked(button) do\n  UI.msg_box(main_window, 'Information', 'You clicked the button')\nend\n\nUI.window_on_closing(main_window) do\n  puts 'Bye Bye'\n  UI.control_destroy(main_window)\n  UI.quit\n  0\nend\n\nUI.window_set_child(main_window, button)\nUI.control_show(main_window)\n\nUI.main\nUI.quit\n```\n\nFor more examples, see the [examples](https://github.com/kojix2/libui/tree/main/examples) directory.\n\n### General Rules\n\nCompared to the original libui library written in C:\n\n- Method names use snake_case.\n- The last argument can be omitted if it's nil.\n- A block can be passed as a callback.\n  - The block will be converted to a Proc object and added as the last argument.\n  - The last argument can still be omitted when nil.\n\nYou can use [the documentation for libui's Go bindings](https://pkg.go.dev/github.com/andlabs/ui) as a reference.\n\n### DSLs for LibUI\n\nLibUI is not object-oriented because it is a thin Ruby wrapper (binding) for the procedural C libui library, mirroring its API structure.\n\nTo build actual applications, it is recommended to use a DSL for LibUI, as they enable writing object-oriented code the Ruby way (instead of procedural code the C way):\n\n- [Glimmer DSL for LibUI](https://github.com/AndyObtiva/glimmer-dsl-libui)\n- [libui_paradise](https://rubygems.org/gems/libui_paradise)\n\n### Working with fiddle pointers\n\n```ruby\nrequire 'libui'\nUI = LibUI\nUI.init\n```\n\nTo convert a pointer to a string:\n\n```ruby\nlabel = UI.new_label(\"Ruby\")\np pointer = UI.label_text(label) # #\u003cFiddle::Pointer\u003e\np pointer.to_s # Ruby\n```\n\nIf you need to use C structs, you can do the following:\n\n```ruby\nfont_button = UI.new_font_button\n\n# Allocate memory\nfont_descriptor = UI::FFI::FontDescriptor.malloc\nfont_descriptor.to_ptr.free = Fiddle::RUBY_FREE\n# font_descriptor = UI::FFI::FontDescriptor.malloc(Fiddle::RUBY_FREE) # fiddle 1.0.1 or higher\n\nUI.font_button_on_changed(font_button) do\n  UI.font_button_font(font_button, font_descriptor)\n  p family:  font_descriptor.Family.to_s,\n    size:    font_descriptor.Size,\n    weight:  font_descriptor.Weight,\n    italic:  font_descriptor.Italic,\n    stretch: font_descriptor.Stretch\nend\n```\n\n- Callbacks\n  - In Ruby/Fiddle, a C callback function is written as an object of\n    `Fiddle::Closure::BlockCaller` or `Fiddle::Closure`.\n    Be careful about Ruby's garbage collection - if the function object is collected, memory will be freed resulting in a segmentation violation when the callback is invoked.\n\n```ruby\n# Assign to a local variable to prevent it from being collected by GC.\nhandler.MouseEvent   = (c1 = Fiddle::Closure::BlockCaller.new(0, [0]) {})\nhandler.MouseCrossed = (c2 = Fiddle::Closure::BlockCaller.new(0, [0]) {})\nhandler.DragBroken   = (c3 = Fiddle::Closure::BlockCaller.new(0, [0]) {})\n```\n\n### Creating a Windows executable (.exe) with OCRA\n\nOCRA (One-Click Ruby Application) builds Windows executables from Ruby source code.\n\n- https://github.com/larsch/ocra/\n\nTo build an exe with Ocra, include 3 DLLs from the ruby_builtin_dlls folder:\n\n```sh\nocra examples/control_gallery.rb        ^\n  --dll ruby_builtin_dlls/libssp-0.dll  ^\n  --dll ruby_builtin_dlls/libgmp-10.dll ^\n  --dll ruby_builtin_dlls/libffi-7.dll  ^\n  --gem-all=fiddle                      ^\n```\n\nAdd additional options below if necessary:\n\n```sh\n  --window                              ^\n  --add-all-core                        ^\n  --chdir-first                         ^\n  --icon assets\\app.ico                 ^\n  --verbose                             ^\n  --output out\\gallery.exe\n```\n\n## Development\n\n```sh\ngit clone https://github.com/kojix2/libui\ncd libui\nbundle install\nbundle exec rake vendor:auto # vendor:build\nbundle exec rake test\n```\n\n### Pre-built shared libraries for libui-ng\n\nUse the following rake tasks to download the shared library required for your platform:\n\n`rake -T`\n\n```\nrake vendor:build[hash]          # Build libui-ng latest master [commit hash]\nrake vendor:libui-ng:macos       # Download latest official pre-build for Mac to vendor directory\nrake vendor:libui-ng:ubuntu_x64  # Download latest official pre-build for Ubuntu to vendor directory\nrake vendor:macos_arm64          # Download pre-build for Mac to vendor directory\nrake vendor:macos_x64            # Download pre-build for Mac to vendor directory\nrake vendor:raspbian_aarch64     # Download pre-build for Raspbian to vendor directory\nrake vendor:ubuntu_x64           # Download pre-build for Ubuntu to vendor directory\nrake vendor:windows_x64          # Download pre-build for Windows to vendor directory\nrake vendor:windows_x86          # Download pre-build for Windows to vendor directory\n```\n\nFor example, if you are using a 32-bit (x86) version of Ruby on Windows, type `vendor:windows_x86`.\nThese shared libraries are [artifacts](https://github.com/kojix2/libui-ng/actions/workflows/pre-build.yml) of the [pre-build branch](https://github.com/kojix2/libui-ng/tree/pre-build) of [kojix2/libui-ng](https://github.com/kojix2/libui-ng). In that case, please let us know.\n\n### Using C libui compiled from source code\n\nThe following Rake task will compile libui-ng. meson or ninja is required.\n\n`bundle exec rake vendor:build`\n\nAlternatively, you can tell Ruby LibUI the location of shared libraries. Set the environment variable `LIBUIDIR` to specify the path to the shared library. (See [#46](https://github.com/kojix2/LibUI/issues/46#issuecomment-1041575792)). This is especially useful on platforms where the LibUI gem does not provide shared library, such as the ARM architecture (used in devices like Raspberry Pi).\n\nAnother simple approach is to replace the shared libraries in the gem vendor directory with the ones you have compiled.\n\n### Publishing gems\n\n```sh\nls vendor             # check the vendor directory\nrm -rf pkg            # remove previously built gems\nrake build_platform   # build gems\n\n# Check the contents of the gem\nfind pkg -name *.gem -exec sh -c \"echo; echo \\# {}; tar -O -f {} -x data.tar.gz | tar zt\" \\;\n\nrake release_platform # publish gems\n```\n\n### libui or libui-ng\n\n- From version 0.1.X, we plan to support only libui-ng/libui-ng.\n- Version 0.0.X only supports andlabs/libui.\n\n## Contributing\n\nWould you like to contribute to LibUI?\n\n- Please feel free to send us your [pull requests](https://github.com/kojix2/libui/pulls).\n  - Small corrections, such as typo fixes, are appreciated.\n- Did you find any bugs? Submit them in the [issues](https://github.com/kojix2/LibUI/issues) section!\n\nDo you need commit rights?\n\n- If you need commit rights to my repository or want to get admin rights and take over the project, please feel free to contact @kojix2.\n- Many OSS projects become abandoned because only the founder has commit rights to the original repository.\n\nSupport libui-ng development\n\n- Contributing to the development of libui-ng is a contribution to the entire libui community, including Ruby's LibUI.\n- For example, it would be easier to release LibUI in Ruby if libui-ng could be built easily and official shared libraries could be distributed.\n\n## Acknowledgements\n\nThis project is inspired by libui-ruby.\n\n- https://github.com/jamescook/libui-ruby\n\nWhile libui-ruby uses [Ruby-FFI](https://github.com/ffi/ffi), this gem uses [Fiddle](https://github.com/ruby/fiddle).\n\n## License\n\n[MIT License](https://opensource.org/licenses/MIT).\n","funding_links":["https://ko-fi.com/kojix2"],"categories":["Ruby"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkojix2%2FLibUI","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkojix2%2FLibUI","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkojix2%2FLibUI/lists"}