libui 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 02ee9e67a91414cbea40a50448a58bbb320f8962f34a35fa9c26d7ed0019878d
4
- data.tar.gz: cfde88b2432abbf23f9dd0d195db0258c143bfd1ff339f51b3112ccaf4742af2
3
+ metadata.gz: dbb5362886495f17bf74055bf1ad4cbc96bb7f0e4518e8db0b18f9572559adf2
4
+ data.tar.gz: 19040d301c6cb135a3e5ef1270f211f48f007f02ec3e5fe7edcbc3be03f275da
5
5
  SHA512:
6
- metadata.gz: cb131ab13e11e6573058c0ec611c7467557756904b49d4121541f4075518958d3fdf2adc74e21d52f0f433c537faeffd6a77ab4162f7d42321fdec75437d1be0
7
- data.tar.gz: 0dc6139433b79bec3e0a096f376db6af7eedc6b989ccab25bf4d3a1123afc75d053d43625d5302122952b2a527a8a17665ec9bc1472c1574f5ae4262bef80197
6
+ metadata.gz: 27a0c320d8592b2e6a6531b66ed0de3a83a3f606058d16469af530d0633a02d2d13e848e5ca4dd8d6c184015449a2ba56b4eb6c7e63ede1ccb7bfa6d447b5f1b
7
+ data.tar.gz: '033190ef229e3f567db9c7a7d338da4107072a6120e79c928a5e03dffcca922ffe75ac76f631fda810133cd6316d6af55ea234eb3fce214540fe1e92fd7d6eaf'
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  ![build](https://github.com/kojix2/libui/workflows/build/badge.svg)
4
4
  [![Gem Version](https://badge.fury.io/rb/libui.svg)](https://badge.fury.io/rb/libui)
5
5
 
6
- :radio_button: [libui](https://github.com/andlabs/libui) - a portable GUI library -for Ruby
6
+ :radio_button: [libui](https://github.com/andlabs/libui) - a portable GUI library - for Ruby
7
7
 
8
8
  ## Installation
9
9
 
@@ -20,25 +20,29 @@ gem install libui
20
20
  |---------|-----|-------|
21
21
  |<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">|
22
22
 
23
+ Note: If you are using the 32-bit (x86) version of Ruby, you need to download the 32-bit (x86) native dll. See [Development](#development).
24
+
23
25
  ## Usage
24
26
 
25
27
  ```ruby
26
28
  require 'libui'
29
+
27
30
  UI = LibUI
28
31
 
29
32
  UI.init
30
33
 
31
- main_window = UI.new_window('hello world', 300, 200, 1)
32
- UI.window_on_closing(main_window) do
33
- puts 'Bye Bye'
34
- UI.control_destroy(main_window)
35
- UI.quit
36
- 0
37
- end
34
+ main_window = UI.new_window('hello world', 200, 100, 1)
38
35
 
39
36
  button = UI.new_button('Button')
37
+
40
38
  UI.button_on_clicked(button) do
41
39
  UI.msg_box(main_window, 'Information', 'You clicked the button')
40
+ end
41
+
42
+ UI.window_on_closing(main_window) do
43
+ puts 'Bye Bye'
44
+ UI.control_destroy(main_window)
45
+ UI.quit
42
46
  0
43
47
  end
44
48
 
@@ -58,7 +62,6 @@ Compared to original libui written in C,
58
62
  * The method names are snake_case.
59
63
  * If the last argument is nil, it can be omitted.
60
64
  * You can pass a block as a callback.
61
- * Please return 0 explicitly in the block.
62
65
  * The block will be converted to a Proc object and added to the last argument.
63
66
  * Even in that case, it is possible to omit the last argument nil.
64
67
 
@@ -101,35 +104,79 @@ UI.font_button_on_changed(font_button) do
101
104
  end
102
105
  ```
103
106
 
107
+ * Callbacks
108
+ * In Ruby/Fiddle, C callback function is written as an object of
109
+ `Fiddle::Closure::BlockCaller` or `Fiddle::Closure`.
110
+ In this case, you need to be careful about Ruby's garbage collection.
111
+ If the function object is collected, memory will be freed
112
+ and a segmentation violation will occur when the callback is invoked.
113
+
114
+ ```ruby
115
+ # to a local variable to prevent it from being collected by GC.
116
+ handler.MouseEvent = (c1 = Fiddle::Closure::BlockCaller.new(0, [0]) {})
117
+ handler.MouseCrossed = (c2 = Fiddle::Closure::BlockCaller.new(0, [0]) {})
118
+ handler.DragBroken = (c3 = Fiddle::Closure::BlockCaller.new(0, [0]) {})
119
+ ```
120
+
104
121
  ### How to create an executable (.exe) on Windows
105
122
 
106
123
  OCRA (One-Click Ruby Application) builds Windows executables from Ruby source code.
107
124
  * https://github.com/larsch/ocra/
108
125
 
126
+ In order to build a exe with Ocra, include 3 DLLs from ruby_builtin_dlls folder:
127
+
128
+ ```sh
129
+ ocra examples/control_gallery.rb ^
130
+ --dll ruby_builtin_dlls/libssp-0.dll ^
131
+ --dll ruby_builtin_dlls/libgmp-10.dll ^
132
+ --dll ruby_builtin_dlls/libffi-7.dll ^
133
+ --gem-all=fiddle ^
134
+ ```
135
+
136
+ Add additional options below if necessary.
137
+
138
+ ```sh
139
+ --window ^
140
+ --add-all-core ^
141
+ --chdir-first ^
142
+ --icon assets\app.ico ^
143
+ --verbose ^
144
+ --output out\gallery.exe
145
+ ```
146
+
109
147
  ## Development
110
148
 
111
149
  ```sh
112
150
  git clone https://github.com/kojix2/libui
113
151
  cd libui
114
152
  bundle install
115
- bundle exec rake vendor:all
153
+ bundle exec rake vendor:all_x64 # download shared libraries for all platforms
116
154
  bundle exec rake test
117
155
  ```
118
156
 
119
- Use the following rake tasks to download the libui binary files and save them in the vendor directory.
157
+ You can use the following rake tasks to download the shared library required for your platform.
120
158
 
121
159
  `rake -T`
122
160
 
123
161
  ```
124
- rake vendor:all # Download libui.so, libui.dylib, and libui.dll to ve...
125
- rake vendor:linux # Download libui.so for Linux to vendor directory
126
- rake vendor:mac # Download libui.dylib for Mac to vendor directory
127
- rake vendor:windows # Download libui.dll for Windows to vendor directory
162
+ rake vendor:all_x64 # Download libui.so, libui.dylib, and libui.dll to...
163
+ rake vendor:linux_x64 # Download libui.so for Linux to vendor directory
164
+ rake vendor:linux_x86 # Download libui.so for Linux to vendor directory
165
+ rake vendor:mac_x64 # Download libui.dylib for Mac to vendor directory
166
+ rake vendor:windows_x64 # Download libui.dll for Windows to vendor directory
167
+ rake vendor:windows_x86 # Download libui.dll for Windows to vendor directory
128
168
  ```
129
169
 
170
+ For example, If you are using a 32-bit (x86) version of Ruby on Windows, type `rake vendor:windows_x86`.
171
+
172
+ Or Set environment variable `LIBUIDIR` to specify the path to the shared library.
173
+
130
174
  ## Contributing
131
175
 
132
- Bug reports and pull requests are welcome on GitHub at https://github.com/kojix2/libui.
176
+ Would you like to add your commits to libui?
177
+ * Please feel free to send us your [pull requests](https://github.com/kojix2/libui/pulls).
178
+ * Small corrections, such as typofixes, are appreciated.
179
+ * Did you find any bugs? Write it in the [issues](https://github.com/kojix2/LibUI/issue) section!
133
180
 
134
181
  ## Acknowledgement
135
182
 
data/lib/libui/utils.rb CHANGED
@@ -8,7 +8,7 @@ module LibUI
8
8
  # Converting camel case to underscore case in ruby
9
9
  # https://stackoverflow.com/questions/1509915/converting-camel-case-to-underscore-case-in-ruby#1509939
10
10
  def underscore(str)
11
- str.gsub(/::/, '/')
11
+ str.gsub(/::/, '/') # Maybe we don't need it.
12
12
  .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
13
13
  .gsub(/([a-z\d])([A-Z])/, '\1_\2')
14
14
  .tr('-', '_')
data/lib/libui/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LibUI
4
- VERSION = '0.0.8'
4
+ VERSION = '0.0.9'
5
5
  end
data/lib/libui.rb CHANGED
@@ -10,14 +10,7 @@ module LibUI
10
10
  attr_accessor :ffi_lib
11
11
  end
12
12
 
13
- lib_name = case RbConfig::CONFIG['host_os']
14
- when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
15
- 'libui.dll'
16
- when /darwin|mac os/
17
- 'libui.dylib'
18
- else
19
- 'libui.so'
20
- end
13
+ lib_name = "libui.#{RbConfig::CONFIG["SOEXT"]}"
21
14
 
22
15
  self.ffi_lib = if ENV['LIBUIDIR'] && !ENV['LIBUIDIR'].empty?
23
16
  File.expand_path(lib_name, ENV['LIBUIDIR'])
@@ -47,9 +40,11 @@ module LibUI
47
40
  # Protect from GC
48
41
  # See https://github.com/kojix2/LibUI/issues/8
49
42
  receiver = args[0]
50
- callbacks = receiver.instance_variable_get(:@callbacks) || []
51
- callbacks << callback
52
- receiver.instance_variable_set(:@callbacks, callback)
43
+ if receiver.instance_variable_defined?(:@callbacks)
44
+ receiver.instance_variable_get(:@callbacks) << callback
45
+ else
46
+ receiver.instance_variable_set(:@callbacks, [callback])
47
+ end
53
48
  callback
54
49
  else
55
50
  arg
@@ -67,10 +62,10 @@ module LibUI
67
62
  module CustomMethods
68
63
  def init(opt = FFI::InitOptions.malloc)
69
64
  i = super(opt)
70
- unless i.size.zero?
71
- warn 'error'
72
- warn UI.free_init_error(init)
73
- end
65
+ return if i.size.zero?
66
+
67
+ warn 'error'
68
+ warn UI.free_init_error(init)
74
69
  end
75
70
  end
76
71
 
data/vendor/libui.so CHANGED
File without changes
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: libui
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - kojix2
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-03 00:00:00.000000000 Z
11
+ date: 2021-08-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -117,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
117
  - !ruby/object:Gem::Version
118
118
  version: '0'
119
119
  requirements: []
120
- rubygems_version: 3.1.4
120
+ rubygems_version: 3.2.22
121
121
  signing_key:
122
122
  specification_version: 4
123
123
  summary: Ruby bindings to libui