libui 0.2.0.pre-arm64-darwin → 0.2.2-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: 2f9904359a2e38169abf117d6d9f35a4777dbbc6b7032c3b94d64a9b408ee16a
4
- data.tar.gz: 30b8ef14230fea6c3c48f6f02ed9aca2fea615f115e95f91c0362d67daf9a07c
3
+ metadata.gz: bab620a614f12ac3bff8eed13a4ebe64fe74f2911b47435bf99e0ae392f7ff8c
4
+ data.tar.gz: 4143c27f60470c99094b47c239aa949bc4d1eddb6a7935309f25614335110192
5
5
  SHA512:
6
- metadata.gz: db6a0f30fc19b99289cca38762c3917278eebfa226072fea18bccafc0107a7b661e41160c5ead4c6fea4b35f8f9ec8a49d72ac2d63b87857a5c648159c6844dc
7
- data.tar.gz: f93b1aefc1b18d1cc5debbc6257fbb6b181ddbc18f53af1283fc2ef319f9291f6e856c3cb0d1d030f8d01132e2e4a9e98fea8f84a5648629b18d208b66074e3e
6
+ metadata.gz: 90e21fd14f8359bea259442d413a8edd2939a097586cd06d6da14ddd8e1140a3e12547342a54bbe5a874b65cb7d2ad4f8f96f2aef051e4e5cf9518ed839ec1b3
7
+ data.tar.gz: ded356ce7a14f2e56819db345e9bebde05c57c38aa56cacfb3735d69110bf84a75374a1846e048c04e257f173dcc9fe6b968b99fb94b8487b8387e54e53f21bd
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2020-2025 kojix2
3
+ Copyright (c) 2020-present 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,7 +1,7 @@
1
1
  # LibUI
2
2
 
