Class: Niente::DisplayService

Inherits:
Shoes::DisplayService show all
Includes:
Shoes::Log
Defined in:
lacci/lib/scarpe/niente/display_service.rb

Overview

This is a "null" DisplayService, doing as little as it can get away with.

Constant Summary

Constants included from Shoes::Log

Shoes::Log::DEFAULT_COMPONENT, Shoes::Log::DEFAULT_DEBUG_LOG_CONFIG, Shoes::Log::DEFAULT_LOG_CONFIG

Class Attribute Summary collapse

Instance Method Summary collapse

Methods included from Shoes::Log

configure_logger, #log_init, logger

Methods inherited from Shoes::DisplayService

dispatch_event, display_service, full_reset!, #query_display_drawable_for, set_display_service_class, #set_drawable_pairing, subscribe_to_event, unsub_from_events

Constructor Details

#initializeDisplayService

Returns a new instance of DisplayService.



13
14
15
16
17
18
19
20
21
22
# File 'lacci/lib/scarpe/niente/display_service.rb', line 13

def initialize
  if Niente::DisplayService.instance
    raise Shoes::SingletonError, "ERROR! This is meant to be a singleton!"
  end

  Niente::DisplayService.instance = self

  log_init("Niente::DisplayService")
  super()
end

Class Attribute Details

.instanceObject

Returns the value of attribute instance.



10
11
12
# File 'lacci/lib/scarpe/niente/display_service.rb', line 10

def instance
  @instance
end

Instance Method Details

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

Create a fake display drawable for a specific Shoes drawable, and pair it with the linkable ID for this Shoes drawable.

Parameters:

  • drawable_class_name (String)

    The class name of the Shoes drawable, e.g. Shoes::Button

  • drawable_id (String)

    the linkable ID for drawable events

  • properties (Hash)

    a JSON-serialisable Hash with the drawable's Shoes styles

  • is_widget (Boolean)

    whether the class is a user-defined Shoes::Widget subclass

Returns:

  • (Webview::Drawable)

    the newly-created Webview drawable



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lacci/lib/scarpe/niente/display_service.rb', line 32

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)
  if existing
    @log.warn("There is already a display drawable for #{drawable_id.inspect}! Returning #{existing.class.name}.")
    return existing
  end

  if drawable_class_name == "App"
    @app = Niente::App.new(properties)
    set_drawable_pairing(drawable_id, @app)

    return @app
  end

  display_drawable = Niente::Drawable.new(properties)
  display_drawable.shoes_type = drawable_class_name
  set_drawable_pairing(drawable_id, display_drawable)

  # Nil parent is okay for DocumentRoot and TextDrawables, so we have to specify it.
  parent = DisplayService.instance.query_display_drawable_for(parent_id, nil_ok: true)
  display_drawable.set_parent(parent)

  return display_drawable
end

#destroyvoid

This method returns an undefined value.

Destroy the display service and the app. Quit the process (eventually.)



60
61
62
63
# File 'lacci/lib/scarpe/niente/display_service.rb', line 60

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