libui_paradise 0.2.49 → 0.3.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +241 -116
  3. data/bin/libui_message +7 -0
  4. data/doc/README.gen +191 -56
  5. data/doc/SNIPPETS.md +1 -30
  6. data/doc/todo/todo.md +13 -8
  7. data/lib/libui_paradise/base/base.rb +64 -25
  8. data/lib/libui_paradise/colours/colours.rb +12 -0
  9. data/lib/libui_paradise/examples/complex/003_open_file_button_example.rb +2 -4
  10. data/lib/libui_paradise/examples/complex/010_table_example.rb +143 -49
  11. data/lib/libui_paradise/examples/simple/003_fancy_text_example.rb +18 -9
  12. data/lib/libui_paradise/examples/simple/005_text_drawing_example.rb +8 -8
  13. data/lib/libui_paradise/examples/simple/007_control_gallery.rb +19 -13
  14. data/lib/libui_paradise/examples/simple/010_font_button.rb +31 -0
  15. data/lib/libui_paradise/examples/simple/011_simple_notepad.rb +24 -0
  16. data/lib/libui_paradise/examples/simple/012_table_example.rb +71 -0
  17. data/lib/libui_paradise/extensions/extensions.rb +961 -11
  18. data/lib/libui_paradise/extensions/toplevel_counters.rb +58 -0
  19. data/lib/libui_paradise/fiddle/{pointer.rb → fiddle.rb} +162 -144
  20. data/lib/libui_paradise/generic_window/generic_window.rb +1 -1
  21. data/lib/libui_paradise/images/README.md +5 -2
  22. data/lib/libui_paradise/libui_classes/box.rb +3 -2
  23. data/lib/libui_paradise/libui_classes/grid.rb +4 -1
  24. data/lib/libui_paradise/libui_classes/libui_classes.rb +113 -78
  25. data/lib/libui_paradise/project/project.rb +5 -1
  26. data/lib/libui_paradise/prototype/prototype.rb +1 -3
  27. data/lib/libui_paradise/requires/require_the_libui_paradise_project.rb +1 -1
  28. data/lib/libui_paradise/version/version.rb +2 -2
  29. data/lib/libui_paradise.rb +0 -0
  30. data/libui_paradise.gemspec +5 -4
  31. metadata +18 -27
  32. data/lib/libui_paradise/extensions/counters.rb +0 -58
  33. data/lib/libui_paradise/extensions/hash_fiddle_pointer_widgets.rb +0 -150
  34. data/lib/libui_paradise/extensions/misc.rb +0 -754
  35. data/lib/libui_paradise/toplevel_methods/misc.rb +0 -13
@@ -14,8 +14,8 @@ outer_vbox = ui_padded_vbox
14
14
  button_open_file = ui_button('Open file')
