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

CUSTOM_LISTENER_NAMES =
['on_destroy']
CUSTOM_LISTENER_NAME_ALIASES =
{
  on_destroyed: 'on_destroy',
}
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, #content_added, #keyword, #libui, #parent_proxy

Instance Method Summary collapse

Methods inherited from Glimmer::LibUI::ControlProxy

#append_properties, #append_property, #can_handle_listener?, constant_symbol, #content, control_proxies, create, #custom_listener_name_aliases, #custom_listener_names, #default_destroy, #deregister_all_custom_listeners, #deregister_custom_listeners, descendant_keyword_constant_map, #enabled, exists?, #handle_custom_listener, #has_custom_listener?, image_proxies, #initialize, keyword, #libui_api_keyword, #listeners, #listeners_for, main_window_proxy, map_descendant_keyword_constants_for, menu_proxies, #method_missing, new_control, #notify_custom_listeners, #post_add_content, reset_descendant_keyword_constant_map, #respond_to?, #respond_to_libui?, #send_to_libui, #visible, widget_proxy_class, #window_proxy

Methods included from DataBindable

#data_bind, #data_bind_read, #data_bind_write, #data_binding_model_attribute_observer_registrations

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

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



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

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



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

def destroy
  return if @destroying
  @destroying = true
  @on_closing_listeners&.clear
  super
  ControlProxy.image_proxies.each { |image_proxy| ::LibUI.free_image(image_proxy.libui) unless image_proxy.area_image? }
  notify_custom_listeners('on_destroy', self)
  deregister_custom_listeners('on_destroy')
  @destroying = false
end

#destroy_child(child) ⇒ Object



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

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

#destroying?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/glimmer/libui/control_proxy/window_proxy.rb', line 61

def destroying?
  @destroying
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
94
95
96
97
98
# File 'lib/glimmer/libui/control_proxy/window_proxy.rb', line 74

def handle_listener(listener_name, &listener)
  case listener_name
  when 'on_closing'
    @on_closing_listeners ||= []
    @on_closing_listeners << listener
    @default_behavior_listener ||= Proc.new do
      return_value = nil
      @on_closing_listeners.each do |l|
        return_value = l.call(self)
        break if return_value.is_a?(Numeric)
      end
      if return_value.is_a?(Numeric)
        return_value
      else
        destroy
        ::LibUI.quit
        0
      end
    end.tap do |default_behavior_listener|
      super(listener_name, &default_behavior_listener)
    end
  else
    super
  end
end

#height(value = nil) ⇒ Object Also known as: height=, set_height



128
129
130
131
132
133
134
# File 'lib/glimmer/libui/control_proxy/window_proxy.rb', line 128

def height(value = nil)
  if value.nil?
    content_size.last
  else
    set_content_size(width, value)
  end
end

#post_initialize_child(child) ⇒ Object



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

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

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



138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/glimmer/libui/control_proxy/window_proxy.rb', line 138

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



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

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

#width(value = nil) ⇒ Object Also known as: width=, set_width



118
119
120
121
122
123
124
# File 'lib/glimmer/libui/control_proxy/window_proxy.rb', line 118

def width(value = nil)
  if value.nil?
    content_size.first
  else
    set_content_size(value, height)
  end
end