Class: Shoes::Slot
- Defined in:
- lacci/lib/shoes.rb,
lacci/lib/shoes/drawables/slot.rb
Constant Summary
Constants inherited from Drawable
Constants included from Log
Log::DEFAULT_COMPONENT, Log::DEFAULT_DEBUG_LOG_CONFIG, Log::DEFAULT_LOG_CONFIG
Instance Attribute Summary collapse
- #children ⇒ Object readonly
-
#draw_context ⇒ Object
readonly
This only shows this specific slot's settings, not its parent's.
Attributes inherited from Drawable
#debug_id, #destroyed, #parent
Attributes inherited from Linkable
Instance Method Summary collapse
-
#add_child(child) ⇒ Object
Do not call directly, use set_parent.
-
#append { ... } ⇒ void
Call the block to append new children to a Slot.
-
#clear { ... } ⇒ void
Remove all children from this drawable.
-
#contents ⇒ Object
Get a list of child drawables.
-
#current_draw_context ⇒ Hash
Get the current draw context styles, based on this slot and its parent slots.
-
#fill(color) ⇒ void
Set the default fill color in this slot and child slots.
-
#initialize ⇒ Slot
constructor
A new instance of Slot.
-
#method_missing(name, *args, **kwargs, &block) ⇒ Object
We use method_missing for drawable-creating methods like "button".
-
#nofill ⇒ void
Set the default fill in this slot and child slots to transparent.
-
#nostroke ⇒ void
Set the default stroke in this slot and child slots to transparent.
-
#remove_child(child) ⇒ Object
Do not call directly, use set_parent.
- #respond_to_missing?(name, include_private = false) ⇒ Boolean
-
#rotate(angle) ⇒ void
Set the current rotation in this slot and any child slots.
-
#stroke(color) ⇒ void
Set the default stroke color in this slot and child slots.
-
#strokewidth(width) ⇒ void
Set the default strokewidth in this slot and child slots.
Methods inherited from Drawable
allocate_drawable_id, #app, #banner, #caption, convert_to_float, convert_to_integer, #destroy, #download, drawable_by_id, drawable_class_by_name, dsl_name, #event, expects_parent?, feature_for_shoes_style, get_shoes_events, #hide, #hover, init_args, #inscription, #inspect, is_widget_class?, #leave, #motion, opt_init_args, optional_init_args, register_drawable_id, registered_shoes_events?, required_init_args, #set_parent, shoes_events, shoes_style, shoes_style_hashes, shoes_style_name?, shoes_style_names, #shoes_style_values, shoes_styles, #show, #style, #subtitle, #tagline, #title, #toggle, unregister_drawable_id, validate_as
Methods included from MarginHelper
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_all_shoes_events, #unsub_shoes_event
Constructor Details
#initialize ⇒ Slot
Returns a new instance of Slot.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lacci/lib/shoes/drawables/slot.rb', line 14 def initialize(...) # The draw context tracks current settings like fill and stroke, # plus potentially other current state that changes from drawable # to drawable and slot to slot. @draw_context = { "fill" => nil, "stroke" => nil, "strokewidth" => nil, "rotate" => nil, # "transform" => nil, # "corner", # "translate" => nil, # [0, 0], } super end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, **kwargs, &block) ⇒ Object
We use method_missing for drawable-creating methods like "button". The parent's method_missing will auto-create Shoes style getters and setters. This is similar to the method_missing in Shoes::App, but differs in where the new drawable will appear.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lacci/lib/shoes/drawables/slot.rb', line 55 def method_missing(name, *args, **kwargs, &block) klass = ::Shoes::Drawable.drawable_class_by_name(name) return super unless klass ::Shoes::Slot.define_method(name) do |*args, **kwargs, &block| instance = nil # Look up the Shoes drawable and create it. But first set # this slot as the current one so that draw context # is handled properly. Shoes::App.instance.with_slot(self) do instance = klass.new(*args, **kwargs, &block) end instance end send(name, *args, **kwargs, &block) end |
Instance Attribute Details
#children ⇒ Object (readonly)
5 6 7 |
# File 'lacci/lib/shoes/drawables/slot.rb', line 5 def children @children end |
#draw_context ⇒ Object (readonly)
This only shows this specific slot's settings, not its parent's. Use current_draw_context to allow inheritance.
11 12 13 |
# File 'lacci/lib/shoes/drawables/slot.rb', line 11 def draw_context @draw_context end |
Instance Method Details
#add_child(child) ⇒ Object
Do not call directly, use set_parent
40 41 42 43 |
# File 'lacci/lib/shoes/drawables/slot.rb', line 40 def add_child(child) @children ||= [] @children << child end |
#append { ... } ⇒ void
This method returns an undefined value.
Call the block to append new children to a Slot.
Should only be called on a Slot, since only Slots can have children.
172 173 174 175 176 177 |
# File 'lacci/lib/shoes/drawables/slot.rb', line 172 def append(&block) raise(Shoes::Errors::InvalidAttributeValueError, "append requires a block!") unless block_given? raise(Shoes::Errors::InvalidAttributeValueError, "Don't append to something that isn't a slot!") unless self.is_a?(Shoes::Slot) Shoes::App.instance.with_slot(self, &block) end |
#clear { ... } ⇒ void
This method returns an undefined value.
Remove all children from this drawable. If a block is given, call the block to replace the children with new contents from that block.
Should only be called on Slots, which can have children.
157 158 159 160 161 162 |
# File 'lacci/lib/shoes/drawables/slot.rb', line 157 def clear(&block) @children ||= [] @children.dup.each(&:destroy) append(&block) if block_given? nil end |
#contents ⇒ Object
Get a list of child drawables
46 47 48 49 |
# File 'lacci/lib/shoes/drawables/slot.rb', line 46 def contents @children ||= [] @children.dup end |
#current_draw_context ⇒ Hash
Get the current draw context styles, based on this slot and its parent slots.
137 138 139 140 141 142 |
# File 'lacci/lib/shoes/drawables/slot.rb', line 137 def current_draw_context s = @parent ? @parent.current_draw_context : {} @draw_context.each { |k, v| s[k] = v unless v.nil? } s end |
#fill(color) ⇒ void
This method returns an undefined value.
Set the default fill color in this slot and child slots. Pass nil for "no setting", so that it can inherit defaults.
88 89 90 |
# File 'lacci/lib/shoes/drawables/slot.rb', line 88 def fill(color) @draw_context["fill"] = color end |
#nofill ⇒ void
This method returns an undefined value.
Set the default fill in this slot and child slots to transparent.
95 96 97 |
# File 'lacci/lib/shoes/drawables/slot.rb', line 95 def nofill @draw_context["fill"] = rgb(0, 0, 0, 0) end |
#nostroke ⇒ void
This method returns an undefined value.
Set the default stroke in this slot and child slots to transparent.
121 122 123 |
# File 'lacci/lib/shoes/drawables/slot.rb', line 121 def nostroke @draw_context["stroke"] = rgb(0, 0, 0, 0) end |
#remove_child(child) ⇒ Object
Do not call directly, use set_parent
31 32 33 34 35 36 37 |
# File 'lacci/lib/shoes/drawables/slot.rb', line 31 def remove_child(child) @children ||= [] unless @children.include?(child) @log.warn("remove_child: no such child(#{child.inspect}) for parent(#{parent.inspect})!") end @children.delete(child) end |
#respond_to_missing?(name, include_private = false) ⇒ Boolean
75 76 77 78 79 |
# File 'lacci/lib/shoes/drawables/slot.rb', line 75 def respond_to_missing?(name, include_private = false) return true if ::Shoes::Drawable.drawable_class_by_name(name.to_s) false end |
#rotate(angle) ⇒ void
This method returns an undefined value.
Set the current rotation in this slot and any child slots. Pass nil to reset the angle to default.
130 131 132 |
# File 'lacci/lib/shoes/drawables/slot.rb', line 130 def rotate(angle) @draw_context["rotate"] = angle end |
#stroke(color) ⇒ void
This method returns an undefined value.
Set the default stroke color in this slot and child slots. Pass nil for "no setting" so it can inherit defaults.
104 105 106 |
# File 'lacci/lib/shoes/drawables/slot.rb', line 104 def stroke(color) @draw_context["stroke"] = color end |
#strokewidth(width) ⇒ void
This method returns an undefined value.
Set the default strokewidth in this slot and child slots. Pass nil for "no setting".
113 114 115 |
# File 'lacci/lib/shoes/drawables/slot.rb', line 113 def strokewidth(width) @draw_context["strokewidth"] = width end |