libui 0.1.2.pre-arm64-darwin → 0.2.0.pre-arm64-darwin

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7d243a66ca518082287840d30e4cac62c5026e27177ec7720f59750596883c33
4
- data.tar.gz: 7fc8f0105d356297a55cbdf2a86cc4d78da8409e41289ddfd2140dc90f809ee9
3
+ metadata.gz: 2f9904359a2e38169abf117d6d9f35a4777dbbc6b7032c3b94d64a9b408ee16a
4
+ data.tar.gz: 30b8ef14230fea6c3c48f6f02ed9aca2fea615f115e95f91c0362d67daf9a07c
5
5
  SHA512:
6
- metadata.gz: b233d0e643425e4c42130a14bdd1776f18e8d83fb46f42c0a2445aead67be68fcd53db76c17daee602cf67593482add0d8d040a0828b1534042dffdab99fd33b
7
- data.tar.gz: 3ff3d96deb4acf85d0db77ae9b46debe9efa340777266a88bb825e1caab94ddd15b577c023a1eee100d57559d6ce0ea963726335df09896ac75a9cc256d5a33c
6
+ metadata.gz: db6a0f30fc19b99289cca38762c3917278eebfa226072fea18bccafc0107a7b661e41160c5ead4c6fea4b35f8f9ec8a49d72ac2d63b87857a5c648159c6844dc
7
+ data.tar.gz: f93b1aefc1b18d1cc5debbc6257fbb6b181ddbc18f53af1283fc2ef319f9291f6e856c3cb0d1d030f8d01132e2e4a9e98fea8f84a5648629b18d208b66074e3e
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2020 kojix2
3
+ Copyright (c) 2020-2025 kojix2
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,34 +1,47 @@
1
1
  # LibUI
2
2
 
