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, aliases, attr_accessor, attribute_type, attribute_types, attributes, convert_string_hash, defined_aliases, deprecated_attribute, from_hash, inherited, #instance_variable_defined?, normalize_hash, normalize_in, normalize_out, options_hash, #set_from_hash, sub_style, sub_styles, #to_hash, typed_attribute, #update_from_other, #use_defaults_from

Constructor Details

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

Returns a new instance of TextLabel.



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

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.



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

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.



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

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