libui 0.1.2.pre-arm64-darwin → 0.2.0-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: 8260a14f6b52f63fc4e436bdd22a8aff20a797b2566b0b50fbcf6afe5e81d6ac
4
+ data.tar.gz: 06c8a83b35a689befc754471ddc3b0458432db5cfae224043807d06e546dc075
5
5
  SHA512:
6
- metadata.gz: b233d0e643425e4c42130a14bdd1776f18e8d83fb46f42c0a2445aead67be68fcd53db76c17daee602cf67593482add0d8d040a0828b1534042dffdab99fd33b
7
- data.tar.gz: 3ff3d96deb4acf85d0db77ae9b46debe9efa340777266a88bb825e1caab94ddd15b577c023a1eee100d57559d6ce0ea963726335df09896ac75a9cc256d5a33c
6
+ metadata.gz: 957fdfe74e7db5f84054af4c54bbe057c5d15681c7aa0cb033b938f42f0add05efd674b8fab39c2a1669490f4d45b4b58da90b2bb4eab70a46c341bcd17e4f9b
7
+ data.tar.gz: fb9d0618abcd661a57bbbda176c277fb59d1ba8ad44535d221dcd8ecb5b74653f55c0699e0d0dd0dab3cc9b281233bef6e946d0e8bd314b226dbab00cde355bb
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.
35
+
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"> |
23
39
 
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">|
40
+ Notes:
27
41
 
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).
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
 
@@ -49,9 +62,8 @@ end
49
62
 
50
63
  UI.window_on_closing(main_window) do
51
64
  puts 'Bye Bye'
52
- UI.control_destroy(main_window)
53
65
  UI.quit
54
- 0
66
+ 1
55
67
  end
56
68
 
57
69
  UI.window_set_child(main_window, button)
@@ -61,30 +73,30 @@ UI.main
61
73
  UI.quit
62
74
  ```
63
75
 
64
- See [examples](https://github.com/kojix2/libui/tree/main/examples) directory.
76
+ For more examples, see the [examples](https://github.com/kojix2/libui/tree/main/examples) directory.
65
77
 
66
78
  ### General Rules
67
79
 
68
- Compared to original libui written in C,
80
+ Compared to the original libui library written in C:
69
81
 
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.
82
+ - Method names use snake_case.
83
+ - The last argument can be omitted if it's nil.
84
+ - A block can be passed as a callback.
85
+ - The block will be converted to a Proc object and added as the last argument.
86
+ - The last argument can still be omitted when nil.
75
87
 
76
88
  You can use [the documentation for libui's Go bindings](https://pkg.go.dev/github.com/andlabs/ui) as a reference.
77
89
 
78
90
  ### DSLs for LibUI
79
91
 
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.
92
+ LibUI is not object-oriented because it is a thin Ruby wrapper (binding) for the procedural C libui library, mirroring its API structure.
81
93
 
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):
94
+ 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
95
 
84
- * [Glimmer DSL for LibUI](https://github.com/AndyObtiva/glimmer-dsl-libui)
85
- * [libui_paradise](https://rubygems.org/gems/libui_paradise)
96
+ - [Glimmer DSL for LibUI](https://github.com/AndyObtiva/glimmer-dsl-libui)
97
+ - [libui_paradise](https://rubygems.org/gems/libui_paradise)
86
98
 
87
- ### How to use fiddle pointers?
99
+ ### Working with fiddle pointers
88
100
 
89
101
  ```ruby
90
102
  require 'libui'
@@ -92,7 +104,7 @@ UI = LibUI
92
104
  UI.init
93
105
  ```
94
106
 
95
- Convert a pointer to a string.
107
+ To convert a pointer to a string:
96
108
 
97
109
  ```ruby
98
110
  label = UI.new_label("Ruby")
@@ -100,12 +112,12 @@ p pointer = UI.label_text(label) # #<Fiddle::Pointer>
100
112
  p pointer.to_s # Ruby
101
113
  ```
102
114
 
103
- If you need to use C structs, you can do the following.
115
+ If you need to use C structs, you can do the following:
104
116
 
105
117
  ```ruby
106
118
  font_button = UI.new_font_button
107
119
 
108
- # Allocate memory
120
+ # Allocate memory
109
121
  font_descriptor = UI::FFI::FontDescriptor.malloc
110
122
  font_descriptor.to_ptr.free = Fiddle::RUBY_FREE
111
123
  # font_descriptor = UI::FFI::FontDescriptor.malloc(Fiddle::RUBY_FREE) # fiddle 1.0.1 or higher
