Class: Glimmer::SWT::GFont

Inherits:
Object
  • Object
show all
Extended by:
Glimmer
Defined in:
lib/glimmer/swt/g_font.rb

Constant Summary collapse

ERROR_INVALID_FONT_STYLE =
" is an invalid font style! Valid values are :normal, :bold, and :italic"
FONT_STYLES =
[:normal, :bold, :italic]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Glimmer

add_contents, add_contents, dsl, dsl, extended, included, logger, method_missing, method_missing

Methods included from Glimmer::SwtPackages

included

Constructor Details

#initialize(g_widget, display = nil) ⇒ GFont

Returns a new instance of GFont.



30
31
32
33
# File 'lib/glimmer/swt/g_font.rb', line 30

def initialize(g_widget, display = nil)
  @g_widget = g_widget
  @display = display || @g_widget.widget.display
end

Instance Attribute Details

#displayObject

Returns the value of attribute display.



13
14
15
# File 'lib/glimmer/swt/g_font.rb', line 13

def display
  @display
end

#g_widgetObject

Returns the value of attribute g_widget.



12
13
14
# File 'lib/glimmer/swt/g_font.rb', line 12

def g_widget
  @g_widget
end

Class Method Details

.for(g_widget) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/glimmer/swt/g_font.rb', line 16

def for(g_widget)
  @instances ||= {}
  unless @instances[g_widget]
    @instances[g_widget] = new(g_widget)
    add_contents(g_widget) {
      on_widget_disposed { |dispose_event|
        @instances.delete(g_widget)
      }
    }
  end
  @instances[g_widget]
end

Instance Method Details

#detect_invalid_font_property(font_properties) ⇒ Object



66
67
68
69
70
71
72
# File 'lib/glimmer/swt/g_font.rb', line 66

def detect_invalid_font_property(font_properties)
  [font_properties[:style]].flatten.select do |style|
    style.is_a?(Symbol) || style.is_a?(String)
  end.each do |style|
    raise style.to_s + ERROR_INVALID_FONT_STYLE if !FONT_STYLES.include?(style.to_sym)
  end
end

#font(font_properties) ⇒ Object



56
57
58
59
60
61
62
63
64
# File 'lib/glimmer/swt/g_font.rb', line 56

def font(font_properties)
  detect_invalid_font_property(font_properties)
  font_properties[:style] = GSWT[*font_properties[:style]]
  font_data_args = [:name, :height, :style].map do |font_property_name|
    font_properties[font_property_name] || send(font_property_name)
  end
  font_datum = FontData.new(*font_data_args)
  Font.new(@display, font_datum)
end

#font_datumObject



40
41
42
# File 'lib/glimmer/swt/g_font.rb', line 40

def font_datum
  @font_datum ||= @g_widget.widget.getFont.getFontData[0]
end

#heightObject



48
49
50
# File 'lib/glimmer/swt/g_font.rb', line 48

def height
  font_datum.getHeight
end

#nameObject



44
45
46
# File 'lib/glimmer/swt/g_font.rb', line 44

def name
  font_datum.getName
end

#styleObject



52
53
54
# File 'lib/glimmer/swt/g_font.rb', line 52

def style
  font_datum.getStyle
end