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, KEYWORD_ALIASES, 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

#content_size(*args) ⇒ Object Also known as: content_size=, set_content_size



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/glimmer/libui/control_proxy/window_proxy.rb', line 98

def content_size(*args)
  if args.empty?
    width = Fiddle::Pointer.malloc(8)
    height = Fiddle::Pointer.malloc(8)
    ::LibUI.window_content_size(@libui, width, height)
    width = width[0, 8].unpack1('i')
    height = height[0, 8].unpack1('i')
    [width, height]
  else
    args = args.first if args.size == 1 && args.first.is_a?(Array)
    super
    @width = args[0]
    @height = args[1]
  end
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
96
# 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
    default_behavior_listener = nil
    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 || 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

#resizable(value = nil) ⇒ Object Also known as: resizable?, resizable=, set_resizable



116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/glimmer/libui/control_proxy/window_proxy.rb', line 116

def resizable(value = nil)
  if value.nil?
    @resizable = true if @resizable.nil?
    @resizable
  else
    @resizable = value
    if !@resizable && !@resizable_listener_registered
      handle_listener('on_content_size_changed') do
        set_content_size(@width, @height) unless @resizable
      end
      @resizable_listener_registered = true
    end
  end
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