@@ -120,26 +132,25 @@ UI.font_button_on_changed(font_button) do
120
132
  end
121
133
  ```
122
134
 
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.
135
+ - Callbacks
136
+ - In Ruby/Fiddle, a C callback function is written as an object of
137
+ `Fiddle::Closure::BlockCaller` or `Fiddle::Closure`.
138
+ 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
139
 
130
140
  ```ruby
131
- # to a local variable to prevent it from being collected by GC.
141
+ # Assign to a local variable to prevent it from being collected by GC.
132
142
  handler.MouseEvent = (c1 = Fiddle::Closure::BlockCaller.new(0, [0]) {})
133
143
  handler.MouseCrossed = (c2 = Fiddle::Closure::BlockCaller.new(0, [0]) {})
134
144
  handler.DragBroken = (c3 = Fiddle::Closure::BlockCaller.new(0, [0]) {})
135
145
  ```
136
146
 
137
- ### How to create an executable (.exe) on Windows
147
+ ### Creating a Windows executable (.exe) with OCRA
138
148
 
139
- OCRA (One-Click Ruby Application) builds Windows executables from Ruby source code.
140
- * https://github.com/larsch/ocra/
149
+ OCRA (One-Click Ruby Application) builds Windows executables from Ruby source code.
141
150
 
142
- In order to build a exe with Ocra, include 3 DLLs from ruby_builtin_dlls folder:
151
+ - https://github.com/larsch/ocra/
152
+
153
+ To build an exe with Ocra, include 3 DLLs from the ruby_builtin_dlls folder:
143
154
 
144
155
  ```sh
145
156
  ocra examples/control_gallery.rb ^
@@ -149,7 +160,7 @@ ocra examples/control_gallery.rb ^
149
160
  --gem-all=fiddle ^
150
161
  ```
151
162
 
152
- Add additional options below if necessary.
163
+ Add additional options below if necessary:
153
164
 
154
165
  ```sh
155
166
  --window ^
@@ -162,59 +173,86 @@ Add additional options below if necessary.
162
173
 
163
174
  ## Development
164
175
 
165
- LibUI is not object-oriented, but it provides high portability with a minimal implementation.
166
-
167
176
  ```sh
168
177
  git clone https://github.com/kojix2/libui
169
178
  cd libui
170
179
  bundle install
171
- bundle exec rake vendor:default # download shared libraries for all platforms
180
+ bundle exec rake vendor:auto
172
181
  bundle exec rake test
173
182
  ```
174
183
 
175
- You can use the following rake tasks to download the shared library required for your platform.
184
+ ### Pre-built shared libraries for libui-ng
176
185
 
177
- `rake -T`
186
+ Download pre-built libui-ng shared libraries (per your current platform):
178
187
 
188
+ ```sh
189
+ bundle exec rake vendor:auto
190
+ ```
191
+
192
+ Clean downloaded vendor files (keeps `vendor/{LICENSE,README}.md`):
193
+
194
+ ```sh
195
+ bundle exec rake vendor:clean
179
196
  ```
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
197
+
198
+ ### Using your own libui build
199
+
200
+ If you build libui-ng yourself, set `LIBUIDIR` to the directory containing the compiled `.so/.dylib/.dll` so LibUI can load it. You may also replace files under `vendor/` with your build if preferred. See [#46](https://github.com/kojix2/LibUI/issues/46#issuecomment-1041575792).
201
+
202
+ ### Publishing gems
203
+
204
+ #### Automated Publishing
205
+
206
+ Push a version tag to automatically publish platform-specific gems:
207
+
208
+ ```sh
209
+ git tag v0.1.3
210
+ git push origin v0.1.3
188
211
  ```
189
212
 
190
- For example, If you are using a 32-bit (x86) version of Ruby on Windows, type `vendor:kojix2:windows_x86`.
213
+ Requires `RUBYGEMS_API_KEY` repository secret with scoped API key.
191
214
 
192
- ### Use C libui compiled from source code
215
+ #### Manual Publishing
193
216
 
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).
217
+ ```sh
218
+ ls vendor # check the vendor directory
219
+ rm -rf pkg # remove previously built gems
220
+ rake build_platform # build gems
221
+
222
+ # Check the contents of the gem
223
+ find pkg -name *.gem -exec sh -c "echo; echo \# {}; tar -O -f {} -x data.tar.gz | tar zt" \;
195
224
 
196
- Another simple approach is to replace the shared libraries in the gem vendor directory with the ones you have compiled.
225
+ rake release_platform # publish gems
226
+ ```
197
227
 
