Class: Shoes::SubscriptionItem
- Defined in:
- lacci/lib/shoes/widgets/subscription_item.rb
Overview
Certain Shoes calls like motion and keydown are basically an event subscription, with no other visible presence. However, they have a place in the widget tree and can be deleted.
Depending on the display library they may not have any direct visual (or similar) presence there either.
Inheriting from Widget gives these a parent slot and a linkable_id automatically.
Constant Summary
Constants included from Log
Log::DEFAULT_COMPONENT, Log::DEFAULT_DEBUG_LOG_CONFIG, Log::DEFAULT_LOG_CONFIG
Instance Attribute Summary
Attributes inherited from Widget
Attributes inherited from Linkable
Instance Method Summary collapse
- #destroy ⇒ Object
-
#initialize(shoes_api_name:, &block) ⇒ SubscriptionItem
constructor
A new instance of SubscriptionItem.
Methods inherited from Widget
#banner, #caption, display_properties, display_property, display_property_name?, display_property_names, #display_property_values, #download, dsl_name, #hide, #inscription, #inspect, #method_missing, #respond_to_missing?, #set_parent, #show, #subtitle, #tagline, #title, #toggle, widget_class_by_name
Methods included from Colors
Methods included from Log
configure_logger, #log_init, logger
Methods inherited from Linkable
#bind_shoes_event, #send_self_event, #send_shoes_event, #unsub_shoes_event
Constructor Details
#initialize(shoes_api_name:, &block) ⇒ SubscriptionItem
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lacci/lib/shoes/widgets/subscription_item.rb', line 15 def initialize(shoes_api_name:, &block) super @callback = block case shoes_api_name when "hover" # Hover passes the Shoes widget as the block param @unsub_id = bind_self_event("hover") do @callback&.call(self) end when "motion" # Shoes sends back x, y, mods as the args. # Shoes3 uses the strings "control" "shift" and # "control_shift" as the mods arg. @unsub_id = bind_self_event("motion") do |x, y, ctrl_key, shift_key, **_kwargs| mods = [ctrl_key ? "control" : nil, shift_key ? "shift" : nil].compact.join("_") @callback&.call(x, y, mods) end when "click" # Click has block params button, left, top # button is the button number, left and top are coords @unsub_id = bind_self_event("click") do |, x, y, **_kwargs| @callback&.call(, x, y) end else raise "Unknown Shoes API call #{shoes_api_name.inspect} passed to SubscriptionItem!" end @unsub_id = bind_self_event(shoes_api_name) do |*args| @callback&.call(*args) end # This won't create a visible display widget, but will turn into # an invisible widget and a stream of events. end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Shoes::Widget
Instance Method Details
#destroy ⇒ Object
53 54 55 56 57 58 59 |
# File 'lacci/lib/shoes/widgets/subscription_item.rb', line 53 def destroy # TODO: we need a better way to do this automatically. See https://github.com/scarpe-team/scarpe/issues/291 unsub_shoes_event(@unsub_id) if @unsub_id @unsub_id = nil super end |