Class: TkWrapper::Util::Tk::Font

Inherits:
Object
  • Object
show all
Defined in:
lib/util/tk/font.rb

Instance Method Summary collapse

Constructor Details

#initialize(tk_widget) ⇒ Font

Returns a new instance of Font.



9
10
11
# File 'lib/util/tk/font.rb', line 9

def initialize(tk_widget)
  @tk_widget = tk_widget
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/util/tk/font.rb', line 32

def method_missing(method, *args)
  if TkFont.respond_to?(method)
    TkFont.send(method, @tk_widget.font, *args)
  else
    super
  end
end

Instance Method Details

#char_widthObject



52
53
54
# File 'lib/util/tk/font.rb', line 52

def char_width
  measure('0')
end

#linespaceObject



56
57
58
# File 'lib/util/tk/font.rb', line 56

def linespace
  metrics['linespace']
end

#loadObject



44
45
46
# File 'lib/util/tk/font.rb', line 44

def load
  @config = TkFont.actual(@tk_widget.font).to_h.transform_keys(&:to_sym)
end

#metricsObject



60
61
62
63
64
# File 'lib/util/tk/font.rb', line 60

def metrics
  @tk_widget.font.metrics.each_with_object({}) do |(key, value), metrics|
    metrics[key] = value
  end
end

#respond_to_missing?(method) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/util/tk/font.rb', line 40

def respond_to_missing?(method, *)
  TkFont.respond_to?(method) || super
end

#updateObject



48
49
50
# File 'lib/util/tk/font.rb', line 48

def update
  @tk_widget.font = TkFont.new(@config)
end

#with_update(&block) ⇒ Object



27
28
29
30
# File 'lib/util/tk/font.rb', line 27

def with_update(&block)
  block.call(self)
  update
end