Class: Clogs::SubscriptionItem

Inherits:
Drawable
  • Object
show all
Defined in:
lib/clogs/drawables/misc.rb

Overview

animate, every, timer, motion, click, hover, keypress: Shoes calls that subscribe to something rather than drawing anything.

Instance Attribute Summary

Attributes inherited from Drawable

#abs_x, #abs_y, #children, #height, #parent, #shoes_linkable_id, #styles, #width, #x, #y

Instance Method Summary collapse

Methods inherited from Drawable

#add_child, #app, #contains?, #draw, #each_peer, #focus_gained, #focus_lost, #focusable?, for_shoes_class, #hidden?, #margin, #needs_layout!, #notify, #on_click, #on_key, #on_mouse_move, #on_release, #paint, #positioned?, #properties_changed, #redraw!, #remove_child, #requested_height, #requested_width, #style

Constructor Details

#initialize(properties) ⇒ SubscriptionItem

Returns a new instance of SubscriptionItem.



10
11
12
13
14
# File 'lib/clogs/drawables/misc.rb', line 10

def initialize(properties)
  super
  @frame = 0
  start_timer
end

Instance Method Details

#api_nameObject



16
17
18
# File 'lib/clogs/drawables/misc.rb', line 16

def api_name
  style(:shoes_api_name).to_s
end

#argsObject



20
21
22
# File 'lib/clogs/drawables/misc.rb', line 20

def args
  Array(style(:args))
end

#clickable?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/clogs/drawables/misc.rb', line 29

def clickable?
  false
end

#destroy_selfObject



72
73
74
75
# File 'lib/clogs/drawables/misc.rb', line 72

def destroy_self
  @stopped = true
  super
end

#install_timerObject



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/clogs/drawables/misc.rb', line 54

def install_timer
  return unless @pending_timer
  return unless app

  interval, repeat, block = @pending_timer
  @pending_timer = nil
  @stopped = false
  app.add_timer(interval, repeat: repeat) do
    block.call unless @stopped
  end
end

#measure(_available_width) ⇒ Object



24
25
26
27
# File 'lib/clogs/drawables/misc.rb', line 24

def measure(_available_width)
  @width = 0
  @height = 0
end

#schedule(interval, repeat: true, &block) ⇒ Object

The app may not exist yet when the subscription is created, so defer.



49
50
51
52
# File 'lib/clogs/drawables/misc.rb', line 49

def schedule(interval, repeat: true, &block)
  @pending_timer = [interval, repeat, block]
  install_timer
end

#set_parent(new_parent) ⇒ Object



66
67
68
69
70
# File 'lib/clogs/drawables/misc.rb', line 66

def set_parent(new_parent)
  super
  @app = nil
  install_timer
end

#start_timerObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/clogs/drawables/misc.rb', line 33

def start_timer
  case api_name
  when "animate"
    fps = (args[0] || 10).to_i
    fps = 10 if fps <= 0
    schedule(1000 / fps) { notify("animate", @frame += 1) }
  when "every"
    seconds = (args[0] || 1).to_f
    schedule((seconds * 1000).round) { notify("every", @frame += 1) }
  when "timer"
    seconds = (args[0] || 1).to_f
    schedule((seconds * 1000).round, repeat: false) { notify("timer") }
  end
end