libui 0.0.5.alpha → 0.0.6

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: 9942c95097af2b3c542472fa3e144e040cf3f9c0ef253e891d87b79b93070e77
4
- data.tar.gz: a69a733f1cd1dd2274c601422a2cb3a5b91d762055d73fc3e9e9f59e6f11c919
3
+ metadata.gz: f0214c682062d1e669d2ec2df579d91466b2d0330205231d00734e3d9b21fc57
4
+ data.tar.gz: 2bce2e4f6edf26bd2442e7205ef10ad59529f1e16f2a88aa0a282cb61d623ced
5
5
  SHA512:
6
- metadata.gz: 47d42cfbc47996ad411f0ba9e6634378fa2bd088d84bc4179698c4ad3c049a7ce8e75218c8fd93538362d01961c9ca4d278aa2c60a5074a1fea532d4b22841b8
7
- data.tar.gz: 25c390450f42ff51ee05a9f5c7c9409c16860ac1ae3351e0d85aa30ad1d753f7cad2e1091ff9193bdf85cb21d77c344fbe1acdb5e429746e9d69574b59388379
6
+ metadata.gz: f700b08bb46f282b7298f7530bbbade2a59fcde144e54af97bb01a1766a98b3a133b10e064cd62a69621e2d61ff9d587bff17d850f96bb23b4e5c2ee101f97a7
7
+ data.tar.gz: 8571472b2ceb6fa2cd5d6627fce64c896e2ae651012fd8d949f9a94a6cf70dc48df6af7f379652c956b3b1e5e6725fb14465d616abdae776e9ec635c0c4150f9
data/README.md CHANGED
@@ -8,15 +8,95 @@
8
8
  ## Installation
9
9
 
10
10
  ```sh
11
- gem install libui --pre
11
+ gem install libui
12
12
  ```
13
13
 
