Class: Cura::Component::Base
- Inherits:
-
Object
- Object
- Cura::Component::Base
- Includes:
- Attributes::HasAttributes, Attributes::HasColors, Attributes::HasDimensions, Attributes::HasEvents, Attributes::HasFocusability, Attributes::HasInitialize, Attributes::HasOffsets, Attributes::HasRelativeCoordinates
- 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
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::HasRelativeCoordinates
#absolute_x, #absolute_y, #initialize
Methods included from Attributes::HasCoordinates
#initialize, #x, #x=, #y, #y=
Methods included from Attributes::HasAttributes
included, #initialize, #update_attributes
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
Instance Method Details
#application ⇒ Application
Get the application of this object.
48 49 50 51 52 |
# File 'lib/cura/component/base.rb', line 48 def application return nil if parent.nil? parent.application end |
#background ⇒ Color
Get the background color of this object.
90 91 92 |
# File 'lib/cura/component/base.rb', line 90 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.
74 75 76 77 78 |
# File 'lib/cura/component/base.rb', line 74 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 }
33 34 35 |
# File 'lib/cura/component/base.rb', line 33 def cursor application.cursor end |
#draw ⇒ Component
Draw this component.
111 112 113 114 115 116 |
# File 'lib/cura/component/base.rb', line 111 def draw draw_background draw_border self end |
#focus ⇒ Component
Focus on this component.
57 58 59 |
# File 'lib/cura/component/base.rb', line 57 def focus application.dispatcher.target = self end |
#focused? ⇒ Boolean
Check whether this component is focused.
64 65 66 |
# File 'lib/cura/component/base.rb', line 64 def focused? application.dispatcher.target == self end |
#foreground ⇒ Color
Get the foreground color of this object.
83 84 85 |
# File 'lib/cura/component/base.rb', line 83 def foreground get_or_inherit_color(:foreground, Color.black) end |
#inspect ⇒ String
Instance inspection.
97 98 99 |
# File 'lib/cura/component/base.rb', line 97 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
41 42 43 |
# File 'lib/cura/component/base.rb', line 41 def pencil application.pencil end |
#update ⇒ Component
Update this component.
104 105 106 |
# File 'lib/cura/component/base.rb', line 104 def update self end |