fidgit 0.2.4 → 0.2.5

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.
Files changed (85) hide show
  1. data/.gitignore +7 -7
  2. data/.rspec +2 -2
  3. data/CHANGELOG.md +30 -30
  4. data/Gemfile +3 -3
  5. data/LICENSE.txt +19 -19
  6. data/README.textile +139 -139
  7. data/Rakefile +37 -37
  8. data/config/default_schema.yml +216 -216
  9. data/examples/_all_examples.rb +9 -9
  10. data/examples/align_example.rb +55 -55
  11. data/examples/button_and_toggle_button_example.rb +37 -37
  12. data/examples/color_picker_example.rb +16 -16
  13. data/examples/color_well_example.rb +24 -24
  14. data/examples/combo_box_example.rb +23 -23
  15. data/examples/file_dialog_example.rb +41 -41
  16. data/examples/grid_packer_example.rb +28 -28
  17. data/examples/helpers/example_window.rb +16 -16
  18. data/examples/label_example.rb +22 -22
  19. data/examples/list_example.rb +22 -22
  20. data/examples/menu_pane_example.rb +26 -26
  21. data/examples/message_dialog_example.rb +64 -64
  22. data/examples/radio_button_example.rb +36 -36
  23. data/examples/readme_example.rb +31 -31
  24. data/examples/scroll_window_example.rb +48 -48
  25. data/examples/slider_example.rb +33 -33
  26. data/examples/splash_example.rb +41 -41
  27. data/examples/text_area_example.rb +32 -32
  28. data/fidgit.gemspec +35 -35
  29. data/lib/fidgit.rb +50 -50
  30. data/lib/fidgit/chingu_ext/window.rb +5 -5
  31. data/lib/fidgit/cursor.rb +37 -37
  32. data/lib/fidgit/elements/button.rb +112 -112
  33. data/lib/fidgit/elements/color_picker.rb +62 -62
  34. data/lib/fidgit/elements/color_well.rb +38 -38
  35. data/lib/fidgit/elements/combo_box.rb +113 -113
  36. data/lib/fidgit/elements/composite.rb +16 -16
  37. data/lib/fidgit/elements/container.rb +208 -208
  38. data/lib/fidgit/elements/element.rb +297 -297
  39. data/lib/fidgit/elements/file_browser.rb +151 -151
  40. data/lib/fidgit/elements/grid.rb +226 -226
  41. data/lib/fidgit/elements/group.rb +64 -64
  42. data/lib/fidgit/elements/horizontal.rb +11 -11
  43. data/lib/fidgit/elements/image_frame.rb +64 -64
  44. data/lib/fidgit/elements/label.rb +84 -84
  45. data/lib/fidgit/elements/list.rb +46 -46
  46. data/lib/fidgit/elements/main_packer.rb +24 -24
  47. data/lib/fidgit/elements/menu_pane.rb +160 -160
  48. data/lib/fidgit/elements/packer.rb +41 -41
  49. data/lib/fidgit/elements/radio_button.rb +85 -85
  50. data/lib/fidgit/elements/scroll_area.rb +67 -67
  51. data/lib/fidgit/elements/scroll_bar.rb +127 -127
  52. data/lib/fidgit/elements/scroll_window.rb +82 -82
  53. data/lib/fidgit/elements/slider.rb +124 -124
  54. data/lib/fidgit/elements/text_area.rb +493 -493
  55. data/lib/fidgit/elements/text_line.rb +91 -91
  56. data/lib/fidgit/elements/toggle_button.rb +66 -66
  57. data/lib/fidgit/elements/tool_tip.rb +34 -34
  58. data/lib/fidgit/elements/vertical.rb +11 -11
  59. data/lib/fidgit/event.rb +158 -158
  60. data/lib/fidgit/gosu_ext/color.rb +135 -135
  61. data/lib/fidgit/gosu_ext/gosu_module.rb +24 -24
  62. data/lib/fidgit/history.rb +90 -90
  63. data/lib/fidgit/redirector.rb +82 -82
  64. data/lib/fidgit/schema.rb +123 -123
  65. data/lib/fidgit/selection.rb +105 -105
  66. data/lib/fidgit/standard_ext/hash.rb +20 -20
  67. data/lib/fidgit/states/dialog_state.rb +51 -51
  68. data/lib/fidgit/states/file_dialog.rb +24 -24
  69. data/lib/fidgit/states/gui_state.rb +329 -329
  70. data/lib/fidgit/states/message_dialog.rb +60 -60
  71. data/lib/fidgit/version.rb +4 -4
  72. data/lib/fidgit/window.rb +19 -19
  73. data/spec/fidgit/elements/helpers/helper.rb +2 -2
  74. data/spec/fidgit/elements/helpers/tex_play_helper.rb +8 -8
  75. data/spec/fidgit/elements/image_frame_spec.rb +68 -68
  76. data/spec/fidgit/elements/label_spec.rb +36 -36
  77. data/spec/fidgit/event_spec.rb +209 -209
  78. data/spec/fidgit/gosu_ext/color_spec.rb +129 -129
  79. data/spec/fidgit/gosu_ext/helpers/helper.rb +2 -2
  80. data/spec/fidgit/helpers/helper.rb +3 -3
  81. data/spec/fidgit/history_spec.rb +153 -153
  82. data/spec/fidgit/redirector_spec.rb +77 -77
  83. data/spec/fidgit/schema_spec.rb +66 -66
  84. data/spec/fidgit/schema_test.yml +32 -32
  85. metadata +67 -22
