Class: Glimmer::SWT::Custom::Shape::Text

Inherits:
Glimmer::SWT::Custom::Shape show all
Defined in:
lib/glimmer/swt/custom/shape/text.rb

Constant Summary

Constants inherited from Glimmer::SWT::Custom::Shape

String

Constants inherited from WidgetProxy

WidgetProxy::DEFAULT_INITIALIZERS, WidgetProxy::JS_KEY_CODE_TO_SWT_KEY_CODE_MAP, WidgetProxy::JS_LOCATION_TO_SWT_KEY_LOCATION_MAP, WidgetProxy::SWT_CURSOR_TO_CSS_CURSOR_MAP

Instance Attribute Summary

Attributes inherited from WidgetProxy

#args, #background, #children, #cursor, #disposed?, #enabled, #focus, #font, #foreground, #menu, #menu_requested, #menu_x, #menu_y, #parent, #path, #rendered

Instance Method Summary collapse

Methods inherited from Glimmer::SWT::Custom::Shape

#attach, create, #current_parameter_name?, #get_attribute, #get_parameter_attribute, #has_attribute?, keywords, #location_parameter_names, #method_missing, #parameter_index, #parameter_name?, #post_add_content, #render, #respond_to?, #set_attribute, valid?

Methods included from PropertyOwner

#attribute_getter, #attribute_setter, #get_attribute, #set_attribute

Methods inherited from WidgetProxy

#add_content_on_render, #add_css_class, #add_css_classes, #add_observer, #apply_property_type_converters, #attach, #build_dom, #can_handle_observation_request?, #clear_css_classes, #content, #content_on_render_blocks, #css_classes, #default_observation_request_to_event_mapping, #dialog_ancestor, #dispose, #dom_element, #effective_observation_request_to_event_mapping, #event_handling_suspended?, #event_listener_proxies, for, #get_data, #handle_javascript_observation_request, #handle_observation_request, #has_style?, #id, #id=, #initialize, #listener_dom_element, #listener_path, #listeners, #listeners_for, max_id_number_for, max_id_numbers, #method_missing, #name, next_id_number_for, #observation_request_to_event_mapping, #observation_requests, #parent_dom_element, #parent_path, #parents, #post_add_content, #post_dispose_child, #post_initialize_child, #print, #property_type_converters, #remove_all_listeners, #remove_css_class, #remove_css_classes, #remove_event_listener_proxies, #render, reset_max_id_numbers!, #resume_event_handling, #selector, #set_attribute, #set_data, #set_focus, #shell, #skip_content_on_render_blocks?, #style_element, #suspend_event_handling, #swt_data, #swt_widget, underscored_widget_name, widget_class, widget_exists?, widget_handling_listener, #widget_property_listener_installers

Constructor Details

This class inherits a constructor from Glimmer::SWT::WidgetProxy

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Glimmer::SWT::Custom::Shape

Instance Method Details

#background=(value) ⇒ Object



84
85
86
87
88
# File 'lib/glimmer/swt/custom/shape/text.rb', line 84

def background=(value)
  # TODO override background= to fill a rectangle containing text, matching its size
  # For now, disable background when foreground is not set
  super(value) unless foreground.nil?
end

#domObject



99
100
101
102
103
104
105
106
107
# File 'lib/glimmer/swt/custom/shape/text.rb', line 99

def dom
  shape_id = id
  shape_class = name
  @dom ||= xml {
    tag(:_name => 'text', id: shape_id, class: shape_class, x: @args[1], y: @args[2]) {
      @args[0]
    }
  }.to_s
end

#elementObject



95
96
97
# File 'lib/glimmer/swt/custom/shape/text.rb', line 95

def element
  'text'
end

#foreground=(value) ⇒ Object



90
91
92
93
# File 'lib/glimmer/swt/custom/shape/text.rb', line 90

def foreground=(value)
  super(value)
  self.background = value
end

#parameter_namesObject



33
34
35
36
37
38
39
40
41
42
# File 'lib/glimmer/swt/custom/shape/text.rb', line 33

def parameter_names
  if text_parameter_names.size == @args.size
    @parameter_names = text_parameter_names
  elsif text_transparent_parameter_names.size == @args.size
    @parameter_names = text_transparent_parameter_names
  elsif text_flags_parameter_names.size == @args.size
    @parameter_names = text_flags_parameter_names
  end
  @parameter_names || text_parameter_names
end

#possible_parameter_namesObject



44
45
46
47
# File 'lib/glimmer/swt/custom/shape/text.rb', line 44

def possible_parameter_names
  # TODO refactor and improve this method through meta-programming (and share across other shapes)
  (text_parameter_names + text_transparent_parameter_names + text_flags_parameter_names).uniq
end

#reattach(old_element) ⇒ Object



78
79
80
81
82
# File 'lib/glimmer/swt/custom/shape/text.rb', line 78

def reattach(old_element)
  old_element.attr('x', Element[@dom].attr('x'))
  old_element.attr('y', Element[@dom].attr('y'))
  old_element.text(Element[@dom].html)
end

#set_parameter_attribute(attribute_name, *args) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/glimmer/swt/custom/shape/text.rb', line 61

def set_parameter_attribute(attribute_name, *args)
  if @parameter_names.to_a.map(&:to_s).include?(attribute_name.to_s)
    super(attribute_name, *args)
    build_dom
    reattach(dom_element)
    return
  end
  if text_parameter_names.map(&:to_s).include?(attribute_name.to_s)
    @parameter_names = text_parameter_names
  elsif text_transparent_parameter_names.map(&:to_s).include?(attribute_name.to_s)
    @parameter_names = text_transparent_parameter_names
  elsif text_flags_parameter_names.map(&:to_s).include?(attribute_name.to_s)
    @parameter_names = text_flags_parameter_names
  end
  super(attribute_name, *args)
end

#text_flags_parameter_namesObject



57
58
59
# File 'lib/glimmer/swt/custom/shape/text.rb', line 57

def text_flags_parameter_names
  [:string, :x, :y, :flags]
end

#text_parameter_namesObject



49
50
51
# File 'lib/glimmer/swt/custom/shape/text.rb', line 49

def text_parameter_names
  [:string, :x, :y]
end

#text_transparent_parameter_namesObject



53
54
55
# File 'lib/glimmer/swt/custom/shape/text.rb', line 53

def text_transparent_parameter_names
  [:string, :x, :y, :is_transparent]
end