Class: Clogs::DisplayService

Inherits:
Shoes::DisplayService
  • Object
show all
Defined in:
lib/clogs/display_service.rb

Overview

Lacci's half of the bargain: it hands us a Shoes drawable class name and an id, and expects a display-side peer back. Everything after that happens through events on that id.

Constant Summary collapse

PEERS =

Shoes class name (minus namespace) => Clogs peer class.

{
  "App" => "App",
  "DocumentRoot" => "DocumentRoot",
  "Stack" => "Stack",
  "Flow" => "Flow",
  "Shape" => "Shape",
  "Mask" => "Mask",
  "Para" => "Para",
  "Link" => "Link",
  "LinkHover" => "Link",
  "Strong" => "Strong",
  "Em" => "Em",
  "Code" => "Code",
  "Del" => "Del",
  "Ins" => "Ins",
  "Sub" => "Sub",
  "Sup" => "Sup",
  "Span" => "Span",
  "Bg" => "Bg",
  "Fg" => "Fg",
  "Button" => "Button",
  "Check" => "Check",
  "Radio" => "Radio",
  "Progress" => "Progress",
  "EditLine" => "EditLine",
  "EditBox" => "EditBox",
  "ListBox" => "ListBox",
  "Image" => "Image",
  "Video" => "Video",
  "Arrow" => "Arrow",
  "Rect" => "Rect",
  "Oval" => "Oval",
  "Line" => "Line",
  "Star" => "Star",
  "Arc" => "Arc",
  "Background" => "Background",
  "Border" => "Border",
  "SubscriptionItem" => "SubscriptionItem"
}.freeze

Class Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDisplayService

Returns a new instance of DisplayService.

Raises:

  • (Shoes::SingletonError)


15
16
17
18
19
20
# File 'lib/clogs/display_service.rb', line 15

def initialize
  raise Shoes::SingletonError, "Clogs::DisplayService is a singleton!" if DisplayService.instance

  DisplayService.instance = self
  super()
end

Class Attribute Details

.instanceObject

Returns the value of attribute instance.



12
13
14
# File 'lib/clogs/display_service.rb', line 12

def instance
  @instance
end

Instance Method Details

#build_peer(class_name, properties, is_widget) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/clogs/display_service.rb', line 89

def build_peer(class_name, properties, is_widget)
  short = class_name.to_s.split("::").last
  return Widget.new(properties) if is_widget && !PEERS.key?(short)

  peer_name = PEERS[short]
  if peer_name
    Clogs.const_get(peer_name).new(properties)
  else
    # A Shoes drawable Clogs does not know about still needs a peer so the
    # tree stays consistent; it simply draws nothing.
    warn "Clogs: no peer for #{class_name}, ignoring it visually."
    Drawable.new(properties)
  end
end

#create_display_drawable_for(drawable_class_name, drawable_id, properties, parent_id:, is_widget:) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/clogs/display_service.rb', line 63

def create_display_drawable_for(drawable_class_name, drawable_id, properties, parent_id:, is_widget:)
  existing = query_display_drawable_for(drawable_id, nil_ok: true)
  return existing if existing

  properties = properties.dup
  properties["shoes_linkable_id"] ||= drawable_id

  peer = build_peer(drawable_class_name, properties, is_widget)
  set_drawable_pairing(drawable_id, peer)

  if peer.is_a?(App)
    @app = peer
  else
    parent = parent_id ? query_display_drawable_for(parent_id, nil_ok: true) : nil
    peer.set_parent(parent)
    @document_root = peer if peer.is_a?(DocumentRoot)
  end

  # Lacci builds the document root *before* the app, so neither one can
  # simply look the other up on creation. Whichever arrives second links
  # them: the root is the app's canvas contents but is not its child.
  @app.document_root = @document_root if @app && @document_root && @app.document_root.nil?

  peer
end

#destroyObject



104
105
106
107
# File 'lib/clogs/display_service.rb', line 104

def destroy
  @app&.destroy
  DisplayService.instance = nil
end