@@ -1,64 +1,64 @@
1
- module Fidgit
2
- class Group < Packer
3
- attr_reader :selected
4
-
5
- event :changed
6
-
7
- def value; @selected ? @selected.value : nil; end
8
-
9
- # @example
10
- # group do
11
- # horizontal do
12
- # radio_button 1, text: '1', checked: true
13
- # radio_button 2, text: '2'
14
- # subscribe :changed do |sender, value|
15
- # puts value
16
- # end
17
- # end
18
- # end
19
- #
20
- # @param (see Packer#initialize)
21
- #
22
- # @option (see Packer#initialize)
23
- def initialize(options = {}, &block)
24
- super(options)
25
-
26
- @selected = nil
27
- @buttons = []
28
- end
29
-
30
- def add_button(button)
31
- @buttons.push button
32
- self.value = button.value if button.checked?
33
- nil
34
- end
35
-
36
- def remove_button(button)
37
- self.value = nil if button == @selected
38
- @buttons.delete button
39
- nil
40
- end
41
-
42
- # @example
43
- # @my_group = group do
44
- # horizontal do
45
- # radio_button(1, text: '1', checked: true)
46
- # radio_button(2, text: '2')
47
- # end
48
- # end
49
- #
50
- # # later
51
- # @my_group.value = 2
52
- def value=(value)
53
- if value != self.value
54
- button = @buttons.find { |b| b.value == value }
55
- @selected.uncheck if @selected and @selected.checked?
56
- @selected = button
57
- @selected.check if @selected and not @selected.checked?
58
- publish :changed, self.value
59
- end
60
-
61
- value
62
- end
63
- end
64
- end
1
+ module Fidgit
2
+ class Group < Packer
3
+ attr_reader :selected
4
+
5
+ event :changed
6
+
7
+ def value; @selected ? @selected.value : nil; end
8
+
9
+ # @example
10
+ # group do
11
+ # horizontal do
12
+ # radio_button 1, text: '1', checked: true
13
+ # radio_button 2, text: '2'
14
+ # subscribe :changed do |sender, value|
15
+ # puts value
16
+ # end
17
+ # end
18
+ # end
19
+ #
20
+ # @param (see Packer#initialize)
21
+ #
22
+ # @option (see Packer#initialize)
23
+ def initialize(options = {}, &block)
24
+ super(options)
25
+
26
+ @selected = nil
27
+ @buttons = []
28
+ end
29
+
30
+ def add_button(button)
31
+ @buttons.push button
32
+ self.value = button.value if button.checked?
33
+ nil
34
+ end
35
+
36
+ def remove_button(button)
37
+ self.value = nil if button == @selected
38
+ @buttons.delete button
39
+ nil
40
+ end
41
+
42
+ # @example
43
+ # @my_group = group do
44
+ # horizontal do
45
+ # radio_button(1, text: '1', checked: true)
46
+ # radio_button(2, text: '2')
47
+ # end
48
+ # end
49
+ #
50
+ # # later
51
+ # @my_group.value = 2
52
+ def value=(value)
53
+ if value != self.value
54
+ button = @buttons.find { |b| b.value == value }
55
+ @selected.uncheck if @selected and @selected.checked?
56
+ @selected = button
57
+ @selected.check if @selected and not @selected.checked?
58
+ publish :changed, self.value
59
+ end
60
+
61
+ value
62
+ end
63
+ end
64
+ end
@@ -1,12 +1,12 @@
1
- # encoding: utf-8
2
-
3
- module Fidgit
4
- # A vertically aligned element packing container.
5
- class Horizontal < Grid
6
- def initialize(options = {})
7
- options[:num_rows] = 1
8
-
9
- super options
10
- end
11
- end
1
+ # encoding: utf-8
2
+
3
+ module Fidgit
4
+ # A vertically aligned element packing container.
5
+ class Horizontal < Grid
6
+ def initialize(options = {})
7
+ options[:num_rows] = 1
8
+
9
+ super options
10
+ end
11
+ end
12
12
  end
