libui 0.2.0.pre-arm64-darwin → 0.2.1-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: e9ff7947a9b584b530dba33a19b9ebbd7051cdbc7907a93e06238964a0351f6f
4
+ data.tar.gz: cc8c67692634e93fcfb5081317229631a419bf9618b5e56424343f1116265f4f
5
5
  SHA512:
6
- metadata.gz: db6a0f30fc19b99289cca38762c3917278eebfa226072fea18bccafc0107a7b661e41160c5ead4c6fea4b35f8f9ec8a49d72ac2d63b87857a5c648159c6844dc
7
- data.tar.gz: f93b1aefc1b18d1cc5debbc6257fbb6b181ddbc18f53af1283fc2ef319f9291f6e856c3cb0d1d030f8d01132e2e4a9e98fea8f84a5648629b18d208b66074e3e
6
+ metadata.gz: 4e956d038e306c5cbfb6cf563331067bfe06ec43780e15f3eeb77f033abc362ba3fcab13e2c33bddc992eadbc7899fadd1a4ed96d9084bb83eeed5c0fb9089fa
7
+ data.tar.gz: 8df39ece64ee5c4aab78b721ce7382c11a09f3e4376023cb2980331f2ded2b62221143fc3c2a0c547a3bff50c5f5f58ac462db033ed3b55d26f58164ab34869b
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
@@ -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
 
@@ -105,12 +96,26 @@ UI = LibUI
105
96
  UI.init
106
97
  ```
107
98
 
108
- To convert a pointer to a string:
99
+ Text getter methods such as `label_text`, `entry_text`, and `window_title`
100
+ return `Fiddle::Pointer` objects for strings allocated by libui. Convert the
101
+ pointer to a Ruby string, then release it with `free_text`.
109
102
 
110
103
  ```ruby
111
104
  label = UI.new_label("Ruby")
112
- p pointer = UI.label_text(label) # #<Fiddle::Pointer>
113
- p pointer.to_s # Ruby
105
+ pointer = UI.label_text(label) # #<Fiddle::Pointer>
106
+ text = pointer.to_s
107
+ UI.free_text(pointer)
108
+ p text # Ruby
109
+ ```
110
+
111
+ Use `ensure` if the code between conversion and cleanup can raise:
112
+
113
+ ```ruby
114
+ def ui_text(text_pointer)
115
+ text_pointer.to_s
116
+ ensure
117
+ UI.free_text(text_pointer) if text_pointer && !text_pointer.null?
118
+ end
114
119
  ```
115
120
 
116
121
  If you need to use C structs, you can do the following:
@@ -125,11 +130,15 @@ font_descriptor.to_ptr.free = Fiddle::RUBY_FREE
125
130
 
126
131
  UI.font_button_on_changed(font_button) do
127
132
  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
133
+ begin
134
+ p family: font_descriptor.Family.to_s,
135
+ size: font_descriptor.Size,
136
+ weight: font_descriptor.Weight,
137
+ italic: font_descriptor.Italic,
138
+ stretch: font_descriptor.Stretch
139
+ ensure
140
+ UI.free_font_button_font(font_descriptor)
141
+ end
133
142
  end
134
143
  ```
135
144
 
@@ -178,40 +187,27 @@ Add additional options below if necessary:
178
187
  git clone https://github.com/kojix2/libui
179
188
  cd libui
180
189
  bundle install
181
- bundle exec rake vendor:auto # vendor:build
190
+ bundle exec rake vendor:auto
182
191
  bundle exec rake test
183
192
  ```
184
193
 
185
194
  ### Pre-built shared libraries for libui-ng
186
195
 
187
- Use the following rake tasks to download the shared library required for your platform:
188
-
189
- `rake -T`
196
+ Download pre-built libui-ng shared libraries (per your current platform):
190
197
 
198
+ ```sh
199
+ bundle exec rake vendor:auto
191
200
  ```
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
201
 
206
- ### Using C libui compiled from source code
202
+ Clean downloaded vendor files (keeps `vendor/{LICENSE,README}.md`):
207
203
 
208
- The following Rake task will compile libui-ng. meson or ninja is required.
209
-
210
- `bundle exec rake vendor:build`
204
+ ```sh
205
+ bundle exec rake vendor:clean
206
+ ```
211
207
 
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).
208
+ ### Using your own libui build
213
209
 
214
- Another simple approach is to replace the shared libraries in the gem vendor directory with the ones you have compiled.
210
+ 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
211
 
216
212
  ### Publishing gems
217
213
 
@@ -220,8 +216,8 @@ Another simple approach is to replace the shared libraries in the gem vendor dir
220
216
  Push a version tag to automatically publish platform-specific gems:
221
217
 
222
218
  ```sh
223
- git tag v0.1.3
224
- git push origin v0.1.3
219
+ git tag v0.2.0
220
+ git push origin v0.2.0
225
221
  ```
226
222
 
227
223
  Requires `RUBYGEMS_API_KEY` repository secret with scoped API key.
@@ -239,9 +235,19 @@ find pkg -name *.gem -exec sh -c "echo; echo \# {}; tar -O -f {} -x data.tar.gz
239
235
  rake release_platform # publish gems
240
236
  ```
241
237
 
238
+ Windows Ruby (x64-mingw32 or x64-mingw-ucrt)
239
+
240
+ ```sh
241
+ gem install rake rubyzip
242
+ GEM_PLATFORM=x64-mingw32 rake vendor:clean
243
+ GEM_PLATFORM=x64-mingw32 rake vendor:auto
244
+ GEM_PLATFORM=x64-mingw32 gem build libui.gemspec
245
+ gem push libui-0.2.0-x64-mingw32.gem
246
+ ```
247
+
242
248
  ### libui or libui-ng
243
249
 
244
- - From version 0.1.X, we plan to support only libui-ng/libui-ng.
250
+ - From version 0.1.X, LibUI supports only libui-ng.
245
251
  - Version 0.0.X only supports andlabs/libui.
246
252
 
247
253
  ## Contributing
data/lib/libui/ffi.rb CHANGED
@@ -3,7 +3,6 @@ require_relative 'fiddle_patch'
3
3
  require_relative 'error'
4
4
 
5
5
  module LibUI
6
- class Error < StandardError; end
7
6
 
8
7
  module FFI
9
8
  extend Fiddle::Importer
@@ -38,6 +37,7 @@ module LibUI
38
37
  end
39
38
 
40
39
  typealias('uint32_t', 'unsigned int')
40
+ typealias('uint64_t', 'unsigned long long')
41
41
 
42
42
  InitOptions = struct [
43
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.2.0.pre'
2
+ VERSION = '0.2.1'
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.1
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: []