glimmer-dsl-libui 0.4.11 → 0.4.15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +31 -0
  3. data/README.md +473 -57
  4. data/VERSION +1 -1
  5. data/examples/basic_image.rb +5 -3
  6. data/examples/basic_image2.rb +1 -3
  7. data/examples/basic_image3.rb +3 -3
  8. data/examples/basic_image4.rb +0 -3
  9. data/examples/basic_image5.rb +0 -2
  10. data/examples/basic_table_color.rb +104 -26
  11. data/examples/basic_table_color2.rb +2 -14
  12. data/examples/basic_table_color3.rb +37 -0
  13. data/examples/basic_table_image.rb +1 -1
  14. data/examples/basic_table_image2.rb +2 -14
  15. data/examples/basic_table_image3.rb +44 -0
  16. data/examples/basic_table_image_text.rb +1 -2
  17. data/examples/basic_table_image_text2.rb +2 -13
  18. data/examples/basic_table_image_text3.rb +44 -0
  19. data/examples/cpu_percentage.rb +1 -1
  20. data/examples/editable_column_table.rb +5 -0
  21. data/examples/form_table.rb +10 -4
  22. data/examples/form_table2.rb +12 -6
  23. data/examples/form_table3.rb +9 -3
  24. data/examples/form_table4.rb +9 -3
  25. data/examples/form_table5.rb +9 -3
  26. data/examples/meta_example.rb +3 -1
  27. data/glimmer-dsl-libui.gemspec +0 -0
  28. data/lib/glimmer/libui/attributed_string.rb +17 -8
  29. data/lib/glimmer/libui/control_proxy/area_proxy.rb +17 -17
  30. data/lib/glimmer/libui/control_proxy/box.rb +1 -0
  31. data/lib/glimmer/libui/control_proxy/column/background_color_column_proxy.rb +4 -0
  32. data/lib/glimmer/libui/control_proxy/column/button_column_proxy.rb +1 -29
  33. data/lib/glimmer/libui/control_proxy/form_proxy.rb +1 -0
  34. data/lib/glimmer/libui/control_proxy/image_proxy.rb +92 -10
  35. data/lib/glimmer/libui/control_proxy/menu_item_proxy/quit_menu_item_proxy.rb +18 -8
  36. data/lib/glimmer/libui/control_proxy/open_type_features_proxy.rb +11 -2
  37. data/lib/glimmer/libui/control_proxy/open_type_tag_proxy.rb +2 -0
  38. data/lib/glimmer/libui/control_proxy/path_proxy.rb +2 -0
  39. data/lib/glimmer/libui/control_proxy/table_proxy.rb +14 -12
  40. data/lib/glimmer/libui/control_proxy/text_proxy.rb +2 -0
  41. data/lib/glimmer/libui/control_proxy/window_proxy.rb +34 -35
  42. data/lib/glimmer/libui/control_proxy.rb +45 -9
  43. data/lib/glimmer/libui/shape.rb +1 -0
  44. data/lib/glimmer/libui.rb +2 -2
  45. metadata +5 -2
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.11
1
+ 0.4.15
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  require 'glimmer-dsl-libui'
4
2
 
5
3
  include Glimmer
@@ -14,6 +12,10 @@ window('Basic Image', 96, 96) {
14
12
  # image pixel rendered. Check basic_image2.rb for a faster alternative using on_draw manually.
15
13
  #
16
14
  # It is recommended to pass width/height args to shrink image and achieve faster performance.
17
- image(File.expand_path('../icons/glimmer.png', __dir__), 96, 96)
15
+ image(File.expand_path('../icons/glimmer.png', __dir__), height: 96) # width is automatically calculated from height while preserving original aspect ratio
16
+ # image(File.expand_path('../icons/glimmer.png', __dir__), width: 96, height: 96) # you can specify both width, height options as alternative
17
+ # image(File.expand_path('../icons/glimmer.png', __dir__), 96, 96) # you can specify width, height args as alternative
18
+ # image(File.expand_path('../icons/glimmer.png', __dir__), 0, 0, 96, 96) # you can specify x, y, width, height args as alternative
19
+ # image(File.expand_path('../icons/glimmer.png', __dir__), x: 0, y: 0, width: 96, height: 96) # you can specify x, y, width, height options as alternative
18
20
  }
