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::OldAttrAccessor

Instance Method Summary collapse

Methods inherited from BaseTextStyle

#draw_text

Methods inherited from BasicStyle

attr_accessor, attributes, from_hash, #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.



116
117
118
119
120
# File 'lib/ctioga2/graphics/styles/texts.rb', line 116

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.



125
126
127
128
129
130
# File 'lib/ctioga2/graphics/styles/texts.rb', line 125

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.



135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/ctioga2/graphics/styles/texts.rb', line 135

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