fidgit 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,13 @@
1
1
  Fidgit changelog
2
2
  ================
3
3
 
4
+ v0.2.1
5
+ ------
6
+
7
+ * Added: Click in ScrollBar gutter to scroll window by height/width of view window.
8
+ * Added: Click and drag to select text in enabled TextArea.
9
+ * Fixed: Color changes on disabling buttons.
10
+
4
11
  v0.2.0
5
12
  ------
6
13
 
@@ -117,7 +117,7 @@
117
117
  :icon_position: :left
118
118
 
119
119
  :disabled:
120
- :color: ?light_gray
120
+ :color: ?gray
121
121
 
122
122
  :List:
123
123
  :background_color: ?light_gray
@@ -6,7 +6,7 @@ class ExampleState < Fidgit::GuiState
6
6
 
7
7
  Gosu.register_entity(:entity, Gosu::Image["head_icon.png"])
8
8
 
9
- string = "<c=3333ff>Hello, my name</c> is <c=ff0000>Brian</c> the&entity;&entity;snail<c=00ff00>!\nHi\nHello!</c>"
9
+ string = "<c=3333ff>Hello, my name</c> is <c=ff0000>Brian</c> the&entity;&entity;snail!"
10
10
  horizontal do
11
11
  vertical do
12
12
  label 'disabled'
@@ -82,17 +82,15 @@ module Fidgit
82
82
 
83
83
  protected
84
84
  def update_colors
85
- @background_color = if @mouse_over and enabled?
86
- default(:hover, :background_color)
87
- else
88
- default(:background_color)
85
+ [:color, :background_color, :border_color].each do |attribute|
86
+ send :"#{attribute.to_s}=", enabled? ? default(attribute) : default(:disabled, attribute)
89
87
  end
90
88
 
91
- self.color = if enabled?
92
- default(:color)
93
- else
94
- default(:disabled, :color)
95
- end
89
+ self.background_color = if @mouse_over and enabled?
90
+ default(:hover, :background_color)
91
+ else
92
+ default(:background_color)
93
+ end
96
94
 
97
95
  @icon.enabled = enabled? if @icon
98
96
 
@@ -47,6 +47,10 @@ module Fidgit
47
47
  @handle_container = Container.new(parent: self, width: options[:width], height: options[:height]) do
48
48
  @handle = Handle.new(parent: self, x: x, y: y, background_color: options[:handle_color])
49
49
  end
50
+
51
+ subscribe :left_mouse_button do |sender, x, y|
52
+ clicked_to_move x, y
53
+ end
50
54
  end
51
55
  end
52
56
 
@@ -81,6 +85,11 @@ module Fidgit
81
85
  def handle_dragged_to(x, y)
82
86
  @owner.offset_x = @owner.content_width * ((x - self.x) / width.to_f)
83
87
  end
88
+
89
+ def clicked_to_move(x, y)
90
+ new_x = x < @handle.x ? @handle.x - @handle.width : @handle.x + @handle.width
91
+ handle_dragged_to new_x, @handle.y
92
+ end
84
93
  end
85
94
 
86
95
  class VerticalScrollBar < ScrollBar
@@ -110,5 +119,10 @@ module Fidgit
110
119
  def handle_dragged_to(x, y)
111
120
  @owner.offset_y = @owner.content_height * ((y - self.y) / height.to_f)
112
121
  end
122
+
123
+ def clicked_to_move(x, y)
124
+ new_y = y < @handle.y ? @handle.y - @handle.height : @handle.y + @handle.height
125
+ handle_dragged_to @handle.x, new_y
126
+ end
113
127
  end
114
128
  end
@@ -2,8 +2,7 @@
2
2
 
3
3
  module Fidgit
4
4
  class ScrollWindow < Composite
5
- def content; @view.content; end
6
-
5
+ def content; @view.content; end
7
6
  def offset_x; @view.offset_x; end
8
7
  def offset_x=(value); @view.offset_x = value; end
9
8
  def offset_y; @view.offset_y; end
@@ -13,9 +12,8 @@ module Fidgit
13
12
  def view_height; @view.height; end
14
13
  def content_width; @view.content.width; end
15
14
  def content_height; @view.content.height; end
16
-
17
- def width=(value); super(value); end
18
- def height=(value); super(value); end
15
+ def width=(value); super(value); end
16
+ def height=(value); super(value); end
19
17
 
20
18
  def initialize(options = {})