19
21
  }.show
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  require 'glimmer-dsl-libui'
4
2
 
5
3
  include Glimmer
@@ -7,7 +5,7 @@ include Glimmer
7
5
  window('Basic Image', 96, 96) {
8
6
  area {
9
7
  on_draw do |area_draw_params|
10
- image(File.expand_path('../icons/glimmer.png', __dir__), 96, 96)
8
+ image(File.expand_path('../icons/glimmer.png', __dir__), height: 96)
11
9
  end
12
10
  }
13
11
  }.show
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  require 'glimmer-dsl-libui'
4
2
 
5
3
  include Glimmer
@@ -16,7 +14,9 @@ window('Basic Image', 96, 96) {
16
14
  # It is recommended to pass width/height args to shrink image and achieve faster performance.
17
15
  image {
18
16
  file File.expand_path('../icons/glimmer.png', __dir__)
19
- width 96
17
+ # x 0 # default
18
+ # y 0 # default
19
+ # width 96 # gets calculated from height while preserving original aspect ratio of 512x512
20
20
  height 96
21
21
  }
22
22
  }
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  require 'glimmer-dsl-libui'
4
2
 
5
3
  include Glimmer
@@ -9,7 +7,6 @@ window('Basic Image', 96, 96) {
9
7
  on_draw do |area_draw_params|
10
8
  image {
11
9
  file File.expand_path('../icons/glimmer.png', __dir__)
12
- width 96
13
10
  height 96
14
11
  }
15
12
  end
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  # This is the manual way of rendering an image unto an area control.
4
2
  # It could come in handy in special situations.
5
3
  # Otherwise, it is recommended to simply utilize the `image` control that
@@ -1,29 +1,107 @@
1
- # frozen_string_literal: true
2
-
3
1
  require 'glimmer-dsl-libui'
4
2
 
5
- include Glimmer
6
-
7
- img = image(File.expand_path('../icons/glimmer.png', __dir__), 24, 24)
8
-
9
- data = [
10
- [['cat', :red] , ['meow', :blue] , [true, 'mammal', :green], [img, 'Glimmer', :dark_blue], {r: 255, g: 120, b: 0, a: 0.5}],
11
- [['dog', :yellow] , ['woof', {r: 240, g: 32, b: 32}] , [true, 'mammal', :green], [img, 'Glimmer', :dark_blue], :skyblue],
12
- [['chicken', :beige], ['cock-a-doodle-doo', :blue] , [false, 'mammal', :red] , [img, 'Glimmer', :beige], {r: 5, g: 120, b: 110}],
13
- [['horse', :purple] , ['neigh', {r: 240, g: 32, b: 32}], [true, 'mammal', :green], [img, 'Glimmer', :dark_blue], '13a1fb'],
14
- [['cow', :gray] , ['moo', :blue] , [true, 'mammal', :green], [img, 'Glimmer', :brown], 0x12ff02]
15
- ]
16
-
17
- window('Animals', 500, 200) {
18
- horizontal_box {
19
- table {
20
- text_color_column('Animal')
21
- text_color_column('Sound')
22
- checkbox_text_color_column('Description')
23
- image_text_color_column('GUI')
24
- background_color_column # must be the last column
3
+ class BasicTableColor
4
+ Animal = Struct.new(:name, :sound, :mammal)
5
+
6
+ class AnimalPresenter < Animal
7
+ def name_color
8
+ color = case name
9
+ when 'cat'
10
+ :red
11
+ when 'dog'
12
+ :yellow
13
+ when 'chicken'
14
+ :beige
15
+ when 'horse'
16
+ :purple
17
+ when 'cow'
18
+ :gray
19
+ end
20
+ [name, color]
21
+ end
22
+
23
+ def sound_color
24
+ color = case name
25
+ when 'cat', 'chicken', 'cow'
26
+ :blue
27
+ when 'dog', 'horse'
28
+ {r: 240, g: 32, b: 32}
29
+ end
30
+ [sound, color]
31
+ end
32
+
33
+ def mammal_description_color
34
+ color = case name
35
+ when 'cat', 'dog', 'horse', 'cow'
36
+ :green
37
+ when 'chicken'
38
+ :red
39
+ end
40
+ [mammal, 'mammal', color]
41
+ end
42
+
43
+ def image_description_color
44
+ color = case name
45
+ when 'cat', 'dog', 'horse'
46
+ :dark_blue
47
+ when 'chicken'
48
+ :beige
49
+ when 'cow'
50
+ :brown
51
+ end
52
+ [img, 'Glimmer', color]
53
+ end
54
+
55
+ def img
56
+ # scale image to 24x24 (can be passed as file path String only instead of Array to avoid scaling)
57
+ [File.expand_path('../icons/glimmer.png', __dir__), 24, 24]
58
+ end
59
+
60
+ def background_color
61
+ case name
62
+ when 'cat'
63
+ {r: 255, g: 120, b: 0, a: 0.5}
64
+ when 'dog'
65
+ :skyblue
66
+ when 'chicken'
67
+ {r: 5, g: 120, b: 110}
68
+ when 'horse'
69
+ '#13a1fb'
70
+ when 'cow'
71
+ 0x12ff02
72
+ end
73
+ end
74
+ end
75
+
76
+ include Glimmer
77
+
78
+ attr_accessor :animals
79
+
80
+ def initialize
81
+ @animals = [
82
+ AnimalPresenter.new('cat', 'meow', true),
83
+ AnimalPresenter.new('dog', 'woof', true),
84
+ AnimalPresenter.new('chicken', 'cock-a-doodle-doo', false),
85
+ AnimalPresenter.new('horse', 'neigh', true),
86
+ AnimalPresenter.new('cow', 'moo', true),
87
+ ]
88
+ end
89
+
90
+ def launch
91
+ window('Animals', 500, 200) {
92
+ horizontal_box {
93
+ table {
94
+ text_color_column('Animal')
95
+ text_color_column('Sound')
96
+ checkbox_text_color_column('Description')
97
+ image_text_color_column('GUI')
98
+ background_color_column # must always be the last column and always expects data-binding model attribute `background_color` when binding to Array of models
99
+
100
+ cell_rows <= [self, :animals, column_attributes: {'Animal' => :name_color, 'Sound' => :sound_color, 'Description' => :mammal_description_color, 'GUI' => :image_description_color}]
101
+ }
102
+ }
103
+ }.show
104
+ end
105
+ end
25
106
 
26
- cell_rows data
27
- }
28
- }
29
- }.show
107
+ BasicTableColor.new.launch
@@ -1,20 +1,8 @@
1
- # frozen_string_literal: true
2
-
3
1
  require 'glimmer-dsl-libui'
4
- require 'chunky_png'
5
2
 
6
3
  include Glimmer
7
4
 
8
- f = File.open(File.expand_path('../icons/glimmer.png', __dir__))
9
- canvas = ChunkyPNG::Canvas.from_io(f)
10
- f.close
11
- canvas.resample_nearest_neighbor!(24, 24)
12
- data = canvas.to_rgba_stream
13
- width = canvas.width
14
- height = canvas.height
15
- img = image {
16
- image_part(data, width, height, width * 4)
17
- }
5
+ img = [File.expand_path('../icons/glimmer.png', __dir__), 24, 24] # scales image to 24x24 (can be passed as file path String only instead of Array to avoid scaling)
18
6
 
19
7
  data = [
20
8
  [['cat', :red] , ['meow', :blue] , [true, 'mammal', :green], [img, 'Glimmer', :dark_blue], {r: 255, g: 120, b: 0, a: 0.5}],
@@ -31,7 +19,7 @@ window('Animals', 500, 200) {
31
19
  text_color_column('Sound')
32
20
  checkbox_text_color_column('Description')
33
21
  image_text_color_column('GUI')
34
- background_color_column('Mammal')
22
+ background_color_column # must be the last column
35
23
 
36
24
  cell_rows data
37
25
  }
@@ -0,0 +1,37 @@
1
+ require 'glimmer-dsl-libui'
2
+ require 'chunky_png'
3
+
4
+ include Glimmer
5
+
6
+ f = File.open(File.expand_path('../icons/glimmer.png', __dir__))
7
+ canvas = ChunkyPNG::Canvas.from_io(f)
8
+ f.close
9
+ canvas.resample_nearest_neighbor!(24, 24)
10
+ data = canvas.to_rgba_stream
11
+ width = canvas.width
12
+ height = canvas.height
13
+ img = image {
14
+ image_part(data, width, height, width * 4)
15
+ }
16
+
17
+ data = [
18
+ [['cat', :red] , ['meow', :blue] , [true, 'mammal', :green], [img, 'Glimmer', :dark_blue], {r: 255, g: 120, b: 0, a: 0.5}],
19
+ [['dog', :yellow] , ['woof', {r: 240, g: 32, b: 32}] , [true, 'mammal', :green], [img, 'Glimmer', :dark_blue], :skyblue],
20
+ [['chicken', :beige], ['cock-a-doodle-doo', :blue] , [false, 'mammal', :red] , [img, 'Glimmer', :beige], {r: 5, g: 120, b: 110}],
21
+ [['horse', :purple] , ['neigh', {r: 240, g: 32, b: 32}], [true, 'mammal', :green], [img, 'Glimmer', :dark_blue], '13a1fb'],
22
+ [['cow', :gray] , ['moo', :blue] , [true, 'mammal', :green], [img, 'Glimmer', :brown], 0x12ff02]
23
+ ]
24
+
25
+ window('Animals', 500, 200) {
26
+ horizontal_box {
27
+ table {
28
+ text_color_column('Animal')
29
+ text_color_column('Sound')
30
+ checkbox_text_color_column('Description')
31
+ image_text_color_column('GUI')
32
+ background_color_column('Mammal')
33
+
34
+ cell_rows data
35
+ }
36
+ }
37
+ }.show
@@ -12,7 +12,7 @@ IMAGE_ROWS = []
12
12
  50.times do |i|
13
13
  url = format('https://www.ghibli.jp/gallery/thumb-redturtle%03d.png', (i + 1))
14
14
  puts "Processing Image: #{url}"; $stdout.flush # for Windows
15
- IMAGE_ROWS << [image(url)] # array of one column cell
15
+ IMAGE_ROWS << [url] # array of one column cell
16
16
  rescue StandardError => e
17
17
  warn url, e.message
18
18
  end
@@ -4,8 +4,6 @@
4
4
  # This example displays images that can be freely downloaded from the Studio Ghibli website.
5
5
 
6
6
  require 'glimmer-dsl-libui'
7
- require 'chunky_png'
8
- require 'open-uri'
9
7
 
10
8
  include Glimmer
11
9
 
@@ -13,18 +11,8 @@ IMAGE_ROWS = []
13
11
 
14
12
  50.times do |i|
15
13
  url = format('https://www.ghibli.jp/gallery/thumb-redturtle%03d.png', (i + 1))
16
- puts "Processing Image: #{url}"
17
- $stdout.flush # for Windows
18
- f = URI.open(url)
19
- canvas = ChunkyPNG::Canvas.from_io(f)
20
- f.close
21
- data = canvas.to_rgba_stream
22
- width = canvas.width
23
- height = canvas.height
24
- img = image {
25
- image_part(data, width, height, width * 4)
26
- }
27
- IMAGE_ROWS << [img] # array of one column cell
14
+ puts "Processing Image: #{url}"; $stdout.flush # for Windows
15
+ IMAGE_ROWS << [image(url)] # array of one column cell
28
16
  rescue StandardError => e
29
17
  warn url, e.message
30
18
  end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ # NOTE:
4
+ # This example displays images that can be freely downloaded from the Studio Ghibli website.
5
+
6
+ require 'glimmer-dsl-libui'
7
+ require 'chunky_png'
8
+ require 'open-uri'
9
+
10
+ include Glimmer
11
+
12
+ IMAGE_ROWS = []
13
+
14
+ 50.times do |i|
15
+ url = format('https://www.ghibli.jp/gallery/thumb-redturtle%03d.png', (i + 1))
16
+ puts "Processing Image: #{url}"
17
+ $stdout.flush # for Windows
18
+ f = URI.open(url)
19
+ canvas = ChunkyPNG::Canvas.from_io(f)
20
+ f.close
21
+ data = canvas.to_rgba_stream
22
+ width = canvas.width
23
+ height = canvas.height
24
+ img = image {
25
+ image_part(data, width, height, width * 4)
26
+ }
27
+ IMAGE_ROWS << [img] # array of one column cell
28
+ rescue StandardError => e
29
+ warn url, e.message
30
+ end
31
+
32
+ window('The Red Turtle', 310, 350, false) {
33
+ horizontal_box {
34
+ table {
35
+ image_column('www.ghibli.jp/works/red-turtle')
36
+
37
+ cell_rows IMAGE_ROWS
38
+ }
39
+ }
40
+
41
+ on_closing do
42
+ puts 'Bye Bye'
43
+ end
44
+ }.show
@@ -13,8 +13,7 @@ IMAGE_ROWS = []
13
13
  url = format('https://www.ghibli.jp/gallery/thumb-redturtle%03d.png', (i + 1))
14
14
  puts "Processing Image: #{url}"; $stdout.flush # for Windows
15
15
  text = url.sub('https://www.ghibli.jp/gallery/thumb-redturtle', '').sub('.png', '')
16
- img = image(url)
17
- IMAGE_ROWS << [[img, text], [img, text]] # cell values are dual-element arrays
16
+ IMAGE_ROWS << [[url, text], [url, text]] # cell values are dual-element arrays
18
17
  rescue StandardError => e
19
18
  warn url, e.message
20
19
  end
@@ -4,8 +4,6 @@
4
4
  # This example displays images that can be freely downloaded from the Studio Ghibli website.
5
5
 
6
6
  require 'glimmer-dsl-libui'
7
- require 'chunky_png'
8
- require 'open-uri'
9
7
 
10
8
  include Glimmer
11
9
 
@@ -13,18 +11,9 @@ IMAGE_ROWS = []
13
11
 
14
12
  5.times do |i|
15
13
  url = format('https://www.ghibli.jp/gallery/thumb-redturtle%03d.png', (i + 1))
16
- puts "Processing Image: #{url}"
17
- $stdout.flush # for Windows
18
- f = URI.open(url)
19
- canvas = ChunkyPNG::Canvas.from_io(f)
20
- f.close
21
- data = canvas.to_rgba_stream
22
- width = canvas.width
23
- height = canvas.height
24
- img = image {
25
- image_part(data, width, height, width * 4)
26
- }
14
+ puts "Processing Image: #{url}"; $stdout.flush # for Windows
27
15
  text = url.sub('https://www.ghibli.jp/gallery/thumb-redturtle', '').sub('.png', '')
16
+ img = image(url)
28
17
  IMAGE_ROWS << [[img, text], [img, text]] # cell values are dual-element arrays
29
18
  rescue StandardError => e
30
19
  warn url, e.message
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ # NOTE:
4
+ # This example displays images that can be freely downloaded from the Studio Ghibli website.
5
+
6
+ require 'glimmer-dsl-libui'
7
+ require 'chunky_png'
8
+ require 'open-uri'
9
+
10
+ include Glimmer
11
+
12
+ IMAGE_ROWS = []
13
+
14
+ 5.times do |i|
15
+ url = format('https://www.ghibli.jp/gallery/thumb-redturtle%03d.png', (i + 1))
16
+ puts "Processing Image: #{url}"
17
+ $stdout.flush # for Windows
18
+ f = URI.open(url)
19
+ canvas = ChunkyPNG::Canvas.from_io(f)
20
+ f.close
21
+ data = canvas.to_rgba_stream
22
+ width = canvas.width
23
+ height = canvas.height
24
+ img = image {
25
+ image_part(data, width, height, width * 4)
26
+ }
27
+ text = url.sub('https://www.ghibli.jp/gallery/thumb-redturtle', '').sub('.png', '')
28
+ IMAGE_ROWS << [[img, text], [img, text]] # cell values are dual-element arrays
29
+ rescue StandardError => e
30
+ warn url, e.message
31
+ end
32
+
33
+ window('The Red Turtle', 670, 350) {
34
+ horizontal_box {
35
+ table {
36
+ image_text_column('image/number')
37
+ image_text_column('image/number (editable)') {
38
+ editable true
39
+ }
40
+
41
+ cell_rows IMAGE_ROWS
42
+ }
43
+ }
44
+ }.show
@@ -23,7 +23,7 @@ Glimmer::LibUI.timer(1) do
23
23
  data[0][2] = cpu_percentage_value
24
24
  end
25
25
 
26
- window('CPU Percentage', 400, 200) {
26
+ window('CPU Percentage', 400, 50) {
27
27
  vertical_box {
28
28
  table {
29
29
  text_column('Name')
@@ -22,6 +22,11 @@ window('Editable column animal sounds', 400, 200) {
22
22
  }
23
23
 
24
24
  cell_rows data
25
+
26
+ on_edited do |row, row_data| # only fires on direct table editing
27
+ puts "Row #{row} edited: #{row_data}"
28
+ $stdout.flush
29
+ end
25
30
  }
26
31
  }
27
32
 
@@ -18,7 +18,7 @@ class FormTable
18
18
  end
19
19
 
20
20
  def launch
21
- window('Contacts', 600, 600) { |w|
21
+ window('Contacts', 600, 600) {
22
22
  margined true
23
23
 
24
24
  vertical_box {
@@ -56,8 +56,8 @@ class FormTable
56
56
 
57
57
  on_clicked do
58
58
  new_row = [name, email, phone, city, state]
59
- if new_row.include?('')
60
- msg_box_error(w, 'Validation Error!', 'All fields are required! Please make sure to enter a value for all fields.')
59
+ if new_row.map(&:to_s).include?('')
60
+ msg_box_error('Validation Error!', 'All fields are required! Please make sure to enter a value for all fields.')
61
61
  else
62
62
  @contacts << Contact.new(*new_row) # automatically inserts a row into the table due to explicit data-binding
63
63
  @unfiltered_contacts = @contacts.dup
@@ -98,10 +98,16 @@ class FormTable
98
98
  text_column('State')
99
99
 
100
100
  editable true
101
- cell_rows <=> [self, :contacts] # explicit data-binding to Model Array
101
+ cell_rows <=> [self, :contacts] # explicit data-binding to self.contacts Model Array, auto-inferring model attribute names from underscored table column names by convention
102
102
 
103
103
  on_changed do |row, type, row_data|
104
104
  puts "Row #{row} #{type}: #{row_data}"
105
+ $stdout.flush # for Windows
106
+ end
107
+
108
+ on_edited do |row, row_data| # only fires on direct table editing
109
+ puts "Row #{row} edited: #{row_data}"
110
+ $stdout.flush # for Windows
105
111
  end
106
112
  }
107
113
  }
@@ -1,7 +1,7 @@
1
1
  require 'glimmer-dsl-libui'
2
2
 
3
3
  class FormTable
4
- Contact = Struct.new(:name, :email, :phone, :city, :state)
4
+ Contact = Struct.new(:name, :email, :phone, :city, :state_province)
5
5
 
6
6
  include Glimmer
7
7
 
@@ -18,7 +18,7 @@ class FormTable
18
18
  end
19
19
 
20
20
  def launch
21
- window('Contacts', 600, 600) { |w|
21
+ window('Contacts', 600, 600) {
22
22
  margined true
23
23
 
24
24
  vertical_box {
@@ -56,8 +56,8 @@ class FormTable
56
56
 
57
57
  on_clicked do
58
58
  new_row = [name, email, phone, city, state]
59
- if new_row.include?('')
60
- msg_box_error(w, 'Validation Error!', 'All fields are required! Please make sure to enter a value for all fields.')
59
+ if new_row.map(&:to_s).include?('')
60
+ msg_box_error('Validation Error!', 'All fields are required! Please make sure to enter a value for all fields.')
61
61
  else
62
62
  @contacts << Contact.new(*new_row) # automatically inserts a row into the table due to implicit data-binding
63
63
  @unfiltered_contacts = @contacts.dup
@@ -95,13 +95,19 @@ class FormTable
95
95
  text_column('Email')
96
96
  text_column('Phone')
97
97
  text_column('City')
98
- text_column('State/Province')
98
+ text_column('State')
99
99
 
100
100
  editable true
101
- cell_rows <=> [self, :contacts, column_attributes: {'State/Province' => :state}] # explicit data-binding to Model Array with column_attributes mapping for a specific column
101
+ cell_rows <=> [self, :contacts, column_attributes: {'State' => :state_province}] # explicit data-binding to Model Array with column_attributes mapping for a specific column
102
102
 
103
103
  on_changed do |row, type, row_data|
104
104
  puts "Row #{row} #{type}: #{row_data}"
105
+ $stdout.flush # for Windows
106
+ end
107
+
108
+ on_edited do |row, row_data| # only fires on direct table editing
109
+ puts "Row #{row} edited: #{row_data}"
110
+ $stdout.flush # for Windows
105
111
  end
106
112
  }
107
113
  }
@@ -19,7 +19,7 @@ class FormTable
19
19
  end
20
20
 
21
21
  def launch
22
- window('Contacts', 600, 600) { |w|
22
+ window('Contacts', 600, 600) {
23
23
  margined true
24
24
 
25
25
  vertical_box {
@@ -57,8 +57,8 @@ class FormTable
57
57
 
58
58
  on_clicked do
59
59
  new_row = [name, email, phone, city, state]
60
- if new_row.include?('')
61
- msg_box_error(w, 'Validation Error!', 'All fields are required! Please make sure to enter a value for all fields.')
60
+ if new_row.map(&:to_s).include?('')
61
+ msg_box_error('Validation Error!', 'All fields are required! Please make sure to enter a value for all fields.')
62
62
  else
63
63
  @contacts << Contact.new(*new_row) # automatically inserts a row into the table due to implicit data-binding
64
64
  @unfiltered_contacts = @contacts.dup
@@ -103,6 +103,12 @@ class FormTable
103
103
 
104
104
  on_changed do |row, type, row_data|
105
105
  puts "Row #{row} #{type}: #{row_data}"
106
+ $stdout.flush # for Windows
107
+ end
108
+
109
+ on_edited do |row, row_data| # only fires on direct table editing
110
+ puts "Row #{row} edited: #{row_data}"
111
+ $stdout.flush # for Windows
106
112
  end
107
113
  }
108
114
  }
@@ -16,7 +16,7 @@ class FormTable
16
16
  end
17
17
 
18
18
  def launch
19
- window('Contacts', 600, 600) { |w|
19
+ window('Contacts', 600, 600) {
20
20
  margined true
21
21
 
22
22
  vertical_box {
@@ -54,8 +54,8 @@ class FormTable
54
54
 
55
55
  on_clicked do
56
56
  new_row = [name, email, phone, city, state]
57
- if new_row.include?('')
58
- msg_box_error(w, 'Validation Error!', 'All fields are required! Please make sure to enter a value for all fields.')
57
+ if new_row.map(&:to_s).include?('')
58
+ msg_box_error('Validation Error!', 'All fields are required! Please make sure to enter a value for all fields.')
59
59
  else
60
60
  data << new_row # automatically inserts a row into the table due to implicit data-binding
61
61
  @unfiltered_data = data.dup
@@ -100,6 +100,12 @@ class FormTable
100
100
 
101
101
  on_changed do |row, type, row_data|
102
102
  puts "Row #{row} #{type}: #{row_data}"
103
+ $stdout.flush # for Windows
104
+ end
105
+
106
+ on_edited do |row, row_data| # only fires on direct table editing
107
+ puts "Row #{row} edited: #{row_data}"
108
+ $stdout.flush # for Windows
103
109
  end
104
110
  }
105
111
  }
@@ -10,7 +10,7 @@ data = [
10
10
  ['Melody Hanheimer', 'melody@hanheimer.com', '213-493-8274', 'Los Angeles', 'CA'],
11
11
  ]
12
12
 
13
- window('Contacts', 600, 600) { |w|
13
+ window('Contacts', 600, 600) {
14
14
  margined true
15
15
 
16
16
  vertical_box {
@@ -43,8 +43,8 @@ window('Contacts', 600, 600) { |w|
43
43
 
44
44
  on_clicked do
45
45
  new_row = [@name_entry.text, @email_entry.text, @phone_entry.text, @city_entry.text, @state_entry.text]
46
- if new_row.include?('')
47
- msg_box_error(w, 'Validation Error!', 'All fields are required! Please make sure to enter a value for all fields.')
46
+ if new_row.map(&:to_s).include?('')
47
+ msg_box_error('Validation Error!', 'All fields are required! Please make sure to enter a value for all fields.')
48
48
  else
49
49
  data << new_row # automatically inserts a row into the table due to implicit data-binding
50
50
  @unfiltered_data = data.dup
@@ -88,6 +88,12 @@ window('Contacts', 600, 600) { |w|
88
88
 
89
89
  on_changed do |row, type, row_data|
90
90
  puts "Row #{row} #{type}: #{row_data}"
91
+ $stdout.flush # for Windows
92
+ end
93
+
94
+ on_edited do |row, row_data| # only fires on direct table editing
95
+ puts "Row #{row} edited: #{row_data}"
96
+ $stdout.flush # for Windows
91
97
  end
92
98
  }
93
99
  }