Method: MiniGL::Label#initialize

Defined in:
lib/minigl/forms.rb

#initialize(x, y = nil, font = nil, text = nil, text_color = 0, disabled_text_color = 0, scale_x = 1, scale_y = 1, anchor = nil) ⇒ Label

Creates a new label.

Parameters:

x

The x-coordinate of the label.

y

The x-coordinate of the label.

font

Font that will be used to draw the label’s text.

text

The label’s text.

text_color

The default text color.

disabled_text_color

The text color when the label is disabled.

scale_x

The horizontal scale factor.

scale_y

The vertical scale factor.

anchor

See parameter with the same name in Panel#initialize for details.



1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
# File 'lib/minigl/forms.rb', line 1444

def initialize(x, y = nil, font = nil, text = nil, text_color = 0, disabled_text_color = 0, scale_x = 1, scale_y = 1, anchor = nil)
  if x.is_a? Hash
    y = x[:y]
    font = x[:font]
    text = x[:text]
    text_color = x.fetch(:text_color, 0)
    disabled_text_color = x.fetch(:disabled_text_color, 0)
    scale_x = x.fetch(:scale_x, 1)
    scale_y = x.fetch(:scale_y, 1)
    anchor = x.fetch(:anchor, nil)
    x = x[:x]
  end

  @scale_x = scale_x
  @scale_y = scale_y
  @w = font.text_width(text) * scale_x
  @h = font.height * scale_y
  @anchor_offset_x = x; @anchor_offset_y = y
  @anchor, x, y = FormUtils.check_anchor(anchor, x, y, @w, @h)
  super(x, y, font, text, text_color, disabled_text_color)
end