Class: Scarpe::Webview::SubscriptionItem
- Inherits:
-
Drawable
- Object
- Shoes::Linkable
- Drawable
- Scarpe::Webview::SubscriptionItem
- Defined in:
- lib/scarpe/wv/subscription_item.rb
Constant Summary
Constants included from Shoes::Log
Shoes::Log::DEFAULT_COMPONENT, Shoes::Log::DEFAULT_DEBUG_LOG_CONFIG, Shoes::Log::DEFAULT_LOG_CONFIG
Instance Attribute Summary
Attributes inherited from Drawable
#children, #parent, #shoes_linkable_id
Attributes inherited from Shoes::Linkable
Instance Method Summary collapse
- #destroy_self ⇒ Object
- #element ⇒ Object
-
#initialize(properties) ⇒ SubscriptionItem
constructor
A new instance of SubscriptionItem.
-
#set_parent(new_parent) ⇒ Object
This will get called once we know the parent, which is useful for events like hover, where our subscription is likely to depend on what our parent is.
Methods inherited from Drawable
#add_child, #bind, display_class_for, #full_window_redraw!, #handler_js_code, #html_element, #html_id, #inspect, #needs_update!, #promise_update, #properties_changed, #remove_child, #shoes_styles, #to_html
Methods included from Shoes::Log
configure_logger, #log_init, logger
Methods inherited from Shoes::Linkable
#bind_shoes_event, #send_self_event, #send_shoes_event, #unsub_all_shoes_events, #unsub_shoes_event
Constructor Details
#initialize(properties) ⇒ SubscriptionItem
Returns a new instance of SubscriptionItem.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/scarpe/wv/subscription_item.rb', line 4 def initialize(properties) super bind(@shoes_api_name) do |*args| send_self_event(*args, event_name: @shoes_api_name) end @wrangler = Scarpe::Webview::DisplayService.instance.wrangler case @shoes_api_name when "animate" frame_rate = (@args[0] || 10) @counter = 0 @wrangler.periodic_code("animate_#{@shoes_linkable_id}", 1.0 / frame_rate) do @counter += 1 send_self_event(@counter, event_name: @shoes_api_name) end when "every" delay = @args[0] @counter = 0 @wrangler.periodic_code("every_#{@shoes_linkable_id}", delay) do @counter += 1 send_self_event(@counter, event_name: @shoes_api_name) end when "timer" # JS setTimeout? raise "Implement me!" when "motion", "hover", "leave", "click", "release", "keypress" # Wait for set_parent else raise Scarpe::UnknownShoesEventAPIError, "Unknown Shoes event API: #{@shoes_api_name}!" end end |
Instance Method Details
#destroy_self ⇒ Object
80 81 82 83 |
# File 'lib/scarpe/wv/subscription_item.rb', line 80 def destroy_self @parent&.remove_event_callbacks(self) super end |
#element ⇒ Object
38 39 40 |
# File 'lib/scarpe/wv/subscription_item.rb', line 38 def element "" end |
#set_parent(new_parent) ⇒ Object
This will get called once we know the parent, which is useful for events like hover, where our subscription is likely to depend on what our parent is.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/scarpe/wv/subscription_item.rb', line 44 def set_parent(new_parent) super case @shoes_api_name when "motion" # TODO: what do we do for whole-screen mousemove outside the window? # Those should be set on body, which right now doesn't have a drawable. # TODO: figure out how to handle alt and meta keys - does Shoes3 recognise those? new_parent.set_event_callback( self, "onmousemove", handler_js_code( @shoes_api_name, "arguments[0].x", "arguments[0].y", "arguments[0].ctrlKey", "arguments[0].shiftKey", ), ) when "hover" new_parent.set_event_callback(self, "onmouseenter", handler_js_code(@shoes_api_name)) when "leave" new_parent.set_event_callback(self, "onmouseleave", handler_js_code(@shoes_api_name)) when "click" new_parent.set_event_callback(self, "onclick", handler_js_code(@shoes_api_name, "arguments[0].button", "arguments[0].x", "arguments[0].y")) when "release" new_parent.set_event_callback(self, "onmouseup", handler_js_code(@shoes_api_name, "arguments[0].button", "arguments[0].x", "arguments[0].y")) when "keypress" raise "Implement me!" when "animate", "every", "timer" # These were handled in initialize(), ignore them here else raise Scarpe::UnknownShoesEventAPIError, "Unknown Shoes event API: #{@shoes_api_name}!" end end |