Class: Glimmer::LibUI::WindowProxy

Inherits:
ControlProxy show all
Defined in:
lib/glimmer/libui/window_proxy.rb

Overview

Proxy for LibUI window objects

Follows the Proxy Design Pattern

Constant Summary collapse

DEFAULT_TITLE =
''
DEFAULT_WIDTH =
150
DEFAULT_HEIGHT =
150
DEFAULT_HAS_MENUBAR =
1

Constants inherited from ControlProxy

ControlProxy::BOOLEAN_PROPERTIES, ControlProxy::STRING_PROPERTIES

Instance Attribute Summary

Attributes inherited from ControlProxy

#args, #block, #keyword, #libui, #parent_proxy

Instance Method Summary collapse

Methods inherited from ControlProxy

#append_properties, #append_property, boolean_to_integer, #content, control_proxies, create, #default_destroy, #enabled, exists?, image_proxies, #initialize, integer_to_boolean, #libui_api_keyword, main_window_proxy, menu_proxies, #method_missing, new_control, #post_add_content, #respond_to?, #respond_to_libui?, #send_to_libui, #visible, widget_proxy_class, #window_proxy

Constructor Details

This class inherits a constructor from Glimmer::LibUI::ControlProxy

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Glimmer::LibUI::ControlProxy

Instance Method Details

#can_handle_listener?(listener_name) ⇒ Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/glimmer/libui/window_proxy.rb', line 70

def can_handle_listener?(listener_name)
  listener_name == 'on_destroy' || super
end

#destroyObject



44
45
46
47
48
# File 'lib/glimmer/libui/window_proxy.rb', line 44

def destroy
  super
  ControlProxy.image_proxies.each { |image_proxy| ::LibUI.free_image(image_proxy.libui) }
  @on_destroy_procs&.each { |on_destroy_proc| on_destroy_proc.call(self)}
end

#destroy_child(child) ⇒ Object



39
40
41
42
# File 'lib/glimmer/libui/window_proxy.rb', line 39

def destroy_child(child)
  ::LibUI.send("window_set_child", @libui, nil)
  super
end

#handle_listener(listener_name, &listener) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/glimmer/libui/window_proxy.rb', line 74

def handle_listener(listener_name, &listener)
  case listener_name
  when 'on_destroy'
    on_destroy(&listener)
  else
    if listener_name == 'on_closing'
      default_behavior_listener = Proc.new do
        return_value = listener.call(self)
        if return_value.is_a?(Numeric)
          return_value
        else
          destroy
          ::LibUI.quit
          0
        end
      end
    end
    super(listener_name, &default_behavior_listener)
  end
end

#on_destroy(&block) ⇒ Object



50
51
52
53
54
55
56
57
58
59
# File 'lib/glimmer/libui/window_proxy.rb', line 50

def on_destroy(&block)
  # TODO look into a way to generalize this logic for multiple listeners
  @on_destroy_procs ||= []
  if block.nil?
    @on_destroy_procs
  else
    @on_destroy_procs << block
    block
  end
end

#post_initialize_child(child) ⇒ Object



35
36
37
# File 'lib/glimmer/libui/window_proxy.rb', line 35

def post_initialize_child(child)
  ::LibUI.window_set_child(@libui, child.libui)
end

#showObject



61
62
63
64
65
66
67
68
# File 'lib/glimmer/libui/window_proxy.rb', line 61

def show
  super
  unless @shown_at_least_once
    @shown_at_least_once = true
    ::LibUI.main
    ::LibUI.quit
  end
end