libui 0.2.0.pre-aarch64-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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 173e40b13a23b0c2a283f1e5092ee4e522d5f20f8676e35973f3931b3687831b
4
+ data.tar.gz: 0ab336bf66b9c5be8880843c911b6c292b494d228b404ef61a34f5b8ec39f209
5
+ SHA512:
6
+ metadata.gz: '098cb8fafe820dd47cca54cd4ffe8a1d1002dc70a15b961a877498199f1d9c2acd40b944a0312025fe4bb90ea012ab09156c6d147a2a618d7d083d280b993698'
7
+ data.tar.gz: eef9f047b1bb087a93bbc41340b49a3cbfd2a3001aa5f5bfa62dcfe90f0a1ebf62486669e3fe4eafe521d568f5167a8214e4fd6503dd72b215894e7de05c6eca
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020-2025 kojix2
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,275 @@
1
+ # LibUI
2
+
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)
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)
8
+
9
+ LibUI is a Ruby wrapper for libui family.
10
+
11
+ :rocket: [libui-ng](https://github.com/libui-ng/libui-ng) - A cross-platform portable GUI library
12
+
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.
16
+
17
+ ## Installation
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
+ ```sh
28
+ gem install libui
29
+ ```
30
+
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"> |
39
+
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.
45
+
46
+ ## Usage
47
+
48
+ ```ruby
49
+ require 'libui'
50
+
51
+ UI = LibUI
52
+
53
+ UI.init
54
+
55
+ main_window = UI.new_window('hello world', 200, 100, 1)
56
+
57
+ button = UI.new_button('Button')
58
+
59
+ UI.button_on_clicked(button) do
60
+ UI.msg_box(main_window, 'Information', 'You clicked the button')
61
+ end
62
+
63
+ UI.window_on_closing(main_window) do
64
+ puts 'Bye Bye'
65
+ UI.control_destroy(main_window)
66
+ UI.quit
67
+ 0
68
+ end
69
+
70
+ UI.window_set_child(main_window, button)
71
+ UI.control_show(main_window)
72
+
73
+ UI.main
74
+ UI.quit
75
+ ```
76
+
77
+ For more examples, see the [examples](https://github.com/kojix2/libui/tree/main/examples) directory.
78
+
79
+ ### General Rules
80
+
81
+ Compared to the original libui library written in C:
82
+
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.
88
+
89
+ You can use [the documentation for libui's Go bindings](https://pkg.go.dev/github.com/andlabs/ui) as a reference.
90
+
91
+ ### DSLs for LibUI
92
+
93
+ LibUI is not object-oriented because it is a thin Ruby wrapper (binding) for the procedural C libui library, mirroring its API structure.
94
+
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):
96
+
97
+ - [Glimmer DSL for LibUI](https://github.com/AndyObtiva/glimmer-dsl-libui)
98
+ - [libui_paradise](https://rubygems.org/gems/libui_paradise)
99
+
100
+ ### Working with fiddle pointers
101
+
102
+ ```ruby
103
+ require 'libui'
104
+ UI = LibUI
105
+ UI.init
106
+ ```
107
+
108
+ To convert a pointer to a string:
109
+
110
+ ```ruby
111
+ label = UI.new_label("Ruby")
112
+ p pointer = UI.label_text(label) # #<Fiddle::Pointer>
113
+ p pointer.to_s # Ruby
114
+ ```
115
+
116
+ If you need to use C structs, you can do the following:
117
+
118
+ ```ruby
119
+ font_button = UI.new_font_button
120
+
121
+ # Allocate memory
122
+ font_descriptor = UI::FFI::FontDescriptor.malloc
123
+ font_descriptor.to_ptr.free = Fiddle::RUBY_FREE
124
+ # font_descriptor = UI::FFI::FontDescriptor.malloc(Fiddle::RUBY_FREE) # fiddle 1.0.1 or higher
125
+
126
+ UI.font_button_on_changed(font_button) do
127
+ 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
+ end
134
+ ```
135
+
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.
140
+
141
+ ```ruby
142
+ # Assign to a local variable to prevent it from being collected by GC.
143
+ handler.MouseEvent = (c1 = Fiddle::Closure::BlockCaller.new(0, [0]) {})
144
+ handler.MouseCrossed = (c2 = Fiddle::Closure::BlockCaller.new(0, [0]) {})
145
+ handler.DragBroken = (c3 = Fiddle::Closure::BlockCaller.new(0, [0]) {})
146
+ ```
147
+
148
+ ### Creating a Windows executable (.exe) with OCRA
149
+
150
+ OCRA (One-Click Ruby Application) builds Windows executables from Ruby source code.
151
+
152
+ - https://github.com/larsch/ocra/
153
+
154
+ To build an exe with Ocra, include 3 DLLs from the ruby_builtin_dlls folder:
155
+
156
+ ```sh
157
+ ocra examples/control_gallery.rb ^
158
+ --dll ruby_builtin_dlls/libssp-0.dll ^
159
+ --dll ruby_builtin_dlls/libgmp-10.dll ^
160
+ --dll ruby_builtin_dlls/libffi-7.dll ^
161
+ --gem-all=fiddle ^
162
+ ```
163
+
164
+ Add additional options below if necessary:
165
+
166
+ ```sh
167
+ --window ^
168
+ --add-all-core ^
169
+ --chdir-first ^
170
+ --icon assets\app.ico ^
171
+ --verbose ^
172
+ --output out\gallery.exe
173
+ ```
174
+
175
+ ## Development
176
+
177
+ ```sh
178
+ git clone https://github.com/kojix2/libui
179
+ cd libui
180
+ bundle install
181
+ bundle exec rake vendor:auto # vendor:build
182
+ bundle exec rake test
183
+ ```
184
+
185
+ ### Pre-built shared libraries for libui-ng
186
+
187
+ Use the following rake tasks to download the shared library required for your platform:
188
+
189
+ `rake -T`
190
+
191
+ ```
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
+
206
+ ### Using C libui compiled from source code
207
+
208
+ The following Rake task will compile libui-ng. meson or ninja is required.
209
+
210
+ `bundle exec rake vendor:build`
211
+
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).
213
+
214
+ Another simple approach is to replace the shared libraries in the gem vendor directory with the ones you have compiled.
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
+
242
+ ### libui or libui-ng
243
+
244
+ - From version 0.1.X, we plan to support only libui-ng/libui-ng.
245
+ - Version 0.0.X only supports andlabs/libui.
246
+
247
+ ## Contributing
248
+
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
261
+
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.
264
+
265
+ ## Acknowledgements
266
+
267
+ This project is inspired by libui-ruby.
268
+
269
+ - https://github.com/jamescook/libui-ruby
270
+
271
+ While libui-ruby uses [Ruby-FFI](https://github.com/ffi/ffi), this gem uses [Fiddle](https://github.com/ruby/fiddle).
272
+
273
+ ## License
274
+
275
+ [MIT License](https://opensource.org/licenses/MIT).
@@ -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