21
19
  options = {
@@ -19,10 +19,16 @@ module Fidgit
19
19
  # @return [String] Text, but stripped of tags.
20
20
  attr_reader :stripped_text
21
21
 
22
+ event :begin_drag
23
+ event :update_drag
24
+ event :end_drag
25
+
22
26
  event :changed
23
27
  event :focus
24
28
  event :blur
25
29
 
30
+ def drag?(button); button == :left; end
31
+
26
32
  # Is the area editable? This will always be false if the Element is disabled.
27
33
  def editable?
28
34
  enabled? and @editable
@@ -161,6 +167,21 @@ module Fidgit
161
167
 
162
168
  subscribe :left_mouse_button, method(:click_in_text)
163
169
  subscribe :right_mouse_button, method(:click_in_text)
170
+
171
+ # Handle dragging.
172
+ subscribe :begin_drag do |sender, x, y|
173
+ # Store position of the handle when it starts to drag.
174
+ @drag_start_pos = [x - self.x, y - self.y]
175
+ end
176
+
177
+ subscribe :update_drag do |sender, x, y|
178
+ index = text_index_at_position(x, y)
179
+ self.caret_position = [index, @stripped_text.length].min if index
180
+ end
181
+
182
+ subscribe :end_drag do
183
+ @drag_start_pos = nil
184
+ end
164
185
  end
165
186
 
166
187
  # @return [nil]
@@ -168,14 +189,8 @@ module Fidgit
168
189
  publish :focus unless focused?
169
190
 
170
191
  # Move caret to position the user clicks on.
171
- mouse_x, mouse_y = x - (self.x + padding_left), y - (self.y + padding_top)
172
- @char_widths.each_with_index do |width, i|
173
- char_x, char_y = @caret_positions[i]
174
- if mouse_x.between?(char_x, char_x + width) and mouse_y.between?(char_y, char_y + font.height)
175
- self.caret_position = @text_input.selection_start = i
176
- break
177
- end
178
- end
192
+ index = text_index_at_position x, y
193
+ self.caret_position = @text_input.selection_start = [index, @stripped_text.length].min if index
179
194
 
180
195
  nil
181
196
  end
@@ -246,6 +261,21 @@ module Fidgit
246
261
  end
247
262
  end
248
263
 
264
+ protected
265
+ # Index of character in reference to the displayable text.
266
+ def text_index_at_position(x, y)
267
+ # Move caret to position the user clicks on.
268
+ mouse_x, mouse_y = x - (self.x + padding_left), y - (self.y + padding_top)
269
+ @char_widths.each.with_index do |width, i|
270
+ char_x, char_y = @caret_positions[i]
271
+ if mouse_x.between?(char_x, char_x + width) and mouse_y.between?(char_y, char_y + font.height)
272
+ return i
273
+ end
274
+ end
275
+
276
+ nil # Didn't find a character at that position.
277
+ end
278
+
249
279
  # y position of the
250
280
  protected
251
281
  def y_at_line(lines_number)
@@ -1,5 +1,5 @@
1
1
  # encoding: UTF-8
2
2
 
3
3
  module Fidgit
4
- VERSION = '0.2.0'
4
+ VERSION = '0.2.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.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-02-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: gosu
16
- requirement: &24620268 !ruby/object:Gem::Requirement
16
+ requirement: &28344852 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.7.41
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *24620268
24
+ version_requirements: *28344852
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: chingu
27
- requirement: &24619380 !ruby/object:Gem::Requirement
27
+ requirement: &28344576 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 0.9rc7
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *24619380
35
+ version_requirements: *28344576
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: clipboard
38
- requirement: &22646484 !ruby/object:Gem::Requirement
38
+ requirement: &28344300 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 0.9.9
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *22646484
46
+ version_requirements: *28344300
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: ffi
49
- requirement: &22644636 !ruby/object:Gem::Requirement
49
+ requirement: &28344024 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - =
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 1.0.9
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *22644636
57
+ version_requirements: *28344024
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rspec
60
- requirement: &22640532 !ruby/object:Gem::Requirement
60
+ requirement: &28343748 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 2.8.0
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *22640532
68
+ version_requirements: *28343748
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: texplay
71
- requirement: &22639572 !ruby/object:Gem::Requirement
71
+ requirement: &28343472 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: 0.3.5
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *22639572
79
+ version_requirements: *28343472
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: rake
82
- requirement: &22638696 !ruby/object:Gem::Requirement
82
+ requirement: &28343244 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *22638696
90
+ version_requirements: *28343244
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: yard
93
- requirement: &22654308 !ruby/object:Gem::Requirement
93
+ requirement: &28342968 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: '0'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *22654308
101
+ version_requirements: *28342968
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: RedCloth
104
- requirement: &22653528 !ruby/object:Gem::Requirement
104
+ requirement: &28342668 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ~>
@@ -109,7 +109,7 @@ dependencies:
109
109
  version: 4.2.9
110
110
  type: :development
111
111
  prerelease: false
112
- version_requirements: *22653528
112
+ version_requirements: *28342668
113
113
  description: Fidgit is a GUI library built on Gosu/Chingu
114
114
  email:
115
115
  - bil.bagpuss@gmail.com