fidgit 0.1.0 → 0.1.1

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.
@@ -93,7 +93,7 @@ class ComboBox < Button
93
93
  protected
94
94
  def layout
95
95
  super
96
- rect.width + height # Allow size for the arrow.
96
+ rect.width += height # Allow size for the arrow.
97
97
 
98
98
  nil
99
99
  end
@@ -152,6 +152,8 @@ module Fidgit
152
152
 
153
153
  @enabled = options[:enabled]
154
154
 
155
+ @mouse_over = false
156
+
155
157
  # Alignment and min/max dimensions.
156
158
  @align_h = options[:align_h] || Array(options[:align]).last || default(:align_h)
157
159
  raise ArgumentError, "Invalid align_h: #{@align_h}" unless VALID_ALIGN_H.include? @align_h
@@ -263,7 +265,7 @@ module Fidgit
263
265
  when 1
264
266
  yield self
265
267
  when 0
266
- instance_methods_eval &block
268
+ instance_methods_eval(&block)
267
269
  else
268
270
  raise "block arity must be 0 or 1"
269
271
  end
@@ -1,7 +1,5 @@
1
- # encoding: utf-8
2
-
3
- module Fidgit
4
- class Group < Packer
1
+ module Fidgit
2
+ class Group < Packer
5
3
  attr_reader :selected
6
4
 
7
5
  event :changed
@@ -67,7 +67,11 @@ module Fidgit
67
67
  center_x = (current_x + x + rect.width - padding_right) / 2.0
68
68
  end
69
69
 
70
- font.draw_rel(@text, center_x, y + padding_top, z, rel_x, 0, 1, 1, @color)
70
+ # Make text centered alongside the icon
71
+ # TODO: Probably should have this as an option.
72
+ center_y = y + padding_top + ((y + height - padding_bottom) - (y + padding_top)) / 2.0
73
+
74
+ font.draw_rel(@text, center_x, center_y, z, rel_x, 0.5, 1, 1, @color)
71
75
  end
72
76
 
73
77
  nil
@@ -77,20 +81,20 @@ module Fidgit
77
81
  def layout
78
82
  if @icon
79
83
  if @text.empty?
80
- rect.width = [padding_left + @icon.width + padding_right, width].max
81
- rect.height = [padding_top + @icon.height + padding_bottom, height].max
84
+ rect.width = [padding_left + @icon.width + padding_right, min_width].max
85
+ rect.height = [padding_top + @icon.height + padding_bottom, min_height].max
82
86
  else
83
87
  # Todo: Use padding_h inside here? Probably by making this a Composite.
84
- rect.width = [padding_left + @icon.width + [padding_left + padding_right].max + font.text_width(@text) + padding_right, width].max
85
- rect.height = [padding_top + [@icon.height, font_size].max + padding_bottom, height].max
88
+ rect.width = [padding_left + @icon.width + [padding_left + padding_right].max + font.text_width(@text) + padding_right, min_width].max
89
+ rect.height = [padding_top + [@icon.height, font_size].max + padding_bottom, min_height].max
86
90
  end
87
91
  else
88
92
  if @text.empty?
89
- rect.width = [padding_left + padding_right, width].max
90
- rect.height = [padding_top + padding_bottom, height].max
93
+ rect.width = [padding_left + padding_right, min_width].max
94
+ rect.height = [padding_top + padding_bottom, min_height].max
91
95
  else
92
- rect.width = [padding_left + font.text_width(@text) + padding_right, width].max
93
- rect.height = [padding_top + font_size + padding_bottom, height].max
96
+ rect.width = [padding_left + font.text_width(@text) + padding_right, min_width].max
97
+ rect.height = [padding_top + font_size + padding_bottom, min_height].max
94
98
  end
95
99
  end
96
100
 
@@ -65,6 +65,8 @@ module Fidgit
65
65
  event :selected
66
66
 
67
67
  def index(value); @items.index find(value); end
68
+ def x=(value); super(value); recalc; end
69
+ def y=(value); super(value); recalc; end
68
70
 
69
71
  # @option (see Composite#initialize)
70
72
  # @option options [Float] :x (cursor x, if in a GuiState)
@@ -86,6 +88,8 @@ module Fidgit
86
88
  }.merge! options
87
89
  end
88
90
 
91
+ @items = nil
92
+
89
93
  super(options)
90
94
 
91
95
  @items = vertical spacing: 0, padding: 0