3
3
  [![test](https://github.com/kojix2/LibUI/actions/workflows/test.yml/badge.svg)](https://github.com/kojix2/LibUI/actions/workflows/test.yml)
4
- [![Gem Version](https://badge.fury.io/rb/libui.svg)](https://badge.fury.io/rb/libui)
4
+ [![Gem Version](https://img.shields.io/badge/dynamic/json?label=gem%20version&query=%24%5B0%5D.number&url=https%3A%2F%2Frubygems.org%2Fapi%2Fv1%2Fversions%2Flibui.json&color=brightgreen)](https://rubygems.org/gems/libui/versions)
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
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)
@@ -16,20 +16,12 @@ LibUI is a Ruby wrapper for libui family.
16
16
 
17
17
  ## Installation
18
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
-
27
19
  ```sh
28
- gem install libui
20
+ gem install libui # --pre
29
21
  ```
30
22
 
31
23
  - The gem package includes the libui-ng shared library for Windows, Mac, and Linux.
32
- - Namely `libui.dll`, `libui.dylib`, or `libui.so`.
24
+ - Namely `libui.x64.dll`/`libui.x86.dll`, `libui.x86_64.dylib`/`libui.arm64.dylib`, or `libui.x86_64.so`/`libui.aarch64.so`.
33
25
  - No dependencies required.
34
26
  - The libui gem uses the standard Ruby library [Fiddle](https://github.com/ruby/fiddle) to call C functions.
35
27
 
@@ -62,9 +54,8 @@ end
62
54
 
63
55
  UI.window_on_closing(main_window) do
64
56
  puts 'Bye Bye'
65
- UI.control_destroy(main_window)
66
57
  UI.quit
67
- 0
58
+ 1
68
59
  end
69
60
 
70
61
  UI.window_set_child(main_window, button)
@@ -86,7 +77,7 @@ Compared to the original libui library written in C:
86
77
  - The block will be converted to a Proc object and added as the last argument.
87
78
  - The last argument can still be omitted when nil.
88
79
 
89
- You can use [the documentation for libui's Go bindings](https://pkg.go.dev/github.com/andlabs/ui) as a reference.
80
+ You can use [the libui-ng API documentation](https://libui-ng.github.io/libui-ng/) as a reference.
90
81
 
91
82
  ### DSLs for LibUI
92
83
 
@@ -95,7 +86,6 @@ LibUI is not object-oriented because it is a thin Ruby wrapper (binding) for the
95
86
  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):
96
87
 
97
88
  - [Glimmer DSL for LibUI](https://github.com/AndyObtiva/glimmer-dsl-libui)
98
- - [libui_paradise](https://rubygems.org/gems/libui_paradise)
99
89
 
100
90
  ### Working with fiddle pointers
101
91
 
@@ -105,12 +95,26 @@ UI = LibUI
105
95
  UI.init
106
96
  ```
107
97
 
108
- To convert a pointer to a string:
98
+ Text getter methods such as `label_text`, `entry_text`, and `window_title`
99
+ return `Fiddle::Pointer` objects for strings allocated by libui. Convert the
100
+ pointer to a Ruby string, then release it with `free_text`.
109
101
 
110
102
  ```ruby
111
103
  label = UI.new_label("Ruby")
112
- p pointer = UI.label_text(label) # #<Fiddle::Pointer>
113
- p pointer.to_s # Ruby
104
+ pointer = UI.label_text(label) # #<Fiddle::Pointer>
105
+ text = pointer.to_s
106
+ UI.free_text(pointer)
107
+ p text # Ruby
108
+ ```
109
+
110
+ Use `ensure` if the code between conversion and cleanup can raise:
111
+
112
+ ```ruby
113
+ def ui_text(text_pointer)
114
+ text_pointer.to_s
115
+ ensure
116
+ UI.free_text(text_pointer) if text_pointer && !text_pointer.null?
117
+ end
114
118
  ```
115
119
 
116
120
  If you need to use C structs, you can do the following:
@@ -125,11 +129,15 @@ font_descriptor.to_ptr.free = Fiddle::RUBY_FREE
125
129
 
126
130
  UI.font_button_on_changed(font_button) do
127
131
  UI.font_button_font(font_button, font_descriptor)
128
- p family: font_descriptor.Family.to_s,
129
- size: font_descriptor.Size,
130
- weight: font_descriptor.Weight,
131
- italic: font_descriptor.Italic,
132
- stretch: font_descriptor.Stretch
132
+ begin
133
+ p family: font_descriptor.Family.to_s,
134
+ size: font_descriptor.Size,
135
+ weight: font_descriptor.Weight,
136
+ italic: font_descriptor.Italic,
137
+ stretch: font_descriptor.Stretch
138
+ ensure
139
+ UI.free_font_button_font(font_descriptor)
140
+ end
133
141
  end
134
142
  ```
135
143
 
@@ -178,40 +186,27 @@ Add additional options below if necessary:
178
186
  git clone https://github.com/kojix2/libui
179
187
  cd libui
180
188
  bundle install
181
- bundle exec rake vendor:auto # vendor:build
189
+ bundle exec rake vendor:auto
182
190
  bundle exec rake test
183
191
  ```
184
192
 
185
193
  ### Pre-built shared libraries for libui-ng
186
194
 
187
- Use the following rake tasks to download the shared library required for your platform:
188
-
189
- `rake -T`
195
+ Download pre-built libui-ng shared libraries (per your current platform):
190
196
 
197
+ ```sh
198
+ bundle exec rake vendor:auto
191
199
  ```
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
201
- ```
202
-
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
200
 
206
- ### Using C libui compiled from source code
201
+ Clean downloaded vendor files (keeps `vendor/{LICENSE,README}.md`):
207
202
 
208
- The following Rake task will compile libui-ng. meson or ninja is required.
209
-
210
- `bundle exec rake vendor:build`
203
+ ```sh
204
+ bundle exec rake vendor:clean
205
+ ```
211
206
 
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).
207
+ ### Using your own libui build
213
208
 
214
- Another simple approach is to replace the shared libraries in the gem vendor directory with the ones you have compiled.
209
+ 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).
215
210
 
216
211
  ### Publishing gems
217
212
 
@@ -220,8 +215,8 @@ Another simple approach is to replace the shared libraries in the gem vendor dir
220
215
  Push a version tag to automatically publish platform-specific gems:
221
216
 
222
217
  ```sh
223
- git tag v0.1.3
224
- git push origin v0.1.3
218
+ git tag v0.2.0
219
+ git push origin v0.2.0
225
220
  ```
226
221
 
227
222
  Requires `RUBYGEMS_API_KEY` repository secret with scoped API key.
@@ -239,9 +234,19 @@ find pkg -name *.gem -exec sh -c "echo; echo \# {}; tar -O -f {} -x data.tar.gz
239
234
  rake release_platform # publish gems
240
235
  ```
241
236
 
237
+ Windows Ruby (x64-mingw32 or x64-mingw-ucrt)
238
+
239
+ ```sh
240
+ gem install rake rubyzip
241
+ GEM_PLATFORM=x64-mingw32 rake vendor:clean
242
+ GEM_PLATFORM=x64-mingw32 rake vendor:auto
243
+ GEM_PLATFORM=x64-mingw32 gem build libui.gemspec
244
+ gem push libui-0.2.0-x64-mingw32.gem
245
+ ```
246
+
242
247
  ### libui or libui-ng
243
248
 
244
- - From version 0.1.X, we plan to support only libui-ng/libui-ng.
249
+ - From version 0.1.X, LibUI supports only libui-ng.
245
250
  - Version 0.0.X only supports andlabs/libui.
246
251
 
247
252
  ## Contributing
data/lib/libui/ffi.rb CHANGED
@@ -3,8 +3,6 @@ require_relative 'fiddle_patch'
3
3
  require_relative 'error'
4
4
 
5
5
  module LibUI
6
- class Error < StandardError; end
7
-
8
6
  module FFI
9
7
  extend Fiddle::Importer
10
8
  extend FiddlePatch
@@ -38,6 +36,7 @@ module LibUI
38
36
  end
39
37
 
40
38
  typealias('uint32_t', 'unsigned int')
39
+ typealias('uint64_t', 'unsigned long long')
41
40
 
42
41
  InitOptions = struct [
43
42
  'size_t Size'
@@ -11,23 +11,23 @@ module LibUI
11
11
  def parse_signature(signature, tymap = nil)
12
12
  tymap ||= {}
13
13
  ctype, func, args = case compact(signature)
14
- when /^(?:[\w\*\s]+)\(\*(\w+)\((.*?)\)\)(?:\[\w*\]|\(.*?\));?$/
14
+ when /^(?:[\w*\s]+)\(\*(\w+)\((.*?)\)\)(?:\[\w*\]|\(.*?\));?$/
15
15
  [TYPE_VOIDP, Regexp.last_match(1), Regexp.last_match(2)]
16
- when /^([\w\*\s]+[*\s])(\w+)\((.*?)\);?$/
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
23
23
  argtype = split_arguments(args).collect.with_index do |arg, idx| # Added with_index
24
24
  # Check if it is a function pointer or not
25
- if arg =~ /\(\*.*\)\(.*\)/ # Added
25
+ if arg =~ /\(\*.*\)\(.*\)/ # Added
26
26
  # From the arguments, create a notation that looks like a function declaration
27
27
  # int(*f)(int *, void *) -> int f(int *, void *)
28
- func_arg = arg.sub('(*', ' ').sub(')', '') # Added
28
+ func_arg = arg.sub('(*', ' ').sub(')', '') # Added
29
29
  # Use Fiddle's parse_signature method again.
30
- callback_argument_types[idx] = parse_signature(func_arg) # Added
30
+ callback_argument_types[idx] = parse_signature(func_arg) # Added
31
31
  end
32
32
  parse_ctype(arg, tymap)
33
33
  end
@@ -41,8 +41,8 @@ module LibUI
41
41
  func = import_function(symname, ctype, argtype, opt[:call_type])
42
42
 
43
43
  # callback_argument_types
44
- func.instance_variable_set(:@callback_argument_types,
45
- callback_argument_types) # Added
44
+ func.instance_variable_set(:@callback_argument_types,
45
+ callback_argument_types) # Added
46
46
  # attr_reader
47
47
  def func.callback_argument_types
48
48
  @callback_argument_types
@@ -68,9 +68,9 @@ module LibUI
68
68
  @func_map[name] = func
69
69
  # define_method(name){|*args,&block| f.call(*args,&block)}
70
70
  begin
71
- /^(.+?):(\d+)/ =~ caller.first
72
- file = Regexp.last_match(1)
73
- line = Regexp.last_match(2).to_i
71
+ location = caller_locations(1, 1).first
72
+ file = location.path
73
+ line = location.lineno
74
74
  rescue StandardError
75
75
  file, line = __FILE__, __LINE__ + 3
76
76
  end
@@ -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.2.0.pre'
2
+ VERSION = '0.2.2'
3
3
  end
data/lib/libui.rb CHANGED
@@ -42,15 +42,121 @@ module LibUI
42
42
 
43
43
  class << self
44
44
  def init(opt = nil)
45
+ # Allocate uiInitOptions if not provided
45
46
  unless opt
46
47
  opt = FFI::InitOptions.malloc
47
48
  opt.to_ptr.free = Fiddle::RUBY_FREE
49
+ opt.Size = FFI::InitOptions.size
48
50
  end
49
- i = super(opt)
50
- return if i.size.zero?
51
51
 
52
- warn 'error'
53
- 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
60
+ end
61
+
62
+ def new_button(text = '')
63
+ super(text)
64
+ end
65
+
66
+ def new_checkbox(text = '')
67
+ super(text)
68
+ end
69
+
70
+ def window_set_title(window, title = '')
71
+ super(window, title)
72
+ end
73
+
74
+ def button_set_text(button, text = '')
75
+ super(button, text)
76
+ end
77
+
78
+ def checkbox_set_text(checkbox, text = '')
79
+ super(checkbox, text)
80
+ end
81
+
82
+ def entry_set_text(entry, text = '')
83
+ super(entry, text)
84
+ end
85
+
86
+ def label_set_text(label, text = '')
87
+ super(label, text)
88
+ end
89
+
90
+ def new_label(text = '')
91
+ super(text)
92
+ end
93
+
94
+ def group_set_title(group, title = '')
95
+ super(group, title)
96
+ end
97
+
98
+ def new_group(title = '')
99
+ super(title)
100
+ end
101
+
102
+ def combobox_append(combobox, text = '')
103
+ super(combobox, text)
104
+ end
105
+
106
+ def combobox_insert_at(combobox, index, text = '')
107
+ super(combobox, index, text)
108
+ end
109
+
110
+ def editable_combobox_append(combobox, text = '')
111
+ super(combobox, text)
112
+ end
113
+
114
+ def editable_combobox_set_text(combobox, text = '')
115
+ super(combobox, text)
116
+ end
117
+
118
+ def radio_buttons_append(radio_buttons, text = '')
119
+ super(radio_buttons, text)
120
+ end
121
+
122
+ def multiline_entry_set_text(entry, text = '')
123
+ super(entry, text)
124
+ end
125
+
126
+ def multiline_entry_append(entry, text = '')
127
+ super(entry, text)
128
+ end
129
+
130
+ def menu_append_item(menu, name = '')
131
+ super(menu, name)
132
+ end
133
+
134
+ def menu_append_check_item(menu, name = '')
135
+ super(menu, name)
136
+ end
137
+
138
+ def new_menu(name = '')
139
+ super(name)
140
+ end
141
+
142
+ def msg_box(parent, title, description = '')
143
+ super(parent, title, description)
144
+ end
145
+
146
+ def msg_box_error(parent, title, description = '')
147
+ super(parent, title, description)
148
+ end
149
+
150
+ def new_attributed_string(initial_string = '')
151
+ super(initial_string)
152
+ end
153
+
154
+ def attributed_string_append_unattributed(attributed_string, str = '')
155
+ super(attributed_string, str)
156
+ end
157
+
158
+ def new_table_value_string(str = '')
159
+ super(str)
54
160
  end
55
161
 
56
162
  # Gets the window position.
Binary file
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: libui
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0.pre
4
+ version: 0.2.2
5
5
  platform: arm64-darwin
6
6
  authors:
7
7
  - kojix2
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2025-08-16 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: fiddle
@@ -24,7 +23,6 @@ dependencies:
24
23
  - - ">="
25
24
  - !ruby/object:Gem::Version
26
25
  version: '0'
27
- description:
28
26
  email:
29
27
  - 2xijok@gmail.com
30
28
  executables: []
@@ -47,7 +45,6 @@ homepage: https://github.com/kojix2/libui
47
45
  licenses:
48
46
  - MIT
49
47
  metadata: {}
50
- post_install_message:
51
48
  rdoc_options: []
52
49
  require_paths:
53
50
  - lib
@@ -62,8 +59,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
62
59
  - !ruby/object:Gem::Version
63
60
  version: '0'
64
61
  requirements: []
65
- rubygems_version: 3.5.22
66
- signing_key:
62
+ rubygems_version: 3.6.9
67
63
  specification_version: 4
68
64
  summary: Ruby bindings to libui
69
65
  test_files: []