3
- ![build](https://github.com/kojix2/libui/workflows/build/badge.svg)
3
+ [![test](https://github.com/kojix2/LibUI/actions/workflows/test.yml/badge.svg)](https://github.com/kojix2/LibUI/actions/workflows/test.yml)
4
4
  [![Gem Version](https://badge.fury.io/rb/libui.svg)](https://badge.fury.io/rb/libui)
5
5
  <a href="https://github.com/AndyObtiva/glimmer-dsl-libui"><img alt="glimmer-dsl-libui" src="https://github.com/AndyObtiva/glimmer/blob/master/images/glimmer-logo-hi-res.svg" width="50" height="50" align="right"></a>
6
+ [![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)
7
+ [![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)
6
8
 
7
- LibUI is a Ruby wrapper for libui and libui-ng.
9
+ LibUI is a Ruby wrapper for libui family.
8
10
 
9
11
  :rocket: [libui-ng](https://github.com/libui-ng/libui-ng) - A cross-platform portable GUI library
10
12
 
11
- :radio_button: [libui](https://github.com/andlabs/libui) - Original version by andlabs
13
+ :wrench: [libui-dev](https://github.com/petabyt/libui-dev) - Native UI library for C - with some extras
14
+
15
+ :radio_button: [libui](https://github.com/andlabs/libui) - Original version by andlabs.
12
16
 
13
17
  ## Installation
14
18
 
19
+ It is recommended to use libui-ng, via the --pre commandline flag:
20
+
21
+ ```sh
22
+ gem install libui --pre # libui-ng; this will fetch libui-0.1.3.pre-x86_64-linux.gem
23
+ ```
24
+
25
+ If for some reason you would like to install the slightly older libui-0.1.2.gem release, issue:
26
+
15
27
  ```sh
16
28
  gem install libui
17
29
  ```
18
30
 
19
- * The gem package contains the [official release](https://github.com/andlabs/libui/releases/tag/alpha4.1) of the libui shared library versions 4.1 for Windows, Mac, and Linux.
20
- * Namely `libui.dll`, `libui.dylib`, and `libui.so` (only 1.8MB in total).
21
- * No dependency
22
- * The libui gem uses the standard Ruby library [Fiddle](https://github.com/ruby/fiddle) to call C functions.
31
+ - The gem package includes the libui-ng shared library for Windows, Mac, and Linux.
32
+ - Namely `libui.dll`, `libui.dylib`, or `libui.so`.
33
+ - No dependencies required.
34
+ - The libui gem uses the standard Ruby library [Fiddle](https://github.com/ruby/fiddle) to call C functions.
23
35
 
24
- | Windows | Mac | Linux |
25
- |---------|-----|-------|
26
- |<img src="https://user-images.githubusercontent.com/5798442/103118046-900ea780-46b0-11eb-81fc-32626762e4df.png">|<img src="https://user-images.githubusercontent.com/5798442/103118059-99980f80-46b0-11eb-9d12-324ec4d297c9.png">|<img src="https://user-images.githubusercontent.com/5798442/103118068-a0bf1d80-46b0-11eb-8c5c-3bdcc3dcfb26.png">|
36
+ | Windows | Mac | Linux |
37
+ | ---------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------- |
38
+ | <img src="https://user-images.githubusercontent.com/5798442/103118046-900ea780-46b0-11eb-81fc-32626762e4df.png"> | <img src="https://user-images.githubusercontent.com/5798442/103118059-99980f80-46b0-11eb-9d12-324ec4d297c9.png"> | <img src="https://user-images.githubusercontent.com/5798442/103118068-a0bf1d80-46b0-11eb-8c5c-3bdcc3dcfb26.png"> |
27
39
 
28
- Note:
29
- * If you are using the 32-bit (x86) version of Ruby, you need to download the 32-bit (x86) native dll. See [Development](#development).
30
- * 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))
31
- * [Raspberry Pi](https://www.raspberrypi.com/) and other platform users will need to compile C libui. See [Development](#development).
40
+ Notes:
41
+
42
+ - 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.
43
+ - 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))
44
+ - Users with [Raspberry Pi](https://www.raspberrypi.com/) or other platforms will need to compile the C libui library. See the [Development](#development) section.
32
45
 
33
46
  ## Usage
34
47
 
@@ -61,30 +74,30 @@ UI.main
61
74
  UI.quit
62
75
  ```
63
76
 
64
- See [examples](https://github.com/kojix2/libui/tree/main/examples) directory.
77
+ For more examples, see the [examples](https://github.com/kojix2/libui/tree/main/examples) directory.
65
78
 
66
79
  ### General Rules
67
80
 
68
- Compared to original libui written in C,
81
+ Compared to the original libui library written in C:
69
82
 
70
- * The method names are snake_case.
71
- * If the last argument is nil, it can be omitted.
72
- * You can pass a block as a callback.
73
- * The block will be converted to a Proc object and added to the last argument.
74
- * Even in that case, it is possible to omit the last argument when nil.
83
+ - Method names use snake_case.
84
+ - The last argument can be omitted if it's nil.
85
+ - A block can be passed as a callback.
86
+ - The block will be converted to a Proc object and added as the last argument.
87
+ - The last argument can still be omitted when nil.
75
88
 
76
89
  You can use [the documentation for libui's Go bindings](https://pkg.go.dev/github.com/andlabs/ui) as a reference.
77
90
 
78
91
  ### DSLs for LibUI
79
92
 
80
- LibUI is intentionally not object-oriented because it is a thin Ruby wrapper (binding) for the procedural C libui library, so it mirrors its API structure.
93
+ LibUI is not object-oriented because it is a thin Ruby wrapper (binding) for the procedural C libui library, mirroring its API structure.
81
94
 
82
- It is recommended that you build actual applications using a DSL for LibUI because DSLs enable writing object-oriented code the Ruby way (instead of procedural code the C way):
95
+ To 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):
83
96
 
84
- * [Glimmer DSL for LibUI](https://github.com/AndyObtiva/glimmer-dsl-libui)
85
- * [libui_paradise](https://rubygems.org/gems/libui_paradise)
97
+ - [Glimmer DSL for LibUI](https://github.com/AndyObtiva/glimmer-dsl-libui)
98
+ - [libui_paradise](https://rubygems.org/gems/libui_paradise)
86
99
 
87
- ### How to use fiddle pointers?
100
+ ### Working with fiddle pointers
88
101
 
89
102
  ```ruby
90
103
  require 'libui'
@@ -92,7 +105,7 @@ UI = LibUI
92
105
  UI.init
93
106
  ```
94
107
 
95
- Convert a pointer to a string.
108
+ To convert a pointer to a string:
96
109
 
97
110
  ```ruby
98
111
  label = UI.new_label("Ruby")
@@ -100,12 +113,12 @@ p pointer = UI.label_text(label) # #<Fiddle::Pointer>
100
113
  p pointer.to_s # Ruby
101
114
  ```
102
115
 
103
- If you need to use C structs, you can do the following.
116
+ If you need to use C structs, you can do the following:
104
117
 
105
118
  ```ruby
106
119
  font_button = UI.new_font_button
107
120
 
108
- # Allocate memory
121
+ # Allocate memory
109
122
  font_descriptor = UI::FFI::FontDescriptor.malloc
110
123
  font_descriptor.to_ptr.free = Fiddle::RUBY_FREE
111
124
  # font_descriptor = UI::FFI::FontDescriptor.malloc(Fiddle::RUBY_FREE) # fiddle 1.0.1 or higher
@@ -120,26 +133,25 @@ UI.font_button_on_changed(font_button) do
120
133
  end
121
134
  ```
122
135
 
123
- * Callbacks
124
- * In Ruby/Fiddle, a C callback function is written as an object of
125
- `Fiddle::Closure::BlockCaller` or `Fiddle::Closure`.
126
- In this case, you need to be careful about Ruby's garbage collection.
127
- If the function object is collected, memory will be freed
128
- and a segmentation violation will occur when the callback is invoked.
136
+ - Callbacks
137
+ - In Ruby/Fiddle, a C callback function is written as an object of
138
+ `Fiddle::Closure::BlockCaller` or `Fiddle::Closure`.
139
+ 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.
129
140
 
130
141
  ```ruby
131
- # to a local variable to prevent it from being collected by GC.
142
+ # Assign to a local variable to prevent it from being collected by GC.
132
143
  handler.MouseEvent = (c1 = Fiddle::Closure::BlockCaller.new(0, [0]) {})
133
144
  handler.MouseCrossed = (c2 = Fiddle::Closure::BlockCaller.new(0, [0]) {})
134
145
  handler.DragBroken = (c3 = Fiddle::Closure::BlockCaller.new(0, [0]) {})
135
146
  ```
136
147
 
137
- ### How to create an executable (.exe) on Windows
148
+ ### Creating a Windows executable (.exe) with OCRA
149
+
150
+ OCRA (One-Click Ruby Application) builds Windows executables from Ruby source code.
138
151
 
139
- OCRA (One-Click Ruby Application) builds Windows executables from Ruby source code.
140
- * https://github.com/larsch/ocra/
152
+ - https://github.com/larsch/ocra/
141
153
 
142
- In order to build a exe with Ocra, include 3 DLLs from ruby_builtin_dlls folder:
154
+ To build an exe with Ocra, include 3 DLLs from the ruby_builtin_dlls folder:
143
155
 
144
156
  ```sh
145
157
  ocra examples/control_gallery.rb ^
@@ -149,7 +161,7 @@ ocra examples/control_gallery.rb ^
149
161
  --gem-all=fiddle ^
150
162
  ```
151
163
 
152
- Add additional options below if necessary.
164
+ Add additional options below if necessary:
153
165
 
154
166
  ```sh
155
167
  --window ^
@@ -162,59 +174,99 @@ Add additional options below if necessary.
162
174
 
163
175
  ## Development
164
176
 
165
- LibUI is not object-oriented, but it provides high portability with a minimal implementation.
166
-
167
177
  ```sh
168
178
  git clone https://github.com/kojix2/libui
169
179
  cd libui
170
180
  bundle install
171
- bundle exec rake vendor:default # download shared libraries for all platforms
181
+ bundle exec rake vendor:auto # vendor:build
172
182
  bundle exec rake test
173
183
  ```
174
184
 
175
- You can use the following rake tasks to download the shared library required for your platform.
185
+ ### Pre-built shared libraries for libui-ng
186
+
187
+ Use the following rake tasks to download the shared library required for your platform:
176
188
 
177
189
  `rake -T`
178
190
 
179
191
  ```
180
- rake vendor:kojix2:auto # Download kojix2 pre-build for your platform to vendor directory
181
- rake vendor:kojix2:mac # Download kojix2 pre-build for Mac to vendor directory
182
- rake vendor:kojix2:ubuntu_x64 # Download kojix2 pre-build for Ubuntu to vendor directory
183
- rake vendor:kojix2:windows_x64 # Download kojix2 pre-build for Windows to vendor directory
184
- rake vendor:kojix2:windows_x86 # Download kojix2 pre-build for Windows to vendor directory
185
- rake vendor:libui-ng:build[hash] # Build libui-ng latest master [commit hash]
186
- rake vendor:libui-ng:mac # Download latest dev build for Mac to vendor directory
187
- rake vendor:libui-ng:ubuntu_x64 # Download latest dev build for Ubuntu to vendor directory
192
+ rake vendor:build[hash] # Build libui-ng latest master [commit hash]
193
+ rake vendor:libui-ng:macos # Download latest official pre-build for Mac to vendor directory
194
+ rake vendor:libui-ng:ubuntu_x64 # Download latest official pre-build for Ubuntu to vendor directory
195
+ rake vendor:macos_arm64 # Download pre-build for Mac to vendor directory
196
+ rake vendor:macos_x64 # Download pre-build for Mac to vendor directory
197
+ rake vendor:raspbian_aarch64 # Download pre-build for Raspbian to vendor directory
198
+ rake vendor:ubuntu_x64 # Download pre-build for Ubuntu to vendor directory
199
+ rake vendor:windows_x64 # Download pre-build for Windows to vendor directory
200
+ rake vendor:windows_x86 # Download pre-build for Windows to vendor directory
188
201
  ```
189
202
 
190
- For example, If you are using a 32-bit (x86) version of Ruby on Windows, type `vendor:kojix2:windows_x86`.
203
+ For example, if you are using a 32-bit (x86) version of Ruby on Windows, type `vendor:windows_x86`.
204
+ These 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.
205
+
206
+ ### Using C libui compiled from source code
207
+
208
+ The following Rake task will compile libui-ng. meson or ninja is required.
191
209
 
192
- ### Use C libui compiled from source code
210
+ `bundle exec rake vendor:build`
193
211
 
194
- You can compile C libui from source code on your platform and tell ruby LibUI where to find the shared libraries. Set 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).
212
+ Alternatively, 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).
195
213
 
196
214
  Another simple approach is to replace the shared libraries in the gem vendor directory with the ones you have compiled.
197
215
 
216
+ ### Publishing gems
217
+
218
+ #### Automated Publishing
219
+
220
+ Push a version tag to automatically publish platform-specific gems:
221
+
222
+ ```sh
223
+ git tag v0.1.3
224
+ git push origin v0.1.3
225
+ ```
226
+
227
+ Requires `RUBYGEMS_API_KEY` repository secret with scoped API key.
228
+
229
+ #### Manual Publishing
230
+
231
+ ```sh
232
+ ls vendor # check the vendor directory
233
+ rm -rf pkg # remove previously built gems
234
+ rake build_platform # build gems
235
+
236
+ # Check the contents of the gem
237
+ find pkg -name *.gem -exec sh -c "echo; echo \# {}; tar -O -f {} -x data.tar.gz | tar zt" \;
238
+
239
+ rake release_platform # publish gems
240
+ ```
241
+
198
242
  ### libui or libui-ng
199
243
 
200
- * From version 0.1.X, we plan to support only libui-ng/libui-ng.
201
- * Version 0.0.X only supports andlabs/libui.
244
+ - From version 0.1.X, we plan to support only libui-ng/libui-ng.
245
+ - Version 0.0.X only supports andlabs/libui.
202
246
 
203
247
  ## Contributing
204
248
 
205
- Would you like to add your commits to libui?
206
- * Please feel free to send us your [pull requests](https://github.com/kojix2/libui/pulls).
207
- * Small corrections, such as typo fixes, are appreciated.
208
- * Did you find any bugs? Enter in the [issues](https://github.com/kojix2/LibUI/issues) section!
249
+ Would you like to contribute to LibUI?
250
+
251
+ - Please feel free to send us your [pull requests](https://github.com/kojix2/libui/pulls).
252
+ - Small corrections, such as typo fixes, are appreciated.
253
+ - Did you find any bugs? Submit them in the [issues](https://github.com/kojix2/LibUI/issues) section!
254
+
255
+ Do you need commit rights?
256
+
257
+ - 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.
258
+ - Many OSS projects become abandoned because only the founder has commit rights to the original repository.
259
+
260
+ Support libui-ng development
209
261
 
210
- I have seen many OSS projects abandoned. The main reason is that no one has the right to commit to the original repository, except the founder.
211
- Do you need commit rights to my repository? Do you want to get admin rights and take over the project? If so, please feel free to contact me @kojix2.
262
+ - Contributing to the development of libui-ng is a contribution to the entire libui community, including Ruby's LibUI.
263
+ - 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.
212
264
 
213
- ## Acknowledgement
265
+ ## Acknowledgements
214
266
 
215
267
  This project is inspired by libui-ruby.
216
268
 
217
- * https://github.com/jamescook/libui-ruby
269
+ - https://github.com/jamescook/libui-ruby
218
270
 
219
271
  While libui-ruby uses [Ruby-FFI](https://github.com/ffi/ffi), this gem uses [Fiddle](https://github.com/ruby/fiddle).
220
272
 
@@ -0,0 +1,10 @@
1
+ module LibUI
2
+ # base error class
3
+ class Error < StandardError; end
4
+
5
+ # LibUI shared library not found error
6
+ class LibraryNotFoundError < Error; end
7
+
8
+ # LibUI shared library load error
9
+ class LibraryLoadError < Error; end
10
+ end
data/lib/libui/ffi.rb CHANGED
@@ -1,15 +1,24 @@
1
1
  require 'fiddle/import'
2
2
  require_relative 'fiddle_patch'
3
+ require_relative 'error'
3
4
 
4
5
  module LibUI
6
+ class Error < StandardError; end
7
+
5
8
  module FFI
6
9
  extend Fiddle::Importer
7
10
  extend FiddlePatch
8
11
 
9
- begin
10
- dlload LibUI.ffi_lib
11
- rescue LoadError
12
- raise LoadError, 'Could not find libui shared library'
12
+ if LibUI.ffi_lib.nil?
13
+ raise LibraryNotFoundError, 'Could not find libui shared library. LibUI.ffi_lib is nil.'
14
+ elsif !File.exist?(LibUI.ffi_lib)
15
+ raise LibraryNotFoundError, "Could not find libui shared library: #{LibUI.ffi_lib}"
16
+ else
17
+ begin
18
+ dlload LibUI.ffi_lib
19
+ rescue LoadError
20
+ raise LibraryLoadError, "Could not load libui shared library: #{LibUI.ffi_lib}"
21
+ end
13
22
  end
14
23
 
15
24
  class << self
@@ -18,6 +27,8 @@ module LibUI
18
27
  def try_extern(signature, *opts)
19
28
  extern(signature, *opts)
20
29
  rescue StandardError => e
30
+ # Do not raise error when the function is not found
31
+ # because some functions may not be available on older versions of libui.
21
32
  warn "#{e.class.name}: #{e.message}"
22
33
  end
23
34
 
@@ -89,6 +100,9 @@ module LibUI
89
100
 
90
101
  try_extern 'char *uiWindowTitle(uiWindow *w)'
91
102
  try_extern 'void uiWindowSetTitle(uiWindow *w, const char *title)'
103
+ try_extern 'void uiWindowPosition(uiWindow *w, int *x, int *y)'
104
+ try_extern 'void uiWindowSetPosition(uiWindow *w, int x, int y)'
105
+ try_extern 'void uiWindowOnPositionChanged(uiWindow *w, void (*f)(uiWindow *sender, void *senderData), void *data)'
92
106
  try_extern 'void uiWindowContentSize(uiWindow *w, int *width, int *height)'
93
107
  try_extern 'void uiWindowSetContentSize(uiWindow *w, int width, int height)'
94
108
  try_extern 'int uiWindowFullscreen(uiWindow *w)'
@@ -1,4 +1,12 @@
1
1
  module LibUI
2
+ # This module overrides Fiddle's mtehods
3
+ # - Fiddle::Importer#extern
4
+ # - Fiddle::CParser#parse_signature
5
+ # Original methods are in
6
+ # - https://github.com/ruby/fiddle/blob/master/lib/fiddle/import.rb
7
+ # - https://github.com/ruby/fiddle/blob/master/lib/fiddle/cparser.rb
8
+ # These changes add the ability to parse the signatures of functions given as arguments.
9
+
2
10
  module FiddlePatch
3
11
  def parse_signature(signature, tymap = nil)
4
12
  tymap ||= {}
data/lib/libui/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module LibUI
2
- VERSION = '0.1.2.pre'
2
+ VERSION = '0.2.0.pre'
3
3
  end
data/lib/libui.rb CHANGED
@@ -1,21 +1,39 @@
1
1
  require_relative 'libui/version'
2
2
  require_relative 'libui/utils'
3
+ require_relative 'libui/error'
3
4
  require 'rbconfig'
4
5
 
5
6
  module LibUI
6
- class Error < StandardError; end
7
-
8
7
  class << self
9
8
  attr_accessor :ffi_lib
10
9
  end
11
10
 
12
- lib_name = "libui.#{RbConfig::CONFIG['SOEXT']}"
13
-
14
- self.ffi_lib = if ENV['LIBUIDIR'] && !ENV['LIBUIDIR'].empty?
15
- File.expand_path(lib_name, ENV['LIBUIDIR'])
16
- else
17
- File.expand_path("../vendor/#{lib_name}", __dir__)
18
- end
11
+ host_cpu = case RbConfig::CONFIG['host_cpu']
12
+ when /i\d86/
13
+ 'x86'
14
+ else
15
+ RbConfig::CONFIG['host_cpu']
16
+ end
17
+
18
+ lib_name = [
19
+ # For libui-ng shared libraries compiled with (rake vendor:build)
20
+ "libui.#{RbConfig::CONFIG['host_cpu']}.#{RbConfig::CONFIG['SOEXT']}",
21
+ # For libui-ng shared library downloaded from RubyGems.org
22
+ "libui.#{host_cpu}.#{RbConfig::CONFIG['SOEXT']}",
23
+ # For backward compatibility or manual compilation of libui-ng
24
+ "libui.#{RbConfig::CONFIG['SOEXT']}"
25
+ ]
26
+
27
+ self.ffi_lib = \
28
+ if ENV['LIBUIDIR'] && !ENV['LIBUIDIR'].empty?
29
+ lib_name.lazy
30
+ .map { |name| File.expand_path(name, ENV['LIBUIDIR']) }
31
+ .find { |path| File.exist?(path) }
32
+ else
33
+ lib_name.lazy
34
+ .map { |name| File.expand_path("../vendor/#{name}", __dir__) }
35
+ .find { |path| File.exist?(path) }
36
+ end
19
37
 
20
38
  require_relative 'libui/ffi'
21
39
  require_relative 'libui/libui_base'
@@ -35,6 +53,25 @@ module LibUI
35
53
  warn UI.free_init_error(init)
36
54
  end
37
55
 
56
+ # Gets the window position.
57
+ # Coordinates are measured from the top left corner of the screen.
58
+ # @param w [Fiddle::Pointer] Pointer of uiWindow instance.
59
+ # @return [Array] position of the window. [x, y]
60
+ # @note This method may return inaccurate or dummy values on Unix platforms.
61
+
62
+ def window_position(w)
63
+ x_ptr = Fiddle::Pointer.malloc(Fiddle::SIZEOF_INT, Fiddle::RUBY_FREE)
64
+ y_ptr = Fiddle::Pointer.malloc(Fiddle::SIZEOF_INT, Fiddle::RUBY_FREE)
65
+ super(w, x_ptr, y_ptr)
66
+ x = x_ptr[0, Fiddle::SIZEOF_INT].unpack1('i*')
67
+ y = y_ptr[0, Fiddle::SIZEOF_INT].unpack1('i*')
68
+ [x, y]
69
+ end
70
+
71
+ # FIXME: This is a workaround for a old version of Fiddle.
72
+ # Fiddle 1.1.2 and above should be able to handle one character string.
73
+ # See https://github.com/ruby/fiddle/issues/96
74
+
38
75
  def open_type_features_add(otf, a, b, c, d, value)
39
76
  a, b, c, d = [a, b, c, d].map { |s| s.is_a?(String) ? s.ord : s }
40
77
  super(otf, a, b, c, d, value)
data/vendor/README.md CHANGED
@@ -68,6 +68,16 @@ For the sake of completeness, I should note that the default value of `--layout`
68
68
 
69
69
  Backends other than `ninja` should work, but are untested by me.
70
70
 
71
+ ## Testing
72
+
73
+ ### Automated Unit Tests
74
+
75
+ Run the included unit tests via `meson test -C build`. Alternatively you can also run the `unit` executable manually.
76
+
77
+ ### Manual Testing Suite
78
+
79
+ Run the manual quality assurance test suite via `qa` and follow the instructions laid out within.
80
+
71
81
  ## Installation
72
82
 
73
83
  Meson also supports installing from source; if you use Ninja, just do
@@ -82,9 +92,13 @@ When running `meson`, the `--prefix` option will set the installation prefix. [T
82
92
 
83
93
  Can be built from AUR: https://aur.archlinux.org/packages/libui-ng-git/
84
94
 
85
- ## Documentation
95
+ ## Documentation [WIP]
96
+
97
+ [API](https://libui-ng.github.io/libui-ng/), check the [modules](https://libui-ng.github.io/libui-ng/modules.html) section for an overview of (nearly all) uiControls.
98
+
99
+ Consult the `ui.h` comments for the uiControls missing in the docs.
86
100
 
87
- Needs to be written. Consult `ui.h` and the examples for details for now.
101
+ Check the `examples` directory for fully fledged examples. Check out the `tests` directory and subdirectories for more real world usage.
88
102
 
89
103
  ## Language Bindings
90
104
 
@@ -96,7 +110,7 @@ Language | Bindings
96
110
  --- | ---
97
111
  C++ | [libui-cpp](https://github.com/billyquith/libui-cpp), [cpp-libui-qtlike](https://github.com/aoloe/cpp-libui-qtlike)
98
112
  C# / .NET Framework | [LibUI.Binding](https://github.com/NattyNarwhal/LibUI.Binding)
99
- C# / .NET Core | [DevZH.UI](https://github.com/noliar/DevZH.UI), [SharpUI](https://github.com/benpye/sharpui/), [SimplexiDev.UI](https://github.com/simplexidev/sdfx)
113
+ C# / .NET Core | [DevZH.UI](https://github.com/noliar/DevZH.UI), [SharpUI](https://github.com/benpye/sharpui/)
100
114
  CHICKEN Scheme | [wasamasa/libui](https://github.com/wasamasa/libui)
101
115
  Common Lisp | [jinwoo/cl-ui](https://github.com/jinwoo/cl-ui)
102
116
  Crystal | [libui.cr](https://github.com/Fusion/libui.cr), [hedron](https://github.com/Qwerp-Derp/hedron), [iu](https://github.com/grkek/iu)
@@ -109,13 +123,13 @@ JavaScript/Node.js | [libui-node](https://github.com/parro-it/libui-node), [libu
109
123
  Julia | [Libui.jl](https://github.com/joa-quim/Libui.jl)
110
124
  Kotlin | [kotlin-libui](https://github.com/msink/kotlin-libui)
111
125
  Lua | [libuilua](https://github.com/zevv/libuilua), [libui-lua](https://github.com/mdombroski/libui-lua), [lui](http://tset.de/lui/index.html), [lui](https://github.com/zhaozg/lui)
112
- Nim | [ui](https://github.com/nim-lang/ui)
126
+ Nim | [ui](https://github.com/nim-lang/ui), [uing](https://github.com/neroist/uing)
113
127
  Perl6 | [perl6-libui](https://github.com/Garland-g/perl6-libui)
114
- PHP | [ui](https://github.com/krakjoe/ui)
128
+ PHP | [ui](https://github.com/krakjoe/ui), [Ardillo](https://github.com/ardillo-php/ext)
115
129
  Python | [pylibui](https://github.com/joaoventura/pylibui)
116
130
  Ring | [RingLibui](https://github.com/ring-lang/ring/tree/master/extensions/ringlibui)
117
131
  Ruby | [libui-ruby](https://github.com/jamescook/libui-ruby), [LibUI](https://github.com/kojix2/libui), [Glimmer DSL for LibUI](https://github.com/AndyObtiva/glimmer-dsl-libui)
118
- Rust | [libui-ng-sys](https://github.com/norepimorphism/libui-ng-sys), [boing](https://github.com/norepimorphism/boing), [libui-rs](https://github.com/rust-native-ui/libui-rs)
132
+ Rust | [libui-ng-sys](https://github.com/norepimorphism/libui-ng-sys), [boing](https://github.com/norepimorphism/boing), [libui-rs](https://github.com/rust-native-ui/libui-rs), [libui](https://github.com/libui-rs/libui)
119
133
  Scala | [scalaui](https://github.com/lolgab/scalaui)
120
134
  Swift | [libui-swift](https://github.com/sclukey/libui-swift)
121
135
 
Binary file
metadata CHANGED
@@ -1,16 +1,30 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: libui
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2.pre
4
+ version: 0.2.0.pre
5
5
  platform: arm64-darwin
6
6
  authors:
7
7
  - kojix2
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-05 00:00:00.000000000 Z
12
- dependencies: []
13
- description:
11
+ date: 2025-08-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: fiddle
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description:
14
28
  email:
15
29
  - 2xijok@gmail.com
16
30
  executables: []
@@ -20,6 +34,7 @@ files:
20
34
  - LICENSE.txt
21
35
  - README.md
22
36
  - lib/libui.rb
37
+ - lib/libui/error.rb
23
38
  - lib/libui/ffi.rb
24
39
  - lib/libui/fiddle_patch.rb
25
40
  - lib/libui/libui_base.rb
@@ -27,12 +42,12 @@ files:
27
42
  - lib/libui/version.rb
28
43
  - vendor/LICENSE.md
29
44
  - vendor/README.md
30
- - vendor/libui.dylib
45
+ - vendor/libui.arm64.dylib
31
46
  homepage: https://github.com/kojix2/libui
32
47
  licenses:
33
48
  - MIT
34
49
  metadata: {}
35
- post_install_message:
50
+ post_install_message:
36
51
  rdoc_options: []
37
52
  require_paths:
38
53
  - lib
@@ -40,15 +55,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
40
55
  requirements:
41
56
  - - ">="
42
57
  - !ruby/object:Gem::Version
43
- version: '2.5'
58
+ version: '2.6'
44
59
  required_rubygems_version: !ruby/object:Gem::Requirement
45
60
  requirements:
46
- - - ">"
61
+ - - ">="
47
62
  - !ruby/object:Gem::Version
48
- version: 1.3.1
63
+ version: '0'
49
64
  requirements: []
50
- rubygems_version: 3.4.6
51
- signing_key:
65
+ rubygems_version: 3.5.22
66
+ signing_key:
52
67
  specification_version: 4
53
68
  summary: Ruby bindings to libui
54
69
  test_files: []
data/vendor/libui.dylib DELETED
Binary file