Class: Reflex::Button
- Inherits:
-
View
- Object
- View
- Reflex::Button
show all
- Defined in:
- lib/reflex/button.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from View
#capturing?, #children, #delay, #find_child, has_model, #interval, #on_contact, #on_contact_begin, #on_contact_end, #remove_self, #shapes, #style, #styles, #timeout
Methods included from HasTags
#clear_tags, #tag, #tag=, #tags, #untag
Methods included from HasFrame
#inset_by, #move_by, #move_to, #resize_by, #resize_to
Methods included from Hookable
#hook
Constructor Details
#initialize(*args, &block) ⇒ Button
13
14
15
16
17
|
# File 'lib/reflex/button.rb', line 13
def initialize(*args, &block)
self.data = false
super
self.text = self.name unless self.text
end
|
Instance Attribute Details
#text ⇒ Object
Returns the value of attribute text.
11
12
13
|
# File 'lib/reflex/button.rb', line 11
def text
@text
end
|
Instance Method Details
#content_bounds ⇒ Object
19
20
21
22
|
# File 'lib/reflex/button.rb', line 19
def content_bounds()
f = window.painter.font
return f.width(@text) + 2, f.height + 2
end
|
#on_data_update(e) ⇒ Object
60
61
62
|
# File 'lib/reflex/button.rb', line 60
def on_data_update(e)
on_press({}) if e.data
end
|
#on_draw(e) ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/reflex/button.rb', line 27
def on_draw(e)
e.painter.push fill: (pressing? ? :white : :none), stroke: :white do |p|
p.rect e.bounds
if @text
p.fill pressing? ? :black : :white
x = (e.bounds.w - p.font.w(@text)) / 2
y = (e.bounds.h - p.font.h) / 2
p.text @text, x, y
end
p.fill :none
p.rect e.bounds
end
end
|
#on_pointer(e) ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/reflex/button.rb', line 43
def on_pointer(e)
case e.action
when :down
self.capture += [:pointer]
redraw
when :up
if pressing?
self.capture -= [:pointer]
if frame.move_to(0, 0).include? e.position
self.data = true
self.data = false
end
redraw
end
end
end
|
#on_press(e) ⇒ Object
24
25
|
# File 'lib/reflex/button.rb', line 24
def on_press(e)
end
|