14
- The libui gem package contains the official release of the libui shared library version 4.1 for Windows, Mac, and Linux.
14
+ The libui gem uses the standard Ruby library [Fiddle](https://github.com/ruby/fiddle) to call C functions. And this gem contains the official release of the libui shared library version 4.1 for Windows, Mac, and Linux. That means there is no need to install anything other than this gem.
15
15
 
16
16
  ## Usage
17
17
 
18
+ ```ruby
19
+ require 'libui'
20
+ UI = LibUI
21
+
22
+ UI.init
23
+
24
+ main_window = UI.new_window('hello world', 300, 200, 1)
25
+ UI.window_on_closing(main_window) do
26
+ puts 'Bye Bye'
27
+ UI.control_destroy(main_window)
28
+ UI.quit
29
+ 0
30
+ end
31
+
32
+ button = UI.new_button('Button')
33
+ UI.button_on_clicked(button) do
34
+ UI.msg_box(main_window, 'Information', 'You clicked the button')
35
+ 0
36
+ end
37
+
38
+ UI.window_set_child(main_window, button)
39
+ UI.control_show(main_window)
40
+
41
+ UI.main
42
+ UI.quit
43
+ ```
44
+
18
45
  See [examples](https://github.com/kojix2/libui/tree/main/examples) directory.
19
46
 
47
+ ### General Rules
48
+
49
+ * The method names are snake_case.
50
+ * If the last argument is nil, it can be omitted.
51
+ * You can pass a block as a callback.
52
+ * Please return 0 explicitly in the block.
53
+ * The block will be converted to a Proc object and added to the last argument.
54
+ * Even in that case, it is possible to omit the last argument nil.
55
+
56
+ ### Not object oriented?
57
+
58
+ * At the moment, it is not object-oriented.
59
+ * Instead of providing a half-baked object-oriented approach, leave it as is.
60
+
61
+ ### How to use fiddle pointers?
62
+
63
+ ```ruby
64
+ require 'libui'
65
+ UI = LibUI
66
+ UI.init
67
+ ```
68
+
69
+ Convert a pointer to a string.
70
+
71
+ ```ruby
72
+ label = UI.new_label("Ruby")
73
+ p pointer = UI.label_text(label) # #<Fiddle::Pointer>
74
+ p pointer.to_s # Ruby
75
+ ```
76
+
77
+ If you need to use C structs, you can do the following.
78
+
79
+ ```ruby
80
+ font_button = UI.new_font_button
81
+
82
+ # Allocate memory
83
+ font_descriptor = UI::FFI::FontDescriptor.malloc
84
+
85
+ UI.font_button_on_changed(font_button) do
86
+ UI.font_button_font(font_button, font_descriptor)
87
+ p family: font_descriptor.Family.to_s,
88
+ size: font_descriptor.Size,
89
+ weight: font_descriptor.Weight,
90
+ italic: font_descriptor.Italic,
91
+ stretch: font_descriptor.Stretch
92
+ end
93
+ ```
94
+
95
+ ### How to create an executable (.exe) on Windows
96
+
97
+ OCRA (One-Click Ruby Application) builds Windows executables from Ruby source code.
98
+ * https://github.com/larsch/ocra/
99
+
20
100
  ## Development
21
101
 
22
102
  ```sh
@@ -27,7 +107,16 @@ bundle exec rake vendor:all
27
107
  bundle exec rake test
28
108
  ```
29
109
 
30
- * Keep it simple.
110
+ Use the following rake tasks to download the libui binary files and save them in the vendor directory.
111
+
112
+ `rake -T`
113
+
114
+ ```
115
+ rake vendor:all # Download libui.so, libui.dylib, and libui.dll to ve...
116
+ rake vendor:linux # Download libui.so for Linux to vendor directory
117
+ rake vendor:mac # Download libui.dylib for Mac to vendor directory
118
+ rake vendor:windows # Download libui.dll for Windows to vendor directory
119
+ ```
31
120
 
32
121
  ## Contributing
33
122
 
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'libui/version'
4
+ require_relative 'libui/utils'
4
5
 
5
6
  module LibUI
6
7
  class Error < StandardError; end
@@ -28,14 +29,7 @@ module LibUI
28
29
 
29
30
  class << self
30
31
  FFI.func_map.each_key do |original_method_name|
31
- # Convert snake_case to CamelCase.
32
- name = original_method_name.delete_prefix('ui')
33
- .gsub(/::/, '/')
34
- .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
35
- .gsub(/([a-z\d])([A-Z])/, '\1_\2')
36
- .tr('-', '_')
37
- .downcase
38
-
32
+ name = Utils.convert_to_ruby_method(original_method_name)
39
33
  func = FFI.func_map[original_method_name]
40
34
 
41
35
  define_method(name) do |*args, &blk|
@@ -35,17 +35,17 @@ module Fiddle
35
35
  def split_signature(signature)
36
36
  case compact(signature)
37
37
  when /^(?:[\w*\s]+)\(\*(\w+)\((.*?)\)\)(?:\[\w*\]|\(.*?\));?$/
38
+ ret = TYPE_VOIDP
38
39
  func = Regexp.last_match(1)
39
40
  args = Regexp.last_match(2)
40
- [TYPE_VOIDP, func, args]
41
41
  when /^([\w*\s]+[*\s])(\w+)\((.*?)\);?$/
42
42
  ret = Regexp.last_match(1).strip
43
43
  func = Regexp.last_match(2)
44
44
  args = Regexp.last_match(3)
45
- [ret, func, args]
46
45
  else
47
46
  raise("can't parse the function prototype: #{signature}")
48
47
  end
48
+ [ret, func, args]
49
49
  end
50
50
 
51
51
  def extern(signature, *opts)
@@ -95,6 +95,10 @@ module LibUI
95
95
  rescue StandardError => e
96
96
  warn "#{e.class.name}: #{e.message}"
97
97
  end
98
+
99
+ def ffi_methods
100
+ @ffi_methods ||= func_map.each_key.to_a
101
+ end
98
102
  end
99
103
 
100
104
  typealias('uint32_t', 'unsigned int')
@@ -0,0 +1,19 @@
1
+ module LibUI
2
+ module Utils
3
+ class << self
4
+ def convert_to_ruby_method(original_method_name)
5
+ underscore(original_method_name.delete_prefix('ui'))
6
+ end
7
+
8
+ # Converting camel case to underscore case in ruby
9
+ # https://stackoverflow.com/questions/1509915/converting-camel-case-to-underscore-case-in-ruby#1509939
10
+ def underscore(str)
11
+ str.gsub(/::/, '/')
12
+ .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
13
+ .gsub(/([a-z\d])([A-Z])/, '\1_\2')
14
+ .tr('-', '_')
15
+ .downcase
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LibUI
4
- VERSION = '0.0.5.alpha'
4
+ VERSION = '0.0.6'
5
5
  end
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.5.alpha
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - kojix2
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-12 00:00:00.000000000 Z
11
+ date: 2020-12-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -91,6 +91,7 @@ files:
91
91
  - README.md
92
92
  - lib/libui.rb
93
93
  - lib/libui/ffi.rb
94
+ - lib/libui/utils.rb
94
95
  - lib/libui/version.rb
95
96
  - vendor/LICENSE
96
97
  - vendor/README.md
@@ -112,9 +113,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
112
113
  version: '2.5'
113
114
  required_rubygems_version: !ruby/object:Gem::Requirement
114
115
  requirements:
115
- - - ">"
116
+ - - ">="
116
117
  - !ruby/object:Gem::Version
117
- version: 1.3.1
118
+ version: '0'
118
119
  requirements: []
119
120
  rubygems_version: 3.1.4
120
121
  signing_key: