Class: Cura::Component::Button

Inherits:
Label show all
Defined in:
lib/cura/component/button.rb

Overview

A button component.

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 inherited from Label

#bold=, #bold?, #draw, #height, #horizontal_alignment, #horizontal_alignment=, #lines, #text, #text=, #text_height, #text_width, #underline?, #underlined=, #vertical_alignment, #vertical_alignment=, #width

Methods included from Attributes::HasAttributes

included, #update_attributes

Methods inherited from Base

#application, #contains_coordinates?, #cursor, #draw, #focus, #focused?, #foreground, #inspect, #pencil, #update

Methods included from Attributes::HasRelativeCoordinates

#absolute_x, #absolute_y

Methods included from Attributes::HasCoordinates

#x, #x=, #y, #y=

Methods included from Attributes::HasAncestry

#ancestors, #parent?

Methods included from Attributes::HasOffsets

#border, #border=, #margin, #margin=, #padding, #padding=

Methods included from Attributes::HasColors

#background=, #foreground, #foreground=

Methods included from Attributes::HasFocusability

#focusable=, #focusable?

Methods included from Attributes::HasEvents

included, #on_event

Methods included from Attributes::HasDimensions

#height, #height=, #resize, #width, #width=

Constructor Details

#initialize(attributes = {}) ⇒ Button

Returns a new instance of Button.



32
33
34
35
36
37
38
39
# File 'lib/cura/component/button.rb', line 32

def initialize(attributes={})
  @focusable = true
  @foreground = Cura::Color.black
  @background = Cura::Color.white
  @focused_background = Color.new(78, 78, 78)
  
  super
end

Instance Method Details

#backgroundObject



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

def background
  focused? ? @focused_background : get_or_inherit_color(:background, Color.black)
end

#clickButton

Click this button.

Returns:



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

def click
  application.dispatch_event(:click, target: self)
  
  self
end

#focused_backgroundColor

Get the focused background color of this object.

Returns:



# File 'lib/cura/component/button.rb', line 19

#focused_background=(value) ⇒ Color

Set the focused background color of this object.

Parameters:

Returns:



30
# File 'lib/cura/component/button.rb', line 30

attribute(:focused_background) { |value| validate_color_attribute(value) }