15
15
  button_open_file.on_clicked {
16
16
  begin
17
- #filename = ui_open_file(window).to_s
18
- filename = ::LibUI.open_file(main_window).to_s
17
+ # filename = ui_open_file(window).to_s
18
+ filename = LibUI.open_file(main_window).to_s
19
19
  e "The filename was: #{filename}"
20
20
  rescue ArgumentError => error # Rescue from "NULL pointer given"
21
21
  pp error
@@ -26,7 +26,6 @@ outer_vbox << button_open_file
26
26
  window.child = outer_vbox
27
27
  window.intelligent_quit
28
28
 
29
-
30
29
  if false
31
30
  LibUI.button_on_clicked(button) {
32
31
  result = ::LibUI.open_file(main_window).to_s
@@ -34,5 +33,4 @@ LibUI.button_on_clicked(button) {
34
33
  e 'The file exists. \o/'
35
34
  end
36
35
  }
37
-
38
36
  end
@@ -2,54 +2,148 @@
2
2
  # Encoding: UTF-8
3
3
  # frozen_string_literal: true
4
4
  # =========================================================================== #
5
- # Todo:
6
- #
7
- # - Add editable entry to the table
8
- #
9
- # =========================================================================== #
10
5
  # require 'libui_paradise/010_table_example.rb'
11
6
  # =========================================================================== #
12
- require 'libui_paradise/autoinclude'
13
-
14
- main_window = padded_window('30) Table example', 300, 200, 1)
15
- hbox = padded_hbox
16
- data = [
17
- %w( cat calm meow ),
18
- %w( dog loyal woof ),
19
- %w( chicken bird cock-a-doodle-doo ),
20
- %w( horse fast neigh ),
21
- %w( cow slow moo )
22
- ]
23
-
24
- # Protect BlockCaller objects from garbage collection.
25
- @block_callers = []
26
- def rbcallback(*args, &block)
27
- args << [0] if args.size == 1 # Argument types are ommited
28
- block_caller = Fiddle::Closure::BlockCaller.new(*args, &block)
29
- @block_callers << block_caller
30
- block_caller
31
- end
32
-
33
- model_handler = LibUI::FFI::TableModelHandler.malloc
34
- model_handler.to_ptr.free = Fiddle::RUBY_FREE
35
-
36
- model_handler.NumColumns = rbcallback(4) { 2 }
37
- model_handler.ColumnType = rbcallback(4) { 0 }
38
- model_handler.NumRows = rbcallback(4) { 5 }
39
- model_handler.CellValue = rbcallback(1, [1, 1, 4, 4]) do |_, _, row, column|
40
- LibUI.new_table_value_string(data[row][column])
41
- end
42
- model_handler.SetCellValue = rbcallback(0, [0]) {}
43
-
44
- model = LibUI.new_table_model(model_handler)
45
-
46
- table_params = ui_table_params_malloc(model)
47
-
48
- table = ui_table(table_params)
49
- table.append_text_column('Animal', 0, -1)
50
- table.append_text_column('Description', 1, -1)
51
- table.append_text_column('Fancy Stuff', 2, -1)
52
-
53
- hbox.add(table, 1)
54
- main_window.child = hbox
55
- main_window.intelligent_quit
7
+ require 'libui_paradise/base/base.rb'
8
+
9
+ module LibuiParadise
10
+
11
+ module GUI
12
+
13
+ module LibUI
14
+
15
+ class TableExample < Base # === LibuiParadise::GUI::LibUI::TableExample
16
+
17
+ # ========================================================================= #
18
+ # === DATA
19
+ # ========================================================================= #
20
+ DATA = [
21
+ %w( cat calm meow ),
22
+ %w( dog loyal woof ),
23
+ %w( chicken bird cock-a-doodle-doo ),
24
+ %w( horse fast neigh ),
25
+ %w( cow slow moo ),
26
+ %w( one two three ),
27
+ %w( 1 2 3 ),
28
+ %w( 4 5 6 ),
29
+ %w( 7 8 9 )
30
+ ]
31
+
32
+ alias e puts
33
+
34
+ require 'libui_paradise'
35
+ include LibuiParadise::Extensions
36
+
37
+ # ========================================================================= #
38
+ # === TITLE
39
+ # ========================================================================= #
40
+ TITLE = 'A TableExample for LibUI'
41
+
42
+ # ========================================================================= #
43
+ # === WIDTH
44
+ # ========================================================================= #
45
+ WIDTH = 800
46
+
47
+ # ========================================================================= #
48
+ # === HEIGHT
49
+ # ========================================================================= #
50
+ HEIGHT = 520
51
+
52
+ # ========================================================================= #
53
+ # === initialize
54
+ # ========================================================================= #
55
+ def initialize(
56
+ run_already = true
57
+ )
58
+ reset
59
+ run if run_already
60
+ end
61
+
62
+ # ========================================================================= #
63
+ # === reset (reset tag)
64
+ # ========================================================================= #
65
+ def reset
66
+ title_width_height(TITLE, WIDTH, HEIGHT)
67
+ end
68
+
69
+ # ========================================================================= #
70
+ # === create_skeleton (create tag, skeleton tag)
71
+ # ========================================================================= #
72
+ def create_skeleton
73
+ # ======================================================================= #
74
+ # === @window
75
+ # ======================================================================= #
76
+ @window = ui_padded_main_window(title?, width?, height?, 0)
77
+ # ======================================================================= #
78
+ # Protects BlockCaller objects from garbage collection.
79
+ # ======================================================================= #
80
+ @block_callers = []
81
+ end
82
+
83
+ # ========================================================================= #
84
+ # === rbcallback
85
+ # ========================================================================= #
86
+ def rbcallback(*args, &block)
87
+ args << [0] if args.size == 1 # Argument types are omitted
88
+ block_caller = Fiddle::Closure::BlockCaller.new(*args, &block)
89
+ @block_callers << block_caller
90
+ block_caller
91
+ end
92
+
93
+ # ========================================================================= #
94
+ # === run
95
+ # ========================================================================= #
96
+ def run
97
+ super()
98
+ outer_vbox = padded_vbox
99
+ # ======================================================================= #
100
+ # First add the two buttons on top:
101
+ # ======================================================================= #
102
+ outer_vbox.add_hsep
103
+
104
+ grid = padded_grid
105
+ # widget, left, top, xspan, yspan, hexpand, halign, vexpand, valign
106
+ grid.ui_grid_append(text('Testing tables'), 0, 0, 1, 1, 0, 0.5, 1, 0)
107
+ outer_vbox.minimal(grid)
108
+
109
+ model_handler = ::LibUI::FFI::TableModelHandler.malloc
110
+ model_handler.to_ptr.free = Fiddle::RUBY_FREE
111
+ model_handler.NumColumns = rbcallback(4) { 2 }
112
+ model_handler.ColumnType = rbcallback(4) { 0 }
113
+ model_handler.NumRows = rbcallback(4) { 5 }
114
+ model_handler.CellValue = rbcallback(1, [1, 1, 4, 4]) do |_, _, row, column|
115
+ ::LibUI.new_table_value_string(
116
+ DATA[row][column] # Pass the data here.
117
+ )
118
+ end
119
+ model_handler.SetCellValue = rbcallback(0, [0]) {}
120
+
121
+ model = ::LibUI.new_table_model(model_handler)
122
+ table_params = ui_table_params_malloc(model)
123
+
124
+ table = create_table(table_params)
125
+ table.append_text_column('Animal', 0)
126
+ table.append_text_column('Description', 1)
127
+ table.append_text_column('TEST', 2)
128
+ # table.append_text_column('TEST', 3, -1) # This would crash it.
129
+ # ::LibUI.table_append_text_column(table, 'Animal', 0, -1)
130
+
131
+ outer_vbox.maximal(table)
132
+ button1 = button('Show the current selection in the table')
133
+ button1.on_clicked {
134
+ e 'This is currently not implemented.'
135
+ }
136
+ outer_vbox.minimal(
137
+ button1
138
+ )
139
+ outer_vbox.minimal(quit_button)
140
+ @window.add(outer_vbox)
141
+ @window.intelligent_exit
142
+ free_table_model(model)
143
+ end
144
+
145
+ end; end; end; end
146
+
147
+ if __FILE__ == $PROGRAM_NAME
148
+ LibuiParadise::GUI::LibUI::TableExample.new
149
+ end
@@ -118,24 +118,26 @@ end
118
118
  # =========================================================================== #
119
119
  # === on_font_changed
120
120
  # =========================================================================== #
121
- def on_font_changed(area)
122
- UI.area_queue_redraw_all(area)
121
+ def on_font_changed(i)
122
+ UI.area_queue_redraw_all(i)
123
123
  end
124
124
 
125
125
  # =========================================================================== #
126
126
  # === on_combobox_selected
127
127
  # =========================================================================== #
128
- def on_combobox_selected(area)
129
- UI.area_queue_redraw_all(area)
128
+ def on_combobox_selected(i)
129
+ UI.area_queue_redraw_all(i)
130
130
  end
131
131
 
132
+ # =========================================================================== #
132
133
  # === draw_event
134
+ # =========================================================================== #
133
135
  def draw_event(adp, attr_str, font_button, alignment)
134
136
  area_draw_params = UI::FFI::AreaDrawParams.new(adp)
137
+
135
138
  default_font = UI::FFI::FontDescriptor.malloc
136
139
  default_font.to_ptr.free = Fiddle::RUBY_FREE
137
- default_font = UI::FFI::FontDescriptor.malloc
138
- default_font.to_ptr.free = Fiddle::RUBY_FREE
140
+
139
141
  params = UI::FFI::DrawTextLayoutParams.malloc
140
142
  params.to_ptr.free = Fiddle::RUBY_FREE
141
143
 
@@ -193,15 +195,20 @@ LibUI.box_set_padded(vbox, 1)
193
195
  LibUI.box_append(hbox, vbox, 0)
194
196
 
195
197
  @font_button = LibUI.new_font_button
196
- LibUI.font_button_on_changed(@font_button) { on_font_changed(@area) }
198
+ LibUI.font_button_on_changed(@font_button) {
199
+ # Invoke a method here:
200
+ on_font_changed(@area)
201
+ }
197
202
  LibUI.box_append(vbox, @font_button, 0)
198
203
 
199
204
  form = LibUI.new_form
200
205
  LibUI.form_set_padded(form, 1)
201
206
  LibUI.box_append(vbox, form, 0)
202
207
 
208
+ # =========================================================================== #
203
209
  # Add a combobox entry next.
204
210
  # @alignment = ui_combobox(%w( Left Center Right ))
211
+ # =========================================================================== #
205
212
  @alignment = LibUI.new_combobox
206
213
  LibUI.combobox_append(@alignment, 'Left')
207
214
  LibUI.combobox_append(@alignment, 'Center')
@@ -210,11 +217,13 @@ LibUI.combobox_set_selected(@alignment, 0)
210
217
  LibUI.combobox_on_selected(@alignment) { on_combobox_selected(@area) }
211
218
  LibUI.form_append(form, 'Alignment', @alignment, 0)
212
219
 
220
+ # =========================================================================== #
221
+ # Add a new area next:
222
+ # =========================================================================== #
213
223
  @area = LibUI.new_area(handler)
214
224
  LibUI.box_append(hbox, @area, 1)
215
225
 
216
226
  LibUI.control_show(main_window)
217
227
  LibUI.main
218
-
219
228
  LibUI.free_attributed_string(@attr_str)
220
- LibUI.uninit
229
+ LibUI.uninit
@@ -30,15 +30,15 @@ def make_attribute_string
30
30
 
31
31
  attr1 = LibUI.new_family_attribute('Courier New')
32
32
  append_with_attribute(attr_str, 'font family', attr1, nil)
33
- UI.attributed_string_append_unattributed(attr_str, ', ')
33
+ LibUI.attributed_string_append_unattributed(attr_str, ', ')
34
34
 
35
35
  attr1 = LibUI.new_size_attribute(18)
36
36
  append_with_attribute(attr_str, 'font size', attr1, nil)
37
- UI.attributed_string_append_unattributed(attr_str, ', ')
37
+ LibUI.attributed_string_append_unattributed(attr_str, ', ')
38
38
 
39
- attr1 = UI.new_weight_attribute(UI::TextWeightBold)
39
+ attr1 = LibUI.new_weight_attribute(UI::TextWeightBold)
40
40
  append_with_attribute(attr_str, 'font weight', attr1, nil)
41
- UI.attributed_string_append_unattributed(attr_str, ', ')
41
+ LibUI.attributed_string_append_unattributed(attr_str, ', ')
42
42
 
43
43
  attr1 = UI.new_italic_attribute(UI::TextItalicItalic)
44
44
  append_with_attribute(attr_str, 'font italicness', attr1, nil)
@@ -137,19 +137,19 @@ handler.MouseCrossed = do_nothing
137
137
  handler.DragBroken = do_nothing
138
138
  handler.KeyEvent = key_event
139
139
 
140
- UI.on_should_quit do
140
+ UI.on_should_quit {
141
141
  UI.control_destroy(main_window)
142
- end
142
+ }
143
143
 
144
144
  @attr_str = make_attribute_string
145
145
 
146
146
  main_window = UI.new_window('Text-Drawing Example', 640, 480, 1)
147
147
  UI.window_set_margined(main_window, 1)
148
- UI.window_on_closing(main_window) do
148
+ UI.window_on_closing(main_window) {
149
149
  UI.control_destroy(main_window)
150
150
  UI.quit
151
151
  0
152
- end
152
+ }
153
153
 
154
154
  hbox = UI.new_horizontal_box
155
155
  UI.box_set_padded(hbox, 1)
@@ -150,40 +150,46 @@ UI.combobox_append(cbox, 'combobox Item 1')
150
150
  UI.combobox_append(cbox, 'combobox Item 2')
151
151
  UI.combobox_append(cbox, 'combobox Item 3')
152
152
  UI.box_append(inner, cbox, 0)
153
- UI.combobox_on_selected(cbox) do |ptr|
153
+ UI.combobox_on_selected(cbox) { |ptr|
154
154
  puts "New combobox selection: #{UI.combobox_selected(ptr)}"
155
- end
155
+ }
156
156
 
157
+ # =========================================================================== #
157
158
  # Editable Combobox
159
+ # =========================================================================== #
158
160
  ebox = UI.new_editable_combobox
159
161
  UI.editable_combobox_append(ebox, 'Editable Item 1')
160
162
  UI.editable_combobox_append(ebox, 'Editable Item 2')
161
163
  UI.editable_combobox_append(ebox, 'Editable Item 3')
162
164
  UI.box_append(inner, ebox, 0)
163
165
 
166
+ # =========================================================================== #
164
167
  # Radio Buttons
168
+ # =========================================================================== #
165
169
  rb = UI.new_radio_buttons
166
170
  UI.radio_buttons_append(rb, 'Radio Button 1')
167
171
  UI.radio_buttons_append(rb, 'Radio Button 2')
168
172
  UI.radio_buttons_append(rb, 'Radio Button 3')
169
173
  UI.box_append(inner, rb, 1)
170
174
 
175
+ # =========================================================================== #
171
176
  # Tab
172
- tab = UI.new_tab
173
- hbox1 = UI.new_horizontal_box
174
- hbox2 = UI.new_horizontal_box
175
- UI.tab_append(tab, 'Page 1', hbox1)
176
- UI.tab_append(tab, 'Page 2', hbox2)
177
- UI.tab_append(tab, 'Page 3', UI.new_horizontal_box)
178
- UI.box_append(inner2, tab, 1)
177
+ # =========================================================================== #
178
+ tab = LibUI.new_tab
179
+ hbox1 = LibUI.new_horizontal_box
180
+ hbox2 = LibUI.new_horizontal_box
181
+ LibUI.tab_append(tab, 'Page 1', hbox1)
182
+ LibUI.tab_append(tab, 'Page 2', hbox2)
183
+ LibUI.tab_append(tab, 'Page 3', UI.new_horizontal_box)
184
+ LibUI.box_append(inner2, tab, 1)
179
185
 
180
186
  # Text Entry
181
187
  text_entry = UI.new_entry
182
- UI.entry_set_text text_entry, 'Please enter your feelings'
183
- UI.entry_on_changed(text_entry) do |ptr|
188
+ LibUI.entry_set_text text_entry, 'Please enter your feelings'
189
+ LibUI.entry_on_changed(text_entry) { |ptr|
184
190
  puts "Current textbox data: '#{UI.entry_text(ptr)}'"
185
- end
186
- UI.box_append(hbox1, text_entry, 1)
191
+ }
192
+ LibUI.box_append(hbox1, text_entry, 1)
187
193
 
188
194
  UI.control_show(MAIN_WINDOW)
189
195
 
@@ -0,0 +1,31 @@
1
+ require 'libui'
2
+
3
+ UI = LibUI
4
+
5
+ UI.init
6
+
7
+ main_window = UI.new_window('Font example', 300, 200, 1)
8
+
9
+ font_button = UI.new_font_button
10
+ font_descriptor = UI::FFI::FontDescriptor.malloc
11
+ font_descriptor.to_ptr.free = Fiddle::RUBY_FREE
12
+ UI.font_button_on_changed(font_button) {
13
+ UI.font_button_font(font_button, font_descriptor) # Add the font_description here.
14
+ p family: font_descriptor.Family.to_s,
15
+ size: font_descriptor.Size,
16
+ weight: font_descriptor.Weight,
17
+ italic: font_descriptor.Italic,
18
+ stretch: font_descriptor.Stretch
19
+ }
20
+
21
+ UI.window_on_closing(main_window) do
22
+ puts 'Bye Bye'
23
+ UI.quit
24
+ 1
25
+ end
26
+
27
+ UI.window_set_child(main_window, font_button)
28
+ UI.control_show(main_window)
29
+
30
+ UI.main
31
+ UI.uninit
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'libui'
4
+
5
+ UI = LibUI
6
+
7
+ UI.init
8
+
9
+ main_window = UI.new_window('Notepad', 500, 300, 1)
10
+ UI.window_on_closing(main_window) do
11
+ puts 'Bye Bye'
12
+ UI.quit
13
+ 1
14
+ end
15
+
16
+ vbox = UI.new_vertical_box
17
+ UI.window_set_child(main_window, vbox)
18
+
19
+ entry = UI.new_non_wrapping_multiline_entry
20
+ UI.box_append(vbox, entry, 1)
21
+
22
+ UI.control_show(main_window)
23
+ UI.main
24
+ UI.uninit
@@ -0,0 +1,71 @@
1
+ # =========================================================================== #
2
+ # === 012_table_example.rb
3
+ # =========================================================================== #
4
+
5
+ # =========================================================================== #
6
+ # Taken from kojix2' upstream code.
7
+ # =========================================================================== #
8
+ require 'libui'
9
+
10
+ alias e puts
11
+
12
+ UI = LibUI
13
+
14
+ LibUI.init
15
+
16
+ main_window = LibUI.new_window('Animal sounds', 300, 200, 1)
17
+
18
+ hbox = LibUI.new_horizontal_box
19
+ LibUI.window_set_child(main_window, hbox)
20
+
21
+ data = [
22
+ %w( cat meow ),
23
+ %w( dog woof ),
24
+ %w( chicken cock-a-doodle-doo ),
25
+ %w( horse neigh ),
26
+ %w( cow moo )
27
+ ]
28
+
29
+ # Protects BlockCaller objects from garbage collection.
30
+ @block_callers = []
31
+ def rbcallback(*args, &block)
32
+ args << [0] if args.size == 1 # Argument types are omitted
33
+ block_caller = Fiddle::Closure::BlockCaller.new(*args, &block)
34
+ @block_callers << block_caller
35
+ block_caller
36
+ end
37
+
38
+ model_handler = UI::FFI::TableModelHandler.malloc
39
+ model_handler.to_ptr.free = Fiddle::RUBY_FREE
40
+ model_handler.NumColumns = rbcallback(4) { 2 }
41
+ model_handler.ColumnType = rbcallback(4) { 0 }
42
+ model_handler.NumRows = rbcallback(4) { 5 }
43
+ model_handler.CellValue = rbcallback(1, [1, 1, 4, 4]) do |_, _, row, column|
44
+ UI.new_table_value_string(data[row][column])
45
+ end
46
+ model_handler.SetCellValue = rbcallback(0, [0]) {}
47
+
48
+ # Create the table model:
49
+ model = UI.new_table_model(model_handler)
50
+
51
+ table_params = UI::FFI::TableParams.malloc
52
+ table_params.to_ptr.free = Fiddle::RUBY_FREE
53
+ table_params.Model = model
54
+ table_params.RowBackgroundColorModelColumn = -1
55
+
56
+ table = UI.new_table(table_params)
57
+ LibUI.table_append_text_column(table, 'Animal', 0, -1)
58
+ LibUI.table_append_text_column(table, 'Description', 1, -1)
59
+
60
+ LibUI.box_append(hbox, table, 1)
61
+ LibUI.control_show(main_window)
62
+
63
+ LibUI.window_on_closing(main_window) {
64
+ e 'Bye Bye'
65
+ UI.quit
66
+ 1
67
+ }
68
+
69
+ UI.main
70
+ UI.free_table_model(model)
71
+ UI.uninit