Class: Metro::UI::Label
Overview
The label will draw the specified text with the font, position, color, and alignment provided.
Constant Summary
Constants included from Metro::Units
Instance Attribute Summary collapse
-
#align ⇒ Object
The alignment for the label.
-
#color ⇒ Object
The text color.
-
#dimensions ⇒ Object
The dimensions of label.
-
#font ⇒ Object
The font to use for the label text.
-
#minimum_dimensions ⇒ Object
When calculating the dimensions of the label, this is the minimum dimensions.
-
#position ⇒ Object
The position of the label.
-
#scale ⇒ Object
The scale of the text.
-
#text ⇒ Object
The text to appear on the label.
-
#vertical_align ⇒ Object
The vertical alignment for the label.
Attributes inherited from Model
Instance Method Summary collapse
Methods inherited from Model
#_load, #_save, #after_initialize, #completed?, #create, hierarchy, inherited, #initialize, metro_name, #model, model_name, models, #name, #notification, #saveable_to_view, #show, #to_hash, #update
Methods included from HasEvents
Methods included from KeyValueCoding
Methods included from PropertyOwner
Constructor Details
This class inherits a constructor from Metro::Model
Instance Attribute Details
#align ⇒ Object
The alignment for the label. This influences where the text draws in relation to the specified position. Your choices are ‘left’, ‘center’, and ‘right’. The default is ‘left’.
42 |
# File 'lib/metro/models/ui/label.rb', line 42 property :align, type: :text, default: "left" |
#color ⇒ Object
The text color
28 |
# File 'lib/metro/models/ui/label.rb', line 28 property :color, default: "rgba(255,255,255,1.0)" |
#dimensions ⇒ Object
The dimensions of label. If the label text is blank, then the dimensions of the label will return a minimum dimension.
59 60 61 62 |
# File 'lib/metro/models/ui/label.rb', line 59 property :dimensions do calculated = Dimensions.of (longest_line * x_factor), (line_height * line_count * y_factor) [ calculated, minimum_dimensions ].max end |
#font ⇒ Object
The font to use for the label text
32 |
# File 'lib/metro/models/ui/label.rb', line 32 property :font, default: { size: 20 } |
#minimum_dimensions ⇒ Object
When calculating the dimensions of the label, this is the minimum dimensions. This is necessary in cases when the text is blank. This allows for the label to have size when in the edit mode.
54 |
# File 'lib/metro/models/ui/label.rb', line 54 property :minimum_dimensions, type: :dimensions, default: "16,16" |
#position ⇒ Object
The position of the label
20 |
# File 'lib/metro/models/ui/label.rb', line 20 property :position |
#scale ⇒ Object
The scale of the text
24 |
# File 'lib/metro/models/ui/label.rb', line 24 property :scale, default: Scale.one |
#text ⇒ Object
The text to appear on the label
36 |
# File 'lib/metro/models/ui/label.rb', line 36 property :text |
#vertical_align ⇒ Object
The vertical alignment for the label. This influences where the text draws in relation to the specified position. Your choices are ‘top’, ‘center’, and ‘bottom’. This default is ‘top’
48 |
# File 'lib/metro/models/ui/label.rb', line 48 property :vertical_align, type: :text, default: "top" |
Instance Method Details
#bounds ⇒ Object
64 65 66 |
# File 'lib/metro/models/ui/label.rb', line 64 def bounds Bounds.new left: left_x, right: right_x, top: top_y, bottom: bottom_y end |
#draw ⇒ Object
68 69 70 71 72 |
# File 'lib/metro/models/ui/label.rb', line 68 def draw parsed_text.each_with_index do |line,index| font.draw line, x_position(index), y_position(index), z_order, x_factor, y_factor, color end end |