libui 0.1.0.pre.0-arm64-darwin
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +233 -0
- data/lib/libui/ffi.rb +628 -0
- data/lib/libui/fiddle_patch.rb +79 -0
- data/lib/libui/libui_base.rb +52 -0
- data/lib/libui/utils.rb +19 -0
- data/lib/libui/version.rb +3 -0
- data/lib/libui.rb +226 -0
- data/vendor/LICENSE.md +10 -0
- data/vendor/README.md +143 -0
- data/vendor/libui.dylib +0 -0
- metadata +54 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3c7bbd9dd62da588b0d161ffaf7000725cc04d1537585fcdbd67bd22db00c344
|
4
|
+
data.tar.gz: 0f0a54e51337554b9032c0b4becbc2013f93e3e834b223b60f10f7268910bd94
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 94581da8f2a97f769ff191ebbb1d8e7862bafb19217c047b5f6a1e4113cc42621c147d61dd884e3dea20c7f01aa55fa0d56b03304b23d1e04c1c1eb7e3ade6ad
|
7
|
+
data.tar.gz: f8abf478833947ae6fa7998f2346bf80cb7610452c2fef48e2a4d83734bfdc01c8f9ba7617941565741fe7232e9a312dc624f8b3ac77549c6003bc462a39780c
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 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,233 @@
|
|
1
|
+
# LibUI
|
2
|
+
|
3
|
+
![build](https://github.com/kojix2/libui/workflows/build/badge.svg)
|
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
|
+
|
7
|
+
LibUI is a Ruby wrapper for libui and libui-ng.
|
8
|
+
|
9
|
+
:rocket: [libui-ng](https://github.com/libui-ng/libui-ng) - A cross-platform portable GUI library
|
10
|
+
|
11
|
+
:radio_button: [libui](https://github.com/andlabs/libui) - Original version by andlabs
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
```sh
|
16
|
+
gem install libui
|
17
|
+
```
|
18
|
+
|
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.
|
23
|
+
|
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">|
|
27
|
+
|
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).
|
32
|
+
|
33
|
+
## Usage
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
require 'libui'
|
37
|
+
|
38
|
+
UI = LibUI
|
39
|
+
|
40
|
+
UI.init
|
41
|
+
|
42
|
+
main_window = UI.new_window('hello world', 200, 100, 1)
|
43
|
+
|
44
|
+
button = UI.new_button('Button')
|
45
|
+
|
46
|
+
UI.button_on_clicked(button) do
|
47
|
+
UI.msg_box(main_window, 'Information', 'You clicked the button')
|
48
|
+
end
|
49
|
+
|
50
|
+
UI.window_on_closing(main_window) do
|
51
|
+
puts 'Bye Bye'
|
52
|
+
UI.control_destroy(main_window)
|
53
|
+
UI.quit
|
54
|
+
0
|
55
|
+
end
|
56
|
+
|
57
|
+
UI.window_set_child(main_window, button)
|
58
|
+
UI.control_show(main_window)
|
59
|
+
|
60
|
+
UI.main
|
61
|
+
UI.quit
|
62
|
+
```
|
63
|
+
|
64
|
+
See [examples](https://github.com/kojix2/libui/tree/main/examples) directory.
|
65
|
+
|
66
|
+
### General Rules
|
67
|
+
|
68
|
+
Compared to original libui written in C,
|
69
|
+
|
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.
|
75
|
+
|
76
|
+
You can use [the documentation for libui's Go bindings](https://pkg.go.dev/github.com/andlabs/ui) as a reference.
|
77
|
+
|
78
|
+
### DSLs for LibUI
|
79
|
+
|
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.
|
81
|
+
|
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):
|
83
|
+
|
84
|
+
* [Glimmer DSL for LibUI](https://github.com/AndyObtiva/glimmer-dsl-libui)
|
85
|
+
* [libui_paradise](https://rubygems.org/gems/libui_paradise)
|
86
|
+
|
87
|
+
### How to use fiddle pointers?
|
88
|
+
|
89
|
+
```ruby
|
90
|
+
require 'libui'
|
91
|
+
UI = LibUI
|
92
|
+
UI.init
|
93
|
+
```
|
94
|
+
|
95
|
+
Convert a pointer to a string.
|
96
|
+
|
97
|
+
```ruby
|
98
|
+
label = UI.new_label("Ruby")
|
99
|
+
p pointer = UI.label_text(label) # #<Fiddle::Pointer>
|
100
|
+
p pointer.to_s # Ruby
|
101
|
+
```
|
102
|
+
|
103
|
+
If you need to use C structs, you can do the following.
|
104
|
+
|
105
|
+
```ruby
|
106
|
+
font_button = UI.new_font_button
|
107
|
+
|
108
|
+
# Allocate memory
|
109
|
+
font_descriptor = UI::FFI::FontDescriptor.malloc
|
110
|
+
font_descriptor.to_ptr.free = Fiddle::RUBY_FREE
|
111
|
+
# font_descriptor = UI::FFI::FontDescriptor.malloc(Fiddle::RUBY_FREE) # fiddle 1.0.1 or higher
|
112
|
+
|
113
|
+
UI.font_button_on_changed(font_button) do
|
114
|
+
UI.font_button_font(font_button, font_descriptor)
|
115
|
+
p family: font_descriptor.Family.to_s,
|
116
|
+
size: font_descriptor.Size,
|
117
|
+
weight: font_descriptor.Weight,
|
118
|
+
italic: font_descriptor.Italic,
|
119
|
+
stretch: font_descriptor.Stretch
|
120
|
+
end
|
121
|
+
```
|
122
|
+
|
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.
|
129
|
+
|
130
|
+
```ruby
|
131
|
+
# to a local variable to prevent it from being collected by GC.
|
132
|
+
handler.MouseEvent = (c1 = Fiddle::Closure::BlockCaller.new(0, [0]) {})
|
133
|
+
handler.MouseCrossed = (c2 = Fiddle::Closure::BlockCaller.new(0, [0]) {})
|
134
|
+
handler.DragBroken = (c3 = Fiddle::Closure::BlockCaller.new(0, [0]) {})
|
135
|
+
```
|
136
|
+
|
137
|
+
### How to create an executable (.exe) on Windows
|
138
|
+
|
139
|
+
OCRA (One-Click Ruby Application) builds Windows executables from Ruby source code.
|
140
|
+
* https://github.com/larsch/ocra/
|
141
|
+
|
142
|
+
In order to build a exe with Ocra, include 3 DLLs from ruby_builtin_dlls folder:
|
143
|
+
|
144
|
+
```sh
|
145
|
+
ocra examples/control_gallery.rb ^
|
146
|
+
--dll ruby_builtin_dlls/libssp-0.dll ^
|
147
|
+
--dll ruby_builtin_dlls/libgmp-10.dll ^
|
148
|
+
--dll ruby_builtin_dlls/libffi-7.dll ^
|
149
|
+
--gem-all=fiddle ^
|
150
|
+
```
|
151
|
+
|
152
|
+
Add additional options below if necessary.
|
153
|
+
|
154
|
+
```sh
|
155
|
+
--window ^
|
156
|
+
--add-all-core ^
|
157
|
+
--chdir-first ^
|
158
|
+
--icon assets\app.ico ^
|
159
|
+
--verbose ^
|
160
|
+
--output out\gallery.exe
|
161
|
+
```
|
162
|
+
|
163
|
+
## Development
|
164
|
+
|
165
|
+
LibUI is not object-oriented, but it provides high portability with a minimal implementation.
|
166
|
+
|
167
|
+
```sh
|
168
|
+
git clone https://github.com/kojix2/libui
|
169
|
+
cd libui
|
170
|
+
bundle install
|
171
|
+
bundle exec rake vendor:default # download shared libraries for all platforms
|
172
|
+
bundle exec rake test
|
173
|
+
```
|
174
|
+
|
175
|
+
You can use the following rake tasks to download the shared library required for your platform.
|
176
|
+
|
177
|
+
`rake -T`
|
178
|
+
|
179
|
+
```
|
180
|
+
rake vendor:default # Downlaod [linux_x64, mac_arm, windows_x64] to vendor directory
|
181
|
+
rake vendor:linux_x64 # Download libui.so for Linux to vendor directory
|
182
|
+
rake vendor:linux_x86 # Download libui.so for Linux to vendor directory
|
183
|
+
rake vendor:mac_arm # Download libui.dylib for Mac to vendor directory (universal binary)
|
184
|
+
rake vendor:mac_x64 # Download libui.dylib for Mac to vendor directory
|
185
|
+
rake vendor:windows_x64 # Download libui.dll for Windows to vendor directory
|
186
|
+
rake vendor:windows_x86 # Download libui.dll for Windows to vendor directory
|
187
|
+
```
|
188
|
+
|
189
|
+
For example, If you are using a 32-bit (x86) version of Ruby on Windows, type `rake vendor:windows_x86`.
|
190
|
+
|
191
|
+
### Use C libui compiled from source code
|
192
|
+
|
193
|
+
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).
|
194
|
+
|
195
|
+
Another simple approach is to replace the shared libraries in the gem vendor directory with the ones you have compiled.
|
196
|
+
|
197
|
+
### libui-ng
|
198
|
+
|
199
|
+
Version 0.0.X only supports libui. From version 0.1.X, we plan to support only libui-ng.
|
200
|
+
|
201
|
+
[libui-ng](https://github.com/libui-ng/libui-ng) is the successor project to libui. Rake tasks are available to build or download libui-ng shared libraries.
|
202
|
+
|
203
|
+
```
|
204
|
+
rake libui-ng:build[hash] # Build libui-ng latest master [commit hash]
|
205
|
+
rake libui-ng:mac # Download latest dev build for Mac to vendor directory
|
206
|
+
rake libui-ng:ubuntu_x64 # Download latest dev build for Ubuntu to vendor directory
|
207
|
+
```
|
208
|
+
|
209
|
+
```
|
210
|
+
rake install
|
211
|
+
```
|
212
|
+
|
213
|
+
## Contributing
|
214
|
+
|
215
|
+
Would you like to add your commits to libui?
|
216
|
+
* Please feel free to send us your [pull requests](https://github.com/kojix2/libui/pulls).
|
217
|
+
* Small corrections, such as typo fixes, are appreciated.
|
218
|
+
* Did you find any bugs? Enter in the [issues](https://github.com/kojix2/LibUI/issues) section!
|
219
|
+
|
220
|
+
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.
|
221
|
+
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.
|
222
|
+
|
223
|
+
## Acknowledgement
|
224
|
+
|
225
|
+
This project is inspired by libui-ruby.
|
226
|
+
|
227
|
+
* https://github.com/jamescook/libui-ruby
|
228
|
+
|
229
|
+
While libui-ruby uses [Ruby-FFI](https://github.com/ffi/ffi), this gem uses [Fiddle](https://github.com/ruby/fiddle).
|
230
|
+
|
231
|
+
## License
|
232
|
+
|
233
|
+
[MIT License](https://opensource.org/licenses/MIT).
|