Class: Cura::Component::Base

Overview

The base class for all components.

All components use a box model similar to CSS. Margins, borders, paddings, then content.

Direct Known Subclasses

Group, Label

Instance Attribute Summary

Attributes included from Attributes::HasAncestry

#parent

Attributes included from Attributes::HasOffsets

#offsets

Attributes included from Attributes::HasEvents

#event_handler

Instance Method Summary collapse

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

#initialize

Instance Method Details

#applicationApplication

Get the application of this object.

Returns:



48
49
50
51
52
# File 'lib/cura/component/base.rb', line 48

def application
  return nil if parent.nil?
  
  parent.application
end

#backgroundColor

Get the background color of this object.

Returns:



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.

Parameters:

  • options (#to_h) (defaults to: {})

Options Hash (options):

  • :x (#to_i)
  • :y (#to_i)

Returns:

  • (Boolean)


74
75
76
77
78
# File 'lib/cura/component/base.rb', line 74

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

#cursorCursor

Get the cursor for this application. TODO: Delegate something like: def_delegate(:cursor) { application }

Returns:



33
34
35
# File 'lib/cura/component/base.rb', line 33

def cursor
  application.cursor
end

#drawComponent

Draw this component.

Returns:



111
112
113
114
115
116
# File 'lib/cura/component/base.rb', line 111

def draw
  draw_background
  draw_border
  
  self
end

#focusComponent

Focus on this component.

Returns:



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.

Returns:

  • (Boolean)


64
65
66
# File 'lib/cura/component/base.rb', line 64

def focused?
  application.dispatcher.target == self
end

#foregroundColor

Get the foreground color of this object.

Returns:



83
84
85
# File 'lib/cura/component/base.rb', line 83

def foreground
  get_or_inherit_color(:foreground, Color.black)
end

#inspectString

Instance inspection.

Returns:

  • (String)


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

#pencilPencil

Get the pencil for this application. TODO: Delegate

Returns:



41
42
43
# File 'lib/cura/component/base.rb', line 41

def pencil
  application.pencil
end

#updateComponent

Update this component.

Returns:



104
105
106
# File 'lib/cura/component/base.rb', line 104

def update
  self
end