Class: CTioga2::Graphics::Styles::TextLabel

Inherits:
FullTextStyle show all
Defined in:
lib/ctioga2/graphics/styles/texts.rb

Overview

A label.

Constant Summary

Constants inherited from BasicStyle

BasicStyle::AllStyles, BasicStyle::OldAttrAccessor

Instance Method Summary collapse

Methods inherited from BaseTextStyle

#draw_text, #hash_for_tioga, #scale_dy, #shift_dy, #vertical?

Methods inherited from BasicStyle

alias_for, attr_accessor, attribute_type, attribute_types, attributes, deprecated_attribute, from_hash, inherited, #instance_variable_defined?, options_hash, #set_from_hash, sub_style, sub_styles, #to_hash, typed_attribute, #update_from_other

Constructor Details

#initialize(text = nil, loc = nil) ⇒ TextLabel

Returns a new instance of TextLabel.



192
193
194
195
196
# File 'lib/ctioga2/graphics/styles/texts.rb', line 192

def initialize(text = nil, loc = nil)
  super()
  @text = text
  @loc = loc
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.



201
202
203
204
205
206
# File 'lib/ctioga2/graphics/styles/texts.rb', line 201

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, location = 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.



211
212
213
214
215
216
217
218
219
220
221
222
# File 'lib/ctioga2/graphics/styles/texts.rb', line 211

def label_extension(t, default = nil, location = nil)
  if @text
    dict = prepare_label_dict(t, default, nil)
    extra = 0
    if location
      extra = location.label_extra_space(t)
    end
    return (dict['shift'] + extra) * dict['scale']
  else
    return 0
  end
end