Class: Glimmer::DSL::SWT::CustomWidgetExpression

Inherits:
Expression
  • Object
show all
Includes:
ParentExpression, TopLevelExpression
Defined in:
lib/glimmer/dsl/swt/custom_widget_expression.rb

Instance Method Summary collapse

Instance Method Details

#add_content(parent, keyword, *args, &block) ⇒ Object



54
55
56
57
58
59
60
61
62
# File 'lib/glimmer/dsl/swt/custom_widget_expression.rb', line 54

def add_content(parent, keyword, *args, &block)
  # TODO consider avoiding source_location
  return if block&.parameters&.count == 2
  if block.source_location == parent.content&.__getobj__&.source_location
    parent.content.call(parent) unless parent.content.called?
  else
    super
  end
end

#can_interpret?(parent, keyword, *args, &block) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
43
44
45
# File 'lib/glimmer/dsl/swt/custom_widget_expression.rb', line 40

def can_interpret?(parent, keyword, *args, &block)
  custom_widget_class = UI::CustomWidget.for(keyword)
  custom_widget_class and
    (parent.respond_to?(:swt_widget) or
    custom_widget_class.ancestors.include?(UI::CustomShell))
end

#interpret(parent, keyword, *args, &block) ⇒ Object



47
48
49
50
51
52
# File 'lib/glimmer/dsl/swt/custom_widget_expression.rb', line 47

def interpret(parent, keyword, *args, &block)
  options = args.last.is_a?(Hash) ? args.pop : {}
  UI::CustomWidget.for(keyword).new(parent, *args, options, &block).tap do |new_custom_widget|
    new_custom_widget.body_root.paint_pixel_by_pixel(&block) if block&.parameters&.count == 2
  end
end