Class: Reflex::Button

Inherits:
View
  • Object
show all
Defined in:
lib/reflex/button.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from View

#capture, #capture=, #capturing?, #children, #gravity=, has_model, #style, #styles

Methods included from HasTags

#clear_tags, #tag, #tag=, #tags, #untag

Methods included from HasFrame

#frame, #frame=, #inset_by, #move_by, #move_to, #resize_by, #resize_to

Methods included from Hookable

#hook

Constructor Details

#initialize(*args, &block) ⇒ Button

Returns a new instance of Button.



16
17
18
19
# File 'lib/reflex/button.rb', line 16

def initialize (*args, &block)
  self.data = false
  super
end

Instance Attribute Details

#textObject

Returns the value of attribute text.



14
15
16
# File 'lib/reflex/button.rb', line 14

def text
  @text
end

Instance Method Details

#content_sizeObject



21
22
23
24
# File 'lib/reflex/button.rb', line 21

def content_size ()
  f = window.painter.font
  return f.width(@text) + 2, f.height + 2
end

#on_data_update(e) ⇒ Object



62
63
64
# File 'lib/reflex/button.rb', line 62

def on_data_update (e)
  on_press({}) if e.data
end

#on_draw(e) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/reflex/button.rb', line 29

def on_draw (e)
  e.painter.color (pressing? ? :white : :none), :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



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/reflex/button.rb', line 45

def on_pointer (e)
  case e.type
  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



26
27
# File 'lib/reflex/button.rb', line 26

def on_press (e)
end