Class: Niente::Drawable
- Inherits:
-
Shoes::Linkable
- Object
- Shoes::Linkable
- Niente::Drawable
- Defined in:
- lacci/lib/scarpe/niente/drawable.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#shoes_linkable_id ⇒ Object
readonly
Returns the value of attribute shoes_linkable_id.
-
#shoes_type ⇒ Object
Returns the value of attribute shoes_type.
Attributes inherited from Shoes::Linkable
Instance Method Summary collapse
-
#add_child(child) ⇒ Object
Do not call directly, use set_parent.
-
#initialize(props) ⇒ Drawable
constructor
A new instance of Drawable.
-
#remove_child(child) ⇒ Object
Do not call directly, use set_parent.
- #set_parent(new_parent) ⇒ Object
Methods inherited from Shoes::Linkable
#bind_shoes_event, #send_self_event, #send_shoes_event, #unsub_all_shoes_events, #unsub_shoes_event
Constructor Details
#initialize(props) ⇒ Drawable
Returns a new instance of Drawable.
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 |
# File 'lacci/lib/scarpe/niente/drawable.rb', line 9 def initialize(props) @shoes_linkable_id = props.delete("shoes_linkable_id") || props.delete(:shoes_linkable_id) @data = props super(linkable_id: @shoes_linkable_id) # This should only be used for reparenting after a drawable was initially created. bind_shoes_event(event_name: "parent", target: shoes_linkable_id) do |new_parent_id| display_parent = DisplayService.instance.query_display_drawable_for(new_parent_id) if @parent != display_parent set_parent(display_parent) end end # When Shoes drawables change properties, we get a change notification here bind_shoes_event(event_name: "prop_change", target: shoes_linkable_id) do |prop_changes| prop_changes.each do |k, v| instance_variable_set("@" + k, v) end properties_changed(prop_changes) if respond_to?(:properties_changed) end bind_shoes_event(event_name: "destroy", target: shoes_linkable_id) do set_parent(nil) end end |
Instance Attribute Details
#children ⇒ Object (readonly)
Returns the value of attribute children.
5 6 7 |
# File 'lacci/lib/scarpe/niente/drawable.rb', line 5 def children @children end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
4 5 6 |
# File 'lacci/lib/scarpe/niente/drawable.rb', line 4 def parent @parent end |
#shoes_linkable_id ⇒ Object (readonly)
Returns the value of attribute shoes_linkable_id.
3 4 5 |
# File 'lacci/lib/scarpe/niente/drawable.rb', line 3 def shoes_linkable_id @shoes_linkable_id end |
#shoes_type ⇒ Object
Returns the value of attribute shoes_type.
7 8 9 |
# File 'lacci/lib/scarpe/niente/drawable.rb', line 7 def shoes_type @shoes_type end |
Instance Method Details
#add_child(child) ⇒ Object
Do not call directly, use set_parent
53 54 55 56 |
# File 'lacci/lib/scarpe/niente/drawable.rb', line 53 def add_child(child) @children ||= [] @children << child end |
#remove_child(child) ⇒ Object
Do not call directly, use set_parent
43 44 45 46 47 48 49 50 |
# File 'lacci/lib/scarpe/niente/drawable.rb', line 43 def remove_child(child) @children ||= [] unless @children.include?(child) STDERR.puts("remove_child: no such child(#{child.inspect}) for"\ " parent(#{parent.inspect})!") end @children.delete(child) end |
#set_parent(new_parent) ⇒ Object
36 37 38 39 40 |
# File 'lacci/lib/scarpe/niente/drawable.rb', line 36 def set_parent(new_parent) @parent&.remove_child(self) new_parent&.add_child(self) @parent = new_parent end |