class Cura::Component::Base
The base class for all components.
All components use a box model similar to CSS. Margins
, borders, paddings, then content.
Public Class Methods
On subclass hook.
# File lib/cura/component/base.rb, line 25 def inherited(subclass) super Component.all << subclass end
The type of this component class.
@example
Cura::Component::XMLTools::AttributeLabel.type # => :xml_tools_attribute_label
@return [Symbol]
# File lib/cura/component/base.rb, line 36 def type # TODO: Helper method for this sort of thing @type ||= to_s.gsub(/^Cura::Component::/, "") .gsub(/([A-Z][A-Za-z]*)([A-Z][A-Za-z0-9_]*)/, "\\1_\\2") .gsub(/::/, "_").downcase.to_sym end
Public Instance Methods
Get the application of this object.
@return [Application]
# File lib/cura/component/base.rb, line 76 def application return nil if parent.nil? parent.application end
Get the background color of this object.
@return [Color]
# File lib/cura/component/base.rb, line 129 def background get_or_inherit_color(:background, Color.white) end
Determine if the given absolute coordinates are within the bounds of this component.
@param [#to_h] options @option options [#to_i] :x @option options [#to_i] :y @return [Boolean]
# File lib/cura/component/base.rb, line 113 def contains_coordinates?(options={}) options = options.to_h (absolute_x..absolute_x + width).include?(options[:x].to_i) && (absolute_y..absolute_y + width).include?(options[:y].to_i) end
Get the cursor for this application. TODO: Delegate something like: def_delegate(:cursor) { application }
@return [Cursor]
# File lib/cura/component/base.rb, line 61 def cursor application.cursor end
Draw this component.
@return [Component]
# File lib/cura/component/base.rb, line 145 def draw return self unless @visible return self unless draw? draw_background draw_border self end
Focus on this component.
@return [Component]
# File lib/cura/component/base.rb, line 96 def focus application.dispatcher.target = self end
Check whether this component is focused.
@return [Boolean]
# File lib/cura/component/base.rb, line 103 def focused? application.dispatcher.target == self end
Get the foreground color of this object.
@return [Color]
# File lib/cura/component/base.rb, line 122 def foreground get_or_inherit_color(:foreground, Color.black) end
# File lib/cura/component/base.rb, line 174 def get_or_inherit_color(name, default) value = instance_variable_get("@#{name}") return value unless value == :inherit return default unless respond_to?(:parent) && parent.respond_to?(name) parent.send(name) end
Instance inspection.
@return [String]
# File lib/cura/component/base.rb, line 170 def inspect "#<#{self.class}:0x#{__id__.to_s(16)} x=#{x} y=#{y} absolute_x=#{absolute_x} absolute_y=#{absolute_y} w=#{width} h=#{height} parent=#{@parent.class}:0x#{@parent.__id__.to_s(16)}>" end
Get the pencil for this application. TODO: Delegate
@return [Pencil]
# File lib/cura/component/base.rb, line 69 def pencil application.pencil end
Update this component.
@return [Component]
# File lib/cura/component/base.rb, line 136 def update @draw = true self end
Get the window of this object.
@return [Application]
# File lib/cura/component/base.rb, line 85 def window return nil if parent.nil? return nil if parent.is_a?(Cura::Application) return parent if parent.is_a?(Cura::Window) parent.window end