@@ -133,7 +137,7 @@ module Fidgit
133
137
  super
134
138
 
135
139
  if @items
136
- # Ensure the menu can't go over the edge of the screen. If it can't be avoided, align with left edge of screen.
140
+ # Ensure the menu can't go over the edge of the screen. If it can't be avoided, align with top-left edge of screen.
137
141
  rect.x = [[x, $window.width - width - padding_right].min, 0].max
138
142
  rect.y = [[y, $window.height - height - padding_bottom].min, 0].max
139
143
 
@@ -144,6 +148,8 @@ module Fidgit
144
148
  # Ensure that all items are of the same width.
145
149
  max_width = @items.each.to_a.map {|c| c.width }.max || 0
146
150
  @items.each {|c| c.rect.width = max_width }
151
+
152
+ @items.recalc # Move all the items inside the packer to correct ones.
147
153
  end
148
154
 
149
155
  nil
data/lib/fidgit/event.rb CHANGED
@@ -34,7 +34,7 @@ module Fidgit
34
34
  raise ArgumentError, "Expected method or block for event handler" unless !block.nil? ^ !method.nil?
35
35
  raise ArgumentError, "#{self.class} does not handle #{event.inspect}" unless events.include? event
36
36
 
37
- @_event_handlers = Hash.new() { |hash, key| hash[key] = [] } unless @_event_handlers
37
+ @_event_handlers ||= Hash.new() { |hash, key| hash[key] = [] }
38
38
  @_event_handlers[event].push(method ? method : block)
39
39
 
40
40
  nil
@@ -59,7 +59,7 @@ module Fidgit
59
59
  return :handled if send(event, self, *args) == :handled
60
60
  end
61
61
 
62
- if @_event_handlers
62
+ if defined? @_event_handlers
63
63
  @_event_handlers[event].reverse_each do |handler|
64
64
  return :handled if handler.call(self, *args) == :handled
65
65
  end
@@ -77,8 +77,8 @@ module Fidgit
77
77
  def self.included(base)
78
78
  class << base
79
79
  def events
80
- unless @events
81
- # Copy the events already set up for your parent.
80
+ # Copy the events already set up for your parent.
81
+ unless defined? @events
82
82
  @events = if superclass.respond_to? :events
83
83
  superclass.events.dup
84
84
  else
@@ -45,11 +45,14 @@ module Fidgit
45
45
  def message(text, options = {}, &block); MessageDialog.new(text, options, &block); end
46
46
 
47
47
  # (see Container#clear)
48
- def clear(*args, &block); @container.clear *args, &block; end
48
+ def clear(*args, &block); @container.clear(*args, &block); end
49
49
 
50
50
  def initialize
51
51
  # The container is where the user puts their content.
52
52
  @container = MainPacker.new
53
+ @menu = nil
54
+ @last_cursor_pos = [-1, -1]
55
+ @mouse_over = nil
53
56
 
54
57
  unless defined? @@draw_pixel
55
58
  media_dir = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'media'))
@@ -1,5 +1,5 @@
1
1
  # encoding: UTF-8
2
2
 
3
3
  module Fidgit
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.1'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fidgit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,12 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-06-10 00:00:00.000000000 +01:00
12
+ date: 2011-06-13 00:00:00.000000000 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: gosu
17
- requirement: &27888528 !ruby/object:Gem::Requirement
17
+ requirement: &26059560 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 0.7.32
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *27888528
25
+ version_requirements: *26059560
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: chingu
28
- requirement: &27888228 !ruby/object:Gem::Requirement
28
+ requirement: &26059164 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ~>
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: 0.9rc5
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *27888228
36
+ version_requirements: *26059164
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: rspec
39
- requirement: &27887940 !ruby/object:Gem::Requirement
39
+ requirement: &26058780 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ~>
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: 2.1.0
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *27887940
47
+ version_requirements: *26058780
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: texplay
50
- requirement: &27887640 !ruby/object:Gem::Requirement
50
+ requirement: &26058396 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ~>
@@ -55,7 +55,7 @@ dependencies:
55
55
  version: 0.3.5
56
56
  type: :development
57
57
  prerelease: false
58
- version_requirements: *27887640
58
+ version_requirements: *26058396
59
59
  description: Fidgit is a GUI library built on Gosu/Chingu
60
60
  email:
61
61
  - bil.bagpuss@gmail.com