198
228
  ### libui or libui-ng
199
229
 
200
- * From version 0.1.X, we plan to support only libui-ng/libui-ng.
201
- * Version 0.0.X only supports andlabs/libui.
230
+ - From version 0.1.X, we plan to support only libui-ng/libui-ng.
231
+ - Version 0.0.X only supports andlabs/libui.
202
232
 
203
233
  ## Contributing
204
234
 
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!
235
+ Would you like to contribute to LibUI?
236
+
237
+ - Please feel free to send us your [pull requests](https://github.com/kojix2/libui/pulls).
238
+ - Small corrections, such as typo fixes, are appreciated.
239
+ - Did you find any bugs? Submit them in the [issues](https://github.com/kojix2/LibUI/issues) section!
240
+
241
+ Do you need commit rights?
242
+
243
+ - 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.
244
+ - Many OSS projects become abandoned because only the founder has commit rights to the original repository.
245
+
246
+ Support libui-ng development
209
247
 
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.
248
+ - Contributing to the development of libui-ng is a contribution to the entire libui community, including Ruby's LibUI.
249
+ - 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
250
 
213
- ## Acknowledgement
251
+ ## Acknowledgements
214
252
 
215
253
  This project is inspired by libui-ruby.
216
254
 
217
- * https://github.com/jamescook/libui-ruby
255
+ - https://github.com/jamescook/libui-ruby
218
256
 
219
257
  While libui-ruby uses [Ruby-FFI](https://github.com/ffi/ffi), this gem uses [Fiddle](https://github.com/ruby/fiddle).
220
258
 
@@ -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,23 @@
1
1
  require 'fiddle/import'
2
2
  require_relative 'fiddle_patch'
3
+ require_relative 'error'
3
4
 
4
5
  module LibUI
6
+
5
7
  module FFI
6
8
  extend Fiddle::Importer
7
9
  extend FiddlePatch
8
10
 
9
- begin
10
- dlload LibUI.ffi_lib
11
- rescue LoadError
12
- raise LoadError, 'Could not find libui shared library'
11
+ if LibUI.ffi_lib.nil?
12
+ raise LibraryNotFoundError, 'Could not find libui shared library. LibUI.ffi_lib is nil.'
13
+ elsif !File.exist?(LibUI.ffi_lib)
14
+ raise LibraryNotFoundError, "Could not find libui shared library: #{LibUI.ffi_lib}"
15
+ else
16
+ begin
17
+ dlload LibUI.ffi_lib
18
+ rescue LoadError
19
+ raise LibraryLoadError, "Could not load libui shared library: #{LibUI.ffi_lib}"
20
+ end
13
21
  end
14
22
 
15
23
  class << self
@@ -18,6 +26,8 @@ module LibUI
18
26
  def try_extern(signature, *opts)
19
27
  extern(signature, *opts)
20
28
  rescue StandardError => e
29
+ # Do not raise error when the function is not found
30
+ # because some functions may not be available on older versions of libui.
21
31
  warn "#{e.class.name}: #{e.message}"
22
32
  end
23
33
 
@@ -27,6 +37,7 @@ module LibUI
27
37
  end
28
38
 
29
39
  typealias('uint32_t', 'unsigned int')
40
+ typealias('uint64_t', 'unsigned long long')
30
41
 
31
42
  InitOptions = struct [
32
43
  'size_t Size'
@@ -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 ||= {}
@@ -8,7 +16,7 @@ module LibUI
8
16
  when /^([\w\*\s]+[*\s])(\w+)\((.*?)\);?$/
9
17
  [parse_ctype(Regexp.last_match(1).strip, tymap), Regexp.last_match(2), Regexp.last_match(3)]
10
18
  else
11
- raise("can't parserake the function prototype: #{signature}")
19
+ raise("can't parse the function prototype: #{signature}")
12
20
  end
13
21
  symname = func
14
22
  callback_argument_types = {} # Added
@@ -25,11 +25,13 @@ module LibUI
25
25
  # Protect from GC
26
26
  # by giving the owner object a reference to the callback.
27
27
  # See https://github.com/kojix2/LibUI/issues/8
28
- owner = if idx == 0 or # UI.queue_main{}
29
- owner.frozen? # UI.timer(100) {}
30
- LibUIBase # or UI is better?
28
+ receiver = args.first
29
+ owner = if idx == 0 || # UI.queue_main{}
30
+ receiver.nil? ||
31
+ (receiver.respond_to?(:frozen?) && receiver.frozen?) # UI.timer(100) {}
32
+ LibUIBase # keep a reference on an internal module to avoid GC
31
33
  else
32
- args[0] # receiver
34
+ receiver # receiver object holds the callback
33
35
  end
34
36
  if owner.instance_variable_defined?(:@callbacks)
35
37
  owner.instance_variable_get(:@callbacks) << callback
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'
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'
@@ -24,17 +42,42 @@ module LibUI
24
42
 
25
43
  class << self
26
44
  def init(opt = nil)
45
+ # Allocate uiInitOptions if not provided
27
46
  unless opt
28
47
  opt = FFI::InitOptions.malloc
29
48
  opt.to_ptr.free = Fiddle::RUBY_FREE
49
+ opt.Size = FFI::InitOptions.size
30
50
  end
31
- i = super(opt)
32
- return if i.size.zero?
33
51
 
34
- warn 'error'
35
- warn UI.free_init_error(init)
52
+ err_ptr = super(opt) # uiInit returns const char* error or NULL on success
53
+ return nil if err_ptr.null?
54
+
55
+ # Convert C string to Ruby string and free the error string per API contract
56
+ err_msg = err_ptr.to_s
57
+ free_init_error(err_ptr)
58
+ warn err_msg
59
+ nil
36
60
  end
37
61
 
62
+ # Gets the window position.
63
+ # Coordinates are measured from the top left corner of the screen.
64
+ # @param w [Fiddle::Pointer] Pointer of uiWindow instance.
65
+ # @return [Array] position of the window. [x, y]
66
+ # @note This method may return inaccurate or dummy values on Unix platforms.
67
+
68
+ def window_position(w)
69
+ x_ptr = Fiddle::Pointer.malloc(Fiddle::SIZEOF_INT, Fiddle::RUBY_FREE)
70
+ y_ptr = Fiddle::Pointer.malloc(Fiddle::SIZEOF_INT, Fiddle::RUBY_FREE)
71
+ super(w, x_ptr, y_ptr)
72
+ x = x_ptr[0, Fiddle::SIZEOF_INT].unpack1('i*')
73
+ y = y_ptr[0, Fiddle::SIZEOF_INT].unpack1('i*')
74
+ [x, y]
75
+ end
76
+
77
+ # FIXME: This is a workaround for a old version of Fiddle.
78
+ # Fiddle 1.1.2 and above should be able to handle one character string.
79
+ # See https://github.com/ruby/fiddle/issues/96
80
+
38
81
  def open_type_features_add(otf, a, b, c, d, value)
39
82
  a, b, c, d = [a, b, c, d].map { |s| s.is_a?(String) ? s.ord : s }
40
83
  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,28 @@
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
5
5
  platform: arm64-darwin
6
6
  authors:
7
7
  - kojix2
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2023-03-05 00:00:00.000000000 Z
12
- dependencies: []
13
- description:
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: fiddle
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '0'
14
26
  email:
15
27
  - 2xijok@gmail.com
16
28
  executables: []
@@ -20,6 +32,7 @@ files:
20
32
  - LICENSE.txt
21
33
  - README.md
22
34
  - lib/libui.rb
35
+ - lib/libui/error.rb
23
36
  - lib/libui/ffi.rb
24
37
  - lib/libui/fiddle_patch.rb
25
38
  - lib/libui/libui_base.rb
@@ -27,12 +40,11 @@ files:
27
40
  - lib/libui/version.rb
28
41
  - vendor/LICENSE.md
29
42
  - vendor/README.md
30
- - vendor/libui.dylib
43
+ - vendor/libui.arm64.dylib
31
44
  homepage: https://github.com/kojix2/libui
32
45
  licenses:
33
46
  - MIT
34
47
  metadata: {}
35
- post_install_message:
36
48
  rdoc_options: []
37
49
  require_paths:
38
50
  - lib
@@ -40,15 +52,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
40
52
  requirements:
41
53
  - - ">="
42
54
  - !ruby/object:Gem::Version
43
- version: '2.5'
55
+ version: '2.6'
44
56
  required_rubygems_version: !ruby/object:Gem::Requirement
45
57
  requirements:
46
- - - ">"
58
+ - - ">="
47
59
  - !ruby/object:Gem::Version
48
- version: 1.3.1
60
+ version: '0'
49
61
  requirements: []
50
- rubygems_version: 3.4.6
51
- signing_key:
62
+ rubygems_version: 3.6.9
52
63
  specification_version: 4
53
64
  summary: Ruby bindings to libui
54
65
  test_files: []
data/vendor/libui.dylib DELETED
Binary file