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, #custom_control, #keyword, #libui, #options, #parent_custom_control, #parent_proxy, #slot

Instance Method Summary collapse

Methods inherited from Glimmer::LibUI::ControlProxy

#append_properties, #append_property, #bind_content, #can_handle_listener?, constant_symbol, #content, control_proxies, control_proxy_class, 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, #window_proxy

Methods included from DataBindable

#data_bind, #data_bind_read, #data_bind_write, #data_binding_model_attribute_observer_registrations

Methods included from Parent

#children

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



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/glimmer/libui/control_proxy/window_proxy.rb', line 105

def content_size(*args)
  if args.empty?
    width = Fiddle::Pointer.malloc(64)
    height = Fiddle::Pointer.malloc(64)
    ::LibUI.window_content_size(@libui, width, height)
    width = width[0, 64].unpack1('i')
    height = height[0, 64].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

#focusedObject Also known as: focused?



161
162
163
# File 'lib/glimmer/libui/control_proxy/window_proxy.rb', line 161

def focused
  Glimmer::LibUI.integer_to_boolean(super)
end

#handle_listener(listener_name, &listener) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/glimmer/libui/control_proxy/window_proxy.rb', line 75

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) || return_value.is_a?(TrueClass) || return_value.is_a?(FalseClass)
      end
      if return_value.is_a?(Numeric)
        return_value
      elsif return_value.is_a?(TrueClass) || return_value.is_a?(FalseClass)
        return_value ? 1 : 0
      elsif self != ControlProxy.main_window_proxy
        1
      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



133
134
135
136
137
138
139
# File 'lib/glimmer/libui/control_proxy/window_proxy.rb', line 133

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



143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/glimmer/libui/control_proxy/window_proxy.rb', line 143

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 Also known as: open



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



123
124
125
126
127
128
129
# File 'lib/glimmer/libui/control_proxy/window_proxy.rb', line 123

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