@@ -1,65 +1,65 @@
1
- module Fidgit
2
- # A wrapper around a Gosu::Image to show it in the GUI.
3
- class ImageFrame < Element
4
- ENABLED_COLOR = Gosu::Color::WHITE
5
- DISABLED_COLOR = Gosu::Color.rgb(150, 150, 150)
6
-
7
- attr_reader :image, :factor_x, :factor_y
8
-
9
- def thumbnail?; @thumbnail; end
10
-
11
- # @param (see Element#initialize)
12
- # @param [Gosu::Image] image Gosu image to display.
13
- #
14
- # @option (see Element#initialize)
15
- # @option options [Boolean] :thumbnail (false) Is the image expanded to be square?
16
- def initialize(image, options = {})
17
- options = {
18
- thumbnail: false,
19
- factor: 1,
20
- }.merge! options
21
-
22
- @thumbnail = options[:thumbnail]
23
- @factor_x = options[:factor_x] || options[:factor]
24
- @factor_y = options[:factor_y] || options[:factor]
25
-
26
- super(options)
27
-
28
- self.image = image
29
- end
30
-
31
- def image=(image)
32
- @image = image
33
-
34
- recalc
35
-
36
- image
37
- end
38
-
39
-
40
- def draw_foreground
41
- @image.draw(x + padding_left, y + padding_top, z, factor_x, factor_y, enabled? ? ENABLED_COLOR : DISABLED_COLOR) if @image
42
- end
43
-
44
- protected
45
- def layout
46
- if @image
47
- if @thumbnail
48
- size = [@image.width, @image.height].max
49
- rect.width = size * @factor_x
50
- rect.height = size * @factor_y
51
- else
52
- rect.width = @image.width * @factor_x
53
- rect.height = @image.height * @factor_y
54
- end
55
- else
56
- rect.width = rect.height = 0
57
- end
58
-
59
- rect.width += padding_left + padding_right
60
- rect.height += padding_top + padding_bottom
61
-
62
- nil
63
- end
64
- end
1
+ module Fidgit
2
+ # A wrapper around a Gosu::Image to show it in the GUI.
3
+ class ImageFrame < Element
4
+ ENABLED_COLOR = Gosu::Color::WHITE
5
+ DISABLED_COLOR = Gosu::Color.rgb(150, 150, 150)
6
+
7
+ attr_reader :image, :factor_x, :factor_y
8
+
9
+ def thumbnail?; @thumbnail; end
10
+
11
+ # @param (see Element#initialize)
12
+ # @param [Gosu::Image] image Gosu image to display.
13
+ #
14
+ # @option (see Element#initialize)
15
+ # @option options [Boolean] :thumbnail (false) Is the image expanded to be square?
16
+ def initialize(image, options = {})
17
+ options = {
18
+ thumbnail: false,
19
+ factor: 1,
20
+ }.merge! options
21
+
22
+ @thumbnail = options[:thumbnail]
23
+ @factor_x = options[:factor_x] || options[:factor]
24
+ @factor_y = options[:factor_y] || options[:factor]
25
+
26
+ super(options)
27
+
28
+ self.image = image
29
+ end
30
+
31
+ def image=(image)
32
+ @image = image
33
+
34
+ recalc
35
+
36
+ image
37
+ end
38
+
39
+
40
+ def draw_foreground
41
+ @image.draw(x + padding_left, y + padding_top, z, factor_x, factor_y, enabled? ? ENABLED_COLOR : DISABLED_COLOR) if @image
42
+ end
43
+
44
+ protected
45
+ def layout
46
+ if @image
47
+ if @thumbnail
48
+ size = [@image.width, @image.height].max
49
+ rect.width = size * @factor_x
50
+ rect.height = size * @factor_y
51
+ else
52
+ rect.width = @image.width * @factor_x
53
+ rect.height = @image.height * @factor_y
54
+ end
55
+ else
56
+ rect.width = rect.height = 0
57
+ end
58
+
59
+ rect.width += padding_left + padding_right
60
+ rect.height += padding_top + padding_bottom
61
+
62
+ nil
63
+ end
64
+ end
65
65
  end
