Method: Glimmer::UI::CustomShape#initialize

Defined in:
lib/glimmer/ui/custom_shape.rb

#initialize(parent, *args, options, &content) ⇒ Object

Raises:

  • (Glimmer::Error)


165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/glimmer/ui/custom_shape.rb', line 165

def initialize(parent, *args, options, &content)
  SWT::DisplayProxy.current_custom_widgets_and_shapes << self
  @parent_proxy = @parent = parent
  @parent_proxy = @parent&.get_data('proxy') if @parent.respond_to?(:get_data) && @parent.get_data('proxy')
  @args = args
  options ||= {}
  @options = self.class.options.merge(options)
  @content = Util::ProcTracker.new(content) if content
  execute_hook('before_body')
  body_block = self.class.instance_variable_get("@body_block")
  raise Glimmer::Error, 'Invalid custom shape for having no body! Please define body block!' if body_block.nil?
  @body_root = instance_exec(&body_block)
  raise Glimmer::Error, 'Invalid custom shape for having an empty body! Please fill body block!' if @body_root.nil?
  auto_exec do # TODO is this necessary given shape is a lightweight construct (not SWT widget) ?
    @body_root.set_data('custom_shape', self)
  end
  auto_exec do
    @dispose_listener_registration = @body_root.on_shape_disposed do
      unless @body_root.shell_proxy.last_shell_closing?
        observer_registrations.compact.each(&:deregister)
        observer_registrations.clear
      end
    end
  end
  execute_hook('after_body')
  post_add_content if content.nil?
end