Class: Cura::Component::Label
- Includes:
- Attributes::HasAttributes
- Defined in:
- lib/cura/component/label.rb
Overview
A component displaying text.
Instance Attribute Summary
Attributes included from Attributes::HasAncestry
Attributes included from Attributes::HasOffsets
Attributes included from Attributes::HasEvents
Instance Method Summary collapse
-
#bold=(value) ⇒ Boolean
Set whether the text is bold.
-
#bold? ⇒ Boolean
Get whether the text is bold.
- #draw ⇒ Object
-
#height ⇒ Integer
Get the height of this label.
-
#horizontal_alignment ⇒ Symbol
Get the horizontal alignment of this label.
-
#horizontal_alignment=(value) ⇒ Symbol
Set the horizontal alignment of this label.
-
#initialize(attributes = {}) ⇒ Label
constructor
Note that you can pass the following: alignment: { horizontal: true, vertical: true } instead of: horizontal_alignment: true, vertical_alignment: true.
-
#lines ⇒ <String>
Get the lines of this label.
-
#text ⇒ String
Get the text of this label.
-
#text=(value) ⇒ String
Set the text of this label.
-
#text_height ⇒ Integer
Get the height of the text of this label.
-
#text_width ⇒ Integer
Get the width of the text of this label.
-
#underline? ⇒ Boolean
Get whether the text is underlined.
-
#underlined=(value) ⇒ Boolean
Set whether the text is underlined.
-
#vertical_alignment ⇒ Symbol
Get the vertical alignment of this label.
-
#vertical_alignment=(value) ⇒ Symbol
Set the vertical alignment of this label.
-
#width ⇒ Integer
Get the width of this label.
Methods included from Attributes::HasAttributes
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
Methods included from Attributes::HasRelativeCoordinates
Methods included from Attributes::HasCoordinates
Methods included from Attributes::HasAncestry
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
Methods included from Attributes::HasEvents
Methods included from Attributes::HasDimensions
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.
92 |
# File 'lib/cura/component/label.rb', line 92 attribute(:bold, query: true) |
#bold? ⇒ Boolean
Get whether the text is bold.
|
# File 'lib/cura/component/label.rb', line 83
|
#draw ⇒ Object
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 |
#height ⇒ Integer
Get the height of this label.
40 41 42 43 44 |
# File 'lib/cura/component/label.rb', line 40 def height return text_height if @height == :auto @height end |
#horizontal_alignment ⇒ Symbol
Get the horizontal alignment of this label.
|
# 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.
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.
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 |
#text ⇒ String
Get the text of this label.
|
# File 'lib/cura/component/label.rb', line 46
|
#text=(value) ⇒ String
Set the text of this label.
56 |
# File 'lib/cura/component/label.rb', line 56 attribute(:text) { |value| value.to_s } |
#text_height ⇒ Integer
Get the height of the text of this label.
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_width ⇒ Integer
Get the width of the text of this label.
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.
|
# File 'lib/cura/component/label.rb', line 94
|
#underlined=(value) ⇒ Boolean
Set whether the text is underlined.
103 |
# File 'lib/cura/component/label.rb', line 103 attribute(:underline, query: true) |
#vertical_alignment ⇒ Symbol
Get the vertical alignment of this label. Will be :left, :center, or :right.
|
# 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.
130 |
# File 'lib/cura/component/label.rb', line 130 attribute(:vertical_alignment) { |value| convert_vertical_alignment_attribute(value) } |
#width ⇒ Integer
Get the width of this label.
31 32 33 34 35 |
# File 'lib/cura/component/label.rb', line 31 def width return text_width if @width == :auto @width end |