libui 0.1.3.pre-x86_64-linux → 0.2.0-x86_64-linux

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: f068fcf26facd76bd1f56faeca3ac4bea3b11e872befe05447c7ecdbe33cd1c5
4
- data.tar.gz: 9911c9a3488c9e0a3c50a36bedba124171a8ce6c2549fb983eee35e8f56955b5
3
+ metadata.gz: 6a4a93bc8fdec0c9c4e2587bb2aa99c0ac11d54e34ae9956e64a9a841a39cac5
4
+ data.tar.gz: 9b4caca40127dea74380e48afa011f0162e2169cdba6a4037d52ad1e38247924
5
5
  SHA512:
6
- metadata.gz: 7d07e4e85f62e610d25203f3eb2c99431eac61b021f1872597b9bbba14d905d32f879598b3b9f5d0582ba73904ca5e7a27a7e8309c671cfa1e8c6605f3810fa4
7
- data.tar.gz: b4195a2387afaf719b34d33742650a147041e7179ddbe71c4d926c41fb641c27eaecd8ad83a4f7da9d002fa3fd7b219fa035132dc3255512234d0a90d350f579
6
+ metadata.gz: 9b39de93bfeeb054f86237741ea0b072aead99d1835156fb3f4e18e73f17bbb6e2c8a2592cce0adc31f00c4c1c28d85d31c7d1564a36f074c7bd64664ce39298
7
+ data.tar.gz: 333a266fcec1f2108cf7443cbcc56b9f0f86d2620886bdbed5e4bd874e6b18c22a4f493c375da1f9afc38c0595baf1ee32bcc3638f6b1d6780d5e71f868ee15f
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
@@ -4,21 +4,32 @@
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
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)
7
8
 
8
- LibUI is a Ruby wrapper for libui and libui-ng.
9
+ LibUI is a Ruby wrapper for libui family.
9
10
 
