Class: Glimmer::LibUI::ControlProxy::WindowProxy

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

Overview

Proxy for LibUI window objects

Follows the Proxy Design Pattern

Constant Summary collapse

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

Constants inherited from Glimmer::LibUI::ControlProxy

BOOLEAN_PROPERTIES, STRING_PROPERTIES, TransformProxy

Instance Attribute Summary

Attributes inherited from Glimmer::LibUI::ControlProxy

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

Instance Method Summary collapse

Methods inherited from Glimmer::LibUI::ControlProxy

#append_properties, #append_property, constant_symbol, #content, control_proxies, create, #custom_listener_aliases, #custom_listeners, #default_destroy, descendant_keyword_constant_map, #enabled, exists?, #handle_custom_listener, #has_custom_listener?, image_proxies, #initialize, keyword, #libui_api_keyword, main_window_proxy, map_descendant_keyword_constants_for, menu_proxies, #method_missing, new_control, #post_add_content, reset_descendant_keyword_constant_map, #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)


72
73
74
# File 'lib/glimmer/libui/control_proxy/window_proxy.rb', line 72

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

#destroyObject



46
47
48
49
50
# File 'lib/glimmer/libui/control_proxy/window_proxy.rb', line 46

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



41
42
43
44
# File 'lib/glimmer/libui/control_proxy/window_proxy.rb', line 41

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

#handle_listener(listener_name, &listener) ⇒ Object



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

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



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

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



37
38
39
# File 'lib/glimmer/libui/control_proxy/window_proxy.rb', line 37

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

#showObject



63
64
65
66
67
68
69
70
# File 'lib/glimmer/libui/control_proxy/window_proxy.rb', line 63

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