@@ -1,85 +1,85 @@
1
- # encoding: utf-8
2
-
3
- module Fidgit
4
- class Label < Composite
5
- ICON_POSITIONS = [:top, :bottom, :left, :right]
6
-
7
- attr_reader :icon_position
8
-
9
- attr_accessor :background_color, :border_color
10
-
11
- def_delegators :@text, :text, :color, :font, :color=, :text=
12
-
13
- def icon; @icon ? @icon.image : nil; end
14
-
15
- def hit_element(x, y)
16
- # The sub-elements should never get events.
17
- hit?(x, y) ? self : nil
18
- end
19
-
20
- def icon=(icon)
21
- raise ArgumentError.new("Icon must be a Gosu::Image") unless icon.is_a? Gosu::Image or icon.nil?
22
-
23
- @contents.remove(@icon) if @icon.image
24
- @icon.image = icon
25
- position = [:left, :top].include?(icon_position) ? 0 : 1
26
- @contents.insert(position, @icon) if @icon.image
27
-
28
- icon
29
- end
30
-
31
- # Set the position of the icon, respective to the text.
32
- def icon_position=(position)
33
- raise ArgumentError.new("icon_position must be one of #{ICON_POSITIONS}") unless ICON_POSITIONS.include? position
34
-
35
- @icon_position = position
36
-
37
- case @icon_position
38
- when :top, :bottom
39
- @contents.instance_variable_set :@type, :fixed_columns
40
- @contents.instance_variable_set :@num_columns, 1
41
- when :left, :right
42
- @contents.instance_variable_set :@type, :fixed_rows
43
- @contents.instance_variable_set :@num_rows, 1
44
- end
45
-
46
- self.icon = @icon.image if @icon.image # Force the icon into the correct position.
47
-
48
- position
49
- end
50
-
51
- # @param (see Element#initialize)
52
- # @param [String] text The string to display in the label.
53
- #
54
- # @option (see Element#initialize)
55
- # @option options [Gosu::Image, nil] :icon (nil)
56
- # @option options [:left, :right, :center] :justify (:left) Text justification.
57
- def initialize(text, options = {})
58
- options = {
59
- color: default(:color),
60
- justify: default(:justify),
61
- background_color: default(:background_color),
62
- border_color: default(:border_color),
63
- icon_options: {},
64
- font_name: default(:font_name),
65
- font_height: default(:font_height),
66
- icon_position: default(:icon_position),
67
- }.merge! options
68
-
69
- super(options)
70
-
71
- # Bit of a fudge since font info is managed circularly here!
72
- # By using a grid, we'll be able to turn it around easily (in theory).
73
- @contents = grid num_rows: 1, padding: 0, spacing_h: spacing_h, spacing_v: spacing_v, width: options[:width], height: options[:height], z: z do |contents|
74
- @text = TextLine.new(text, parent: contents, justify: options[:justify], color: options[:color], padding: 0, z: z,
75
- font_name: options[:font_name], font_height: options[:font_height], align_h: :fill, align_v: :center)
76
- end
77
-
78
- # Create an image frame, but don't show it unless there is an image in it.
79
- @icon = ImageFrame.new(nil, options[:icon_options].merge(z: z, align: :center))
80
- @icon.image = options[:icon]
81
-
82
- self.icon_position = options[:icon_position]
83
- end
84
- end
1
+ # encoding: utf-8
2
+
3
+ module Fidgit
4
+ class Label < Composite
5
+ ICON_POSITIONS = [:top, :bottom, :left, :right]
6
+
7
+ attr_reader :icon_position
8
+
9
+ attr_accessor :background_color, :border_color
10
+
11
+ def_delegators :@text, :text, :color, :font, :color=, :text=
12
+
13
+ def icon; @icon ? @icon.image : nil; end
14
+
15
+ def hit_element(x, y)
16
+ # The sub-elements should never get events.
17
+ hit?(x, y) ? self : nil
18
+ end
19
+
20
+ def icon=(icon)
21
+ raise ArgumentError.new("Icon must be a Gosu::Image") unless icon.is_a? Gosu::Image or icon.nil?
22
+
23
+ @contents.remove(@icon) if @icon.image
24
+ @icon.image = icon
25
+ position = [:left, :top].include?(icon_position) ? 0 : 1
26
+ @contents.insert(position, @icon) if @icon.image
27
+
28
+ icon
29
+ end
30
+
31
+ # Set the position of the icon, respective to the text.
32
+ def icon_position=(position)
33
+ raise ArgumentError.new("icon_position must be one of #{ICON_POSITIONS}") unless ICON_POSITIONS.include? position
34
+
35
+ @icon_position = position
36
+
37
+ case @icon_position
38
+ when :top, :bottom
39
+ @contents.instance_variable_set :@type, :fixed_columns
40
+ @contents.instance_variable_set :@num_columns, 1
41
+ when :left, :right
42
+ @contents.instance_variable_set :@type, :fixed_rows
43
+ @contents.instance_variable_set :@num_rows, 1
44
+ end
45
+
46
+ self.icon = @icon.image if @icon.image # Force the icon into the correct position.
47
+
48
+ position
49
+ end
50
+
51
+ # @param (see Element#initialize)
52
+ # @param [String] text The string to display in the label.
53
+ #
54
+ # @option (see Element#initialize)
55
+ # @option options [Gosu::Image, nil] :icon (nil)
56
+ # @option options [:left, :right, :center] :justify (:left) Text justification.
57
+ def initialize(text, options = {})
58
+ options = {
59
+ color: default(:color),
60
+ justify: default(:justify),
61
+ background_color: default(:background_color),
62
+ border_color: default(:border_color),
63
+ icon_options: {},
64
+ font_name: default(:font_name),
65
+ font_height: default(:font_height),
66
+ icon_position: default(:icon_position),
67
+ }.merge! options
68
+
69
+ super(options)
70
+
71
+ # Bit of a fudge since font info is managed circularly here!
72
+ # By using a grid, we'll be able to turn it around easily (in theory).
73
+ @contents = grid num_rows: 1, padding: 0, spacing_h: spacing_h, spacing_v: spacing_v, width: options[:width], height: options[:height], z: z do |contents|
74
+ @text = TextLine.new(text, parent: contents, justify: options[:justify], color: options[:color], padding: 0, z: z,
75
+ font_name: options[:font_name], font_height: options[:font_height], align_h: :fill, align_v: :center)
76
+ end
77
+
78
+ # Create an image frame, but don't show it unless there is an image in it.
79
+ @icon = ImageFrame.new(nil, options[:icon_options].merge(z: z, align: :center))
80
+ @icon.image = options[:icon]
81
+
82
+ self.icon_position = options[:icon_position]
83
+ end
84
+ end
85
85
  end