10
11
  :rocket: [libui-ng](https://github.com/libui-ng/libui-ng) - A cross-platform portable GUI library
11
12
 
13
+ :wrench: [libui-dev](https://github.com/petabyt/libui-dev) - Native UI library for C - with some extras
14
+
12
15
  :radio_button: [libui](https://github.com/andlabs/libui) - Original version by andlabs.
13
16
 
14
17
  ## Installation
15
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
+
16
27
  ```sh
17
28
  gem install libui
18
29
  ```
19
30
 
20
- - The gem package includes the [official release](https://github.com/andlabs/libui/releases/tag/alpha4.1) of the libui shared library version 4.1 for Windows, Mac, and Linux.
21
- - Namely `libui.dll`, `libui.dylib`, and `libui.so` (only 1.8MB in total).
31
+ - The gem package includes the libui-ng shared library for Windows, Mac, and Linux.
32
+ - Namely `libui.dll`, `libui.dylib`, or `libui.so`.
22
33
  - No dependencies required.
23
34
  - The libui gem uses the standard Ruby library [Fiddle](https://github.com/ruby/fiddle) to call C functions.
24
35
 
@@ -51,9 +62,8 @@ end
51
62
 
52
63
  UI.window_on_closing(main_window) do
53
64
  puts 'Bye Bye'
54
- UI.control_destroy(main_window)
55
65
  UI.quit
56
- 0
66
+ 1
57
67
  end
58
68
 
59
69
  UI.window_set_child(main_window, button)
@@ -167,42 +177,42 @@ Add additional options below if necessary:
167
177
  git clone https://github.com/kojix2/libui
168
178
  cd libui
169
179
  bundle install
170
- bundle exec rake vendor:auto # vendor:build
180
+ bundle exec rake vendor:auto
171
181
  bundle exec rake test
172
182
  ```
173
183
 
174
184
  ### Pre-built shared libraries for libui-ng
175
185
 
176
- Use the following rake tasks to download the shared library required for your platform:
177
-
178
- `rake -T`
186
+ Download pre-built libui-ng shared libraries (per your current platform):
179
187
 
188
+ ```sh
189
+ bundle exec rake vendor:auto
180
190
  ```
181
- rake vendor:build[hash] # Build libui-ng latest master [commit hash]
182
- rake vendor:libui-ng:macos # Download latest official pre-build for Mac to vendor directory
183
- rake vendor:libui-ng:ubuntu_x64 # Download latest official pre-build for Ubuntu to vendor directory
184
- rake vendor:macos_arm64 # Download pre-build for Mac to vendor directory
185
- rake vendor:macos_x64 # Download pre-build for Mac to vendor directory
186
- rake vendor:raspbian_aarch64 # Download pre-build for Raspbian to vendor directory
187
- rake vendor:ubuntu_x64 # Download pre-build for Ubuntu to vendor directory
188
- rake vendor:windows_x64 # Download pre-build for Windows to vendor directory
189
- rake vendor:windows_x86 # Download pre-build for Windows to vendor directory
191
+
192
+ Clean downloaded vendor files (keeps `vendor/{LICENSE,README}.md`):
193
+
194
+ ```sh
195
+ bundle exec rake vendor:clean
190
196
  ```
191
197
 
192
- For example, if you are using a 32-bit (x86) version of Ruby on Windows, type `vendor:windows_x86`.
193
- 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.
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).
194
201
 
195
- ### Using C libui compiled from source code
202
+ ### Publishing gems
196
203
 
197
- The following Rake task will compile libui-ng. meson or ninja is required.
204
+ #### Automated Publishing
198
205
 
199
- `bundle exec rake vendor:build`
206
+ Push a version tag to automatically publish platform-specific gems:
200
207
 
201
- 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).
208
+ ```sh
209
+ git tag v0.1.3
210
+ git push origin v0.1.3
211
+ ```
202
212
 
203
- Another simple approach is to replace the shared libraries in the gem vendor directory with the ones you have compiled.
213
+ Requires `RUBYGEMS_API_KEY` repository secret with scoped API key.
204
214
 
205
- ### Publishing gems
215
+ #### Manual Publishing
206
216
 
207
217
  ```sh
208
218
  ls vendor # check the vendor directory
@@ -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'
@@ -16,7 +16,7 @@ module LibUI
16
16
  when /^([\w\*\s]+[*\s])(\w+)\((.*?)\);?$/
17
17
  [parse_ctype(Regexp.last_match(1).strip, tymap), Regexp.last_match(2), Regexp.last_match(3)]
18
18
  else
19
- raise("can't parserake the function prototype: #{signature}")
19
+ raise("can't parse the function prototype: #{signature}")
20
20
  end
21
21
  symname = func
22
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.3.pre'
2
+ VERSION = '0.2.0'
3
3
  end
data/lib/libui.rb CHANGED
@@ -1,16 +1,26 @@
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
 
11
+ host_cpu = case RbConfig::CONFIG['host_cpu']
12
+ when /i\d86/
13
+ 'x86'
14
+ else
15
+ RbConfig::CONFIG['host_cpu']
16
+ end
17
+
12
18
  lib_name = [
19
+ # For libui-ng shared libraries compiled with (rake vendor:build)
13
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
14
24
  "libui.#{RbConfig::CONFIG['SOEXT']}"
15
25
  ]
16
26
 
@@ -32,15 +42,21 @@ module LibUI
32
42
 
33
43
  class << self
34
44
  def init(opt = nil)
45
+ # Allocate uiInitOptions if not provided
35
46
  unless opt
36
47
  opt = FFI::InitOptions.malloc
37
48
  opt.to_ptr.free = Fiddle::RUBY_FREE
49
+ opt.Size = FFI::InitOptions.size
38
50
  end
39
- i = super(opt)
40
- return if i.size.zero?
41
51
 
42
- warn 'error'
43
- 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
44
60
  end
45
61
 
46
62
  # Gets the window position.
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.3.pre
4
+ version: 0.2.0
5
5
  platform: x86_64-linux
6
6
  authors:
7
7
  - kojix2
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2023-11-09 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
@@ -32,7 +45,6 @@ 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
@@ -43,12 +55,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
43
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.14
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: []