Class: Cura::Component::Base
- Inherits:
-
Object
- Object
- Cura::Component::Base
- Includes:
- Attributes::HasAncestry, Attributes::HasAttributes, Attributes::HasColors, Attributes::HasDimensions, Attributes::HasEvents, Attributes::HasFocusability, Attributes::HasInitialize, Attributes::HasOffsets, Attributes::HasRelativeCoordinates, Attributes::HasVisibility
- Defined in:
- lib/cura/component/base.rb
Overview
The base class for all components.
All components use a box model similar to CSS. Margins, borders, paddings, then content.
Instance Attribute Summary
Attributes included from Attributes::HasAncestry
Attributes included from Attributes::HasOffsets
Attributes included from Attributes::HasEvents
Class Method Summary collapse
-
.inherited(subclass) ⇒ Object
On subclass hook.
-
.type ⇒ Symbol
The type of this component class.
Instance Method Summary collapse
-
#application ⇒ Application
Get the application of this object.
-
#background ⇒ Color
Get the background color of this object.
-
#contains_coordinates?(options = {}) ⇒ Boolean
Determine if the given absolute coordinates are within the bounds of this component.
-
#cursor ⇒ Cursor
Get the cursor for this application.
-
#draw ⇒ Component
Draw this component.
-
#focus ⇒ Component
Focus on this component.
-
#focused? ⇒ Boolean
Check whether this component is focused.
-
#foreground ⇒ Color
Get the foreground color of this object.
-
#inspect ⇒ String
Instance inspection.
-
#pencil ⇒ Pencil
Get the pencil for this application.
-
#update ⇒ Component
Update this component.
Methods included from Attributes::HasVisibility
#initialize, #visible=, #visible?
Methods included from Attributes::HasAttributes
included, #initialize, #update_attributes
Methods included from Attributes::HasRelativeCoordinates
#absolute_x, #absolute_y, #initialize
Methods included from Attributes::HasCoordinates
#initialize, #x, #x=, #y, #y=
Methods included from Attributes::HasAncestry
#ancestors, #initialize, #parent?
Methods included from Attributes::HasOffsets
#border, #border=, #initialize, #margin, #margin=, #padding, #padding=
Methods included from Attributes::HasColors
#background=, #foreground=, #initialize
Methods included from Attributes::HasFocusability
#focusable=, #focusable?, #initialize
Methods included from Attributes::HasEvents
included, #initialize, #on_event
Methods included from Attributes::HasDimensions
#height, #height=, #initialize, #resize, #width, #width=
Methods included from Attributes::HasInitialize
Class Method Details
.inherited(subclass) ⇒ Object
On subclass hook.
22 23 24 |
# File 'lib/cura/component/base.rb', line 22 def inherited(subclass) Component.all << subclass end |
.type ⇒ Symbol
The type of this component class.
31 32 33 34 35 |
# File 'lib/cura/component/base.rb', line 31 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 |
Instance Method Details
#application ⇒ Application
Get the application of this object.
69 70 71 72 73 |
# File 'lib/cura/component/base.rb', line 69 def application return nil if parent.nil? parent.application end |
#background ⇒ Color
Get the background color of this object.
111 112 113 |
# File 'lib/cura/component/base.rb', line 111 def background get_or_inherit_color(:background, Color.white) end |
#contains_coordinates?(options = {}) ⇒ Boolean
Determine if the given absolute coordinates are within the bounds of this component.
95 96 97 98 99 |
# File 'lib/cura/component/base.rb', line 95 def contains_coordinates?(={}) = .to_h (absolute_x..absolute_x + width).include?([:x].to_i) && (absolute_y..absolute_y + width).include?([:y].to_i) end |
#cursor ⇒ Cursor
Get the cursor for this application. TODO: Delegate something like: def_delegate(:cursor) { application }
54 55 56 |
# File 'lib/cura/component/base.rb', line 54 def cursor application.cursor end |
#draw ⇒ Component
Draw this component.
125 126 127 128 129 130 131 132 |
# File 'lib/cura/component/base.rb', line 125 def draw if @visible draw_background draw_border end self end |
#focus ⇒ Component
Focus on this component.
78 79 80 |
# File 'lib/cura/component/base.rb', line 78 def focus application.dispatcher.target = self end |
#focused? ⇒ Boolean
Check whether this component is focused.
85 86 87 |
# File 'lib/cura/component/base.rb', line 85 def focused? application.dispatcher.target == self end |
#foreground ⇒ Color
Get the foreground color of this object.
104 105 106 |
# File 'lib/cura/component/base.rb', line 104 def foreground get_or_inherit_color(:foreground, Color.black) end |
#inspect ⇒ String
Instance inspection.
137 138 139 |
# File 'lib/cura/component/base.rb', line 137 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 |
#pencil ⇒ Pencil
Get the pencil for this application. TODO: Delegate
62 63 64 |
# File 'lib/cura/component/base.rb', line 62 def pencil application.pencil end |
#update ⇒ Component
Update this component.
118 119 120 |
# File 'lib/cura/component/base.rb', line 118 def update self end |