Class: CTioga2::Graphics::Styles::TextLabel
- Inherits:
-
FullTextStyle
- Object
- BasicStyle
- BaseTextStyle
- FullTextStyle
- CTioga2::Graphics::Styles::TextLabel
- Defined in:
- lib/ctioga2/graphics/styles/texts.rb
Overview
A label.
Constant Summary
Constants inherited from BasicStyle
Instance Attribute Summary collapse
-
#loc ⇒ Object
The location of the label.
-
#text ⇒ Object
The text of the label.
Attributes inherited from FullTextStyle
Attributes inherited from BaseTextStyle
#alignement, #angle, #justification, #scale, #shift
Instance Method Summary collapse
-
#draw(t, default = nil, measure = nil) ⇒ Object
Draw the label, if #text is not nil or false.
-
#initialize(text = nil) ⇒ TextLabel
constructor
A new instance of TextLabel.
-
#label_extension(t, default = nil, side = nil) ⇒ Object
Gets the extension of the label, in units of text height.
Methods inherited from BaseTextStyle
Methods inherited from BasicStyle
attr_accessor, attributes, from_hash, #instance_variable_defined?, #set_from_hash, #to_hash, #update_from_other
Constructor Details
#initialize(text = nil) ⇒ TextLabel
Returns a new instance of TextLabel.
132 133 134 |
# File 'lib/ctioga2/graphics/styles/texts.rb', line 132 def initialize(text = nil) @text = text end |
Instance Attribute Details
#loc ⇒ Object
The location of the label.
130 131 132 |
# File 'lib/ctioga2/graphics/styles/texts.rb', line 130 def loc @loc end |
#text ⇒ Object
The text of the label. nil or false means there will be no text displayed
127 128 129 |
# File 'lib/ctioga2/graphics/styles/texts.rb', line 127 def text @text end |
Instance Method Details
#draw(t, default = nil, measure = nil) ⇒ Object
Draw the label, if #text is not nil or false. Attributes such as scale, shift and angle are taken from the corresponding default if default isn’t nil.
139 140 141 142 143 144 |
# File 'lib/ctioga2/graphics/styles/texts.rb', line 139 def draw(t, default = nil, measure = nil) if @text dict = prepare_label_dict(t, default, measure) t.show_text(dict) end end |
#label_extension(t, default = nil, side = nil) ⇒ Object
Gets the extension of the label, in units of text height. Default values for the various parameters are taken from the default parameter if they are not specified.
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/ctioga2/graphics/styles/texts.rb', line 149 def label_extension(t, default = nil, side = nil) if @text dict = prepare_label_dict(t, default, nil) case side when :bottom, :right extra = 0.5 # To account for baseline ? when :top, :left extra = 1 else # We take the safe side ! extra = 1 end return (dict['shift'] + extra) * dict['scale'] else return 0 end end |