Class: Cura::Component::Label

Inherits:
Base
  • Object
show all
Includes:
Attributes::HasAttributes
Defined in:
lib/cura/component/label.rb

Overview

A component displaying text.

Direct Known Subclasses

Button, Textbox

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::HasAttributes

included, #update_attributes

Methods inherited from Base

#application, #background, #contains_coordinates?, #cursor, #draw=, #draw?, #focus, #focused?, #foreground, #get_or_inherit_color, inherited, #inspect, #pencil, type, #update, #window

Methods included from Attributes::HasVisibility

#visible=, #visible?

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, #background=, #foreground, #foreground=

Methods included from Attributes::HasFocusability

#focusable=, #focusable?

Methods included from Attributes::HasEvents

included, #on_event

Methods included from Attributes::HasDimensions

#height=, #resize, #width=

Constructor Details

#initialize(attributes = {}) ⇒ Label

Note that you can pass the following:

alignment: { horizontal: true, vertical: true }

instead of:

horizontal_alignment: true, vertical_alignment: true


16
17
18
19
20
21
22
23
24
# File 'lib/cura/component/label.rb', line 16

def initialize(attributes={})
  @horizontal_alignment = :left
  @vertical_alignment = :top
  @bold = false
  @underline = false
  @text = ""

  super
end

Instance Method Details

#bold=(value) ⇒ Boolean

Set whether the text is bold.

Returns:

  • (Boolean)


92
# File 'lib/cura/component/label.rb', line 92

attribute(:bold, query: true)

#bold?Boolean

Get whether the text is bold.

Returns:

  • (Boolean)


# File 'lib/cura/component/label.rb', line 83

#drawObject



132
133
134
135
136
137
# File 'lib/cura/component/label.rb', line 132

def draw
  super
  return self unless @draw

  draw_text unless text.empty?
end

#heightInteger

Get the height of this label.

Returns:

  • (Integer)


40
41
42
43
44
# File 'lib/cura/component/label.rb', line 40

def height
  return text_height if @height == :auto

  @height
end

#horizontal_alignmentSymbol

Get the horizontal alignment of this label.

Returns:

  • (Symbol)


# File 'lib/cura/component/label.rb', line 105

#horizontal_alignment=(value) ⇒ Symbol

Set the horizontal alignment of this label. Must be :left, :center, or :right.

Parameters:

  • value (#to_sym)

Returns:

  • (Symbol)


116
# File 'lib/cura/component/label.rb', line 116

attribute(:horizontal_alignment) { |value| convert_horizontal_alignment_attribute(value) }

#lines<String>

Get the lines of this label.

Returns:

  • (<String>)


61
62
63
# File 'lib/cura/component/label.rb', line 61

def lines
  @text.split("\n") # NOTE: Would use String#lines but it's output doesn't think a trailing newline character constitutes a line unless it is followed by another character. #split also removes the newline characters.
end

#textString

Get the text of this label.

Returns:

  • (String)


# File 'lib/cura/component/label.rb', line 46

#text=(value) ⇒ String

Set the text of this label.

Parameters:

  • value (#to_s)

Returns:

  • (String)


56
# File 'lib/cura/component/label.rb', line 56

attribute(:text) { |value| value.to_s }

#text_heightInteger

Get the height of the text of this label.

Returns:

  • (Integer)


77
78
79
80
81
# File 'lib/cura/component/label.rb', line 77

def text_height
  value = lines.length

  value == 0 ? 1 : value
end

#text_widthInteger

Get the width of the text of this label.

Returns:

  • (Integer)


68
69
70
71
72
# File 'lib/cura/component/label.rb', line 68

def text_width
  return 0 if @text.empty?

  lines.collect(&:length).sort.last
end

#underline?Boolean

Get whether the text is underlined.

Returns:

  • (Boolean)


# File 'lib/cura/component/label.rb', line 94

#underlined=(value) ⇒ Boolean

Set whether the text is underlined.

Returns:

  • (Boolean)


103
# File 'lib/cura/component/label.rb', line 103

attribute(:underline, query: true)

#vertical_alignmentSymbol

Get the vertical alignment of this label. Will be :left, :center, or :right.

Returns:

  • (Symbol)


# File 'lib/cura/component/label.rb', line 118

#vertical_alignment=(value) ⇒ Symbol

Set the vertical alignment of this label. Must be :left, :center, or :right.

Parameters:

  • value (#to_sym)

Returns:

  • (Symbol)


130
# File 'lib/cura/component/label.rb', line 130

attribute(:vertical_alignment) { |value| convert_vertical_alignment_attribute(value) }

#widthInteger

Get the width of this label.

Returns:

  • (Integer)


31
32
33
34
35
# File 'lib/cura/component/label.rb', line 31

def width
  return text_width if @width == :auto

  @width
end