libui 0.2.0-x86_64-linux → 0.2.2-x86_64-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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6a4a93bc8fdec0c9c4e2587bb2aa99c0ac11d54e34ae9956e64a9a841a39cac5
4
- data.tar.gz: 9b4caca40127dea74380e48afa011f0162e2169cdba6a4037d52ad1e38247924
3
+ metadata.gz: 19f94055bcaf8d77d1a3400b92cc9c2ea871e2683d1f67bca77e5df92369f7d4
4
+ data.tar.gz: d9868e00988881499b935aea1d5bb2b06534395c1742d2751a7878a75214221b
5
5
  SHA512:
6
- metadata.gz: 9b39de93bfeeb054f86237741ea0b072aead99d1835156fb3f4e18e73f17bbb6e2c8a2592cce0adc31f00c4c1c28d85d31c7d1564a36f074c7bd64664ce39298
7
- data.tar.gz: 333a266fcec1f2108cf7443cbcc56b9f0f86d2620886bdbed5e4bd874e6b18c22a4f493c375da1f9afc38c0595baf1ee32bcc3638f6b1d6780d5e71f868ee15f
6
+ metadata.gz: 9d4601a5b785c8caf0feac08b427b23e5570e0f4f14a426b6fba82e2c919e03afb77ec22c09468e25dbf7bf0049b111bf2ec556674cbe85392f783d7cd46707a
7
+ data.tar.gz: 4b95ac42fd8ec00d13ad5a0943d3b563c52feb7eb46296ce7a1d67eb3d383b04e8d11c6e3cbb19f4e84568c0126cd637275df3013cc7273af96efac8755ea6df
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
@@ -1,7 +1,7 @@
1
1
  # LibUI
2
2
 
3
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)
4
+ [![Gem Version](https://img.shields.io/badge/dynamic/json?label=gem%20version&query=%24%5B0%5D.number&url=https%3A%2F%2Frubygems.org%2Fapi%2Fv1%2Fversions%2Flibui.json&color=brightgreen)](https://rubygems.org/gems/libui/versions)
5
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
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
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)
@@ -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
19
  ```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
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
 
@@ -85,7 +77,7 @@ Compared to the original libui library written in C:
85
77
  - The block will be converted to a Proc object and added as the last argument.
86
78
  - The last argument can still be omitted when nil.
87
79
 
88
- 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.
89
81
 
90
82
  ### DSLs for LibUI
91
83
 
@@ -94,7 +86,6 @@ LibUI is not object-oriented because it is a thin Ruby wrapper (binding) for the
94
86
  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):
95
87
 
96
88
  - [Glimmer DSL for LibUI](https://github.com/AndyObtiva/glimmer-dsl-libui)
97
- - [libui_paradise](https://rubygems.org/gems/libui_paradise)
98
89
 
99
90
  ### Working with fiddle pointers
100
91
 
@@ -104,12 +95,26 @@ UI = LibUI
104
95
  UI.init
105
96
  ```
106
97
 
107
- To convert a pointer to a string:
98
+ Text getter methods such as `label_text`, `entry_text`, and `window_title`
99
+ return `Fiddle::Pointer` objects for strings allocated by libui. Convert the
100
+ pointer to a Ruby string, then release it with `free_text`.
108
101
 
109
102
  ```ruby
110
103
  label = UI.new_label("Ruby")
111
- p pointer = UI.label_text(label) # #<Fiddle::Pointer>
112
- p pointer.to_s # Ruby
104
+ pointer = UI.label_text(label) # #<Fiddle::Pointer>
105
+ text = pointer.to_s
106
+ UI.free_text(pointer)
107
+ p text # Ruby
108
+ ```
109
+
110
+ Use `ensure` if the code between conversion and cleanup can raise:
111
+
112
+ ```ruby
113
+ def ui_text(text_pointer)
114
+ text_pointer.to_s
115
+ ensure
116
+ UI.free_text(text_pointer) if text_pointer && !text_pointer.null?
117
+ end
113
118
  ```
114
119
 
115
120
  If you need to use C structs, you can do the following:
@@ -124,11 +129,15 @@ font_descriptor.to_ptr.free = Fiddle::RUBY_FREE
124
129
 
125
130
  UI.font_button_on_changed(font_button) do
126
131
  UI.font_button_font(font_button, font_descriptor)
127
- p family: font_descriptor.Family.to_s,
128
- size: font_descriptor.Size,
129
- weight: font_descriptor.Weight,
130
- italic: font_descriptor.Italic,
131
- stretch: font_descriptor.Stretch
132
+ begin
133
+ p family: font_descriptor.Family.to_s,
134
+ size: font_descriptor.Size,
135
+ weight: font_descriptor.Weight,
136
+ italic: font_descriptor.Italic,
137
+ stretch: font_descriptor.Stretch
138
+ ensure
139
+ UI.free_font_button_font(font_descriptor)
140
+ end
132
141
  end
133
142
  ```
134
143
 
@@ -206,8 +215,8 @@ If you build libui-ng yourself, set `LIBUIDIR` to the directory containing the c
206
215
  Push a version tag to automatically publish platform-specific gems:
207
216
 
208
217
  ```sh
209
- git tag v0.1.3
210
- git push origin v0.1.3
218
+ git tag v0.2.0
219
+ git push origin v0.2.0
211
220
  ```
212
221
 
213
222
  Requires `RUBYGEMS_API_KEY` repository secret with scoped API key.
@@ -225,9 +234,19 @@ find pkg -name *.gem -exec sh -c "echo; echo \# {}; tar -O -f {} -x data.tar.gz
225
234
  rake release_platform # publish gems
226
235
  ```
227
236
 
237
+ Windows Ruby (x64-mingw32 or x64-mingw-ucrt)
238
+
239
+ ```sh
240
+ gem install rake rubyzip
241
+ GEM_PLATFORM=x64-mingw32 rake vendor:clean
242
+ GEM_PLATFORM=x64-mingw32 rake vendor:auto
243
+ GEM_PLATFORM=x64-mingw32 gem build libui.gemspec
244
+ gem push libui-0.2.0-x64-mingw32.gem
245
+ ```
246
+
228
247
  ### libui or libui-ng
229
248
 
230
- - From version 0.1.X, we plan to support only libui-ng/libui-ng.
249
+ - From version 0.1.X, LibUI supports only libui-ng.
231
250
  - Version 0.0.X only supports andlabs/libui.
232
251
 
233
252
  ## 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
-
7
6
  module FFI
8
7
  extend Fiddle::Importer
9
8
  extend FiddlePatch
@@ -11,9 +11,9 @@ module LibUI
11
11
  def parse_signature(signature, tymap = nil)
12
12
  tymap ||= {}
13
13
  ctype, func, args = case compact(signature)
14
- when /^(?:[\w\*\s]+)\(\*(\w+)\((.*?)\)\)(?:\[\w*\]|\(.*?\));?$/
14
+ when /^(?:[\w*\s]+)\(\*(\w+)\((.*?)\)\)(?:\[\w*\]|\(.*?\));?$/
15
15
  [TYPE_VOIDP, Regexp.last_match(1), Regexp.last_match(2)]
16
- when /^([\w\*\s]+[*\s])(\w+)\((.*?)\);?$/
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
19
  raise("can't parse the function prototype: #{signature}")
@@ -22,12 +22,12 @@ module LibUI
22
22
  callback_argument_types = {} # Added
23
23
  argtype = split_arguments(args).collect.with_index do |arg, idx| # Added with_index
24
24
  # Check if it is a function pointer or not
25
- if arg =~ /\(\*.*\)\(.*\)/ # Added
25
+ if arg =~ /\(\*.*\)\(.*\)/ # Added
26
26
  # From the arguments, create a notation that looks like a function declaration
27
27
  # int(*f)(int *, void *) -> int f(int *, void *)
28
- func_arg = arg.sub('(*', ' ').sub(')', '') # Added
28
+ func_arg = arg.sub('(*', ' ').sub(')', '') # Added
29
29
  # Use Fiddle's parse_signature method again.
30
- callback_argument_types[idx] = parse_signature(func_arg) # Added
30
+ callback_argument_types[idx] = parse_signature(func_arg) # Added
31
31
  end
32
32
  parse_ctype(arg, tymap)
33
33
  end
@@ -41,8 +41,8 @@ module LibUI
41
41
  func = import_function(symname, ctype, argtype, opt[:call_type])
42
42
 
43
43
  # callback_argument_types
44
- func.instance_variable_set(:@callback_argument_types,
45
- callback_argument_types) # Added
44
+ func.instance_variable_set(:@callback_argument_types,
45
+ callback_argument_types) # Added
46
46
  # attr_reader
47
47
  def func.callback_argument_types
48
48
  @callback_argument_types
@@ -68,9 +68,9 @@ module LibUI
68
68
  @func_map[name] = func
69
69
  # define_method(name){|*args,&block| f.call(*args,&block)}
70
70
  begin
71
- /^(.+?):(\d+)/ =~ caller.first
72
- file = Regexp.last_match(1)
73
- line = Regexp.last_match(2).to_i
71
+ location = caller_locations(1, 1).first
72
+ file = location.path
73
+ line = location.lineno
74
74
  rescue StandardError
75
75
  file, line = __FILE__, __LINE__ + 3
76
76
  end
data/lib/libui/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module LibUI
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.2'
3
3
  end
data/lib/libui.rb CHANGED
@@ -59,6 +59,106 @@ module LibUI
59
59
  nil
60
60
  end
61
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)
160
+ end
161
+
62
162
  # Gets the window position.
63
163
  # Coordinates are measured from the top left corner of the screen.
64
164
  # @param w [Fiddle::Pointer] Pointer of uiWindow instance.
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: libui
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.2
5
5
  platform: x86_64-linux
6
6
  authors:
7
7
  - kojix2