Class: Glimmer::SWT::LabelProxy

Inherits:
WidgetProxy show all
Defined in:
lib/glimmer/swt/label_proxy.rb

Constant Summary

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 collapse

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 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=, #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, #reattach, #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

Methods included from PropertyOwner

#attribute_getter, #attribute_setter, #get_attribute, #set_attribute

Constructor Details

#initialize(parent, args, block) ⇒ LabelProxy

Returns a new instance of LabelProxy.



32
33
34
35
36
# File 'lib/glimmer/swt/label_proxy.rb', line 32

def initialize(parent, args, block)
  @separator = args.detect { |arg| SWTProxy[arg] == SWTProxy[:separator] }
  @vertical = args.detect { |arg| SWTProxy[arg] == SWTProxy[:vertical] }
  super(parent, args, block)
end

Dynamic Method Handling

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

Instance Attribute Details

#background_imageObject

Returns the value of attribute background_image.



28
29
30
# File 'lib/glimmer/swt/label_proxy.rb', line 28

def background_image
  @background_image
end

#imageObject

Returns the value of attribute image.



28
29
30
# File 'lib/glimmer/swt/label_proxy.rb', line 28

def image
  @image
end

#separatorObject (readonly) Also known as: separator?

Returns the value of attribute separator.



28
29
30
# File 'lib/glimmer/swt/label_proxy.rb', line 28

def separator
  @separator
end

#textObject

Returns the value of attribute text.



28
29
30
# File 'lib/glimmer/swt/label_proxy.rb', line 28

def text
  @text
end

#verticalObject (readonly) Also known as: vertical?

Returns the value of attribute vertical.



28
29
30
# File 'lib/glimmer/swt/label_proxy.rb', line 28

def vertical
  @vertical
end

Instance Method Details

#alignmentObject



69
70
71
72
73
74
75
76
# File 'lib/glimmer/swt/label_proxy.rb', line 69

def alignment
  if @alignment.nil?
    found_arg = nil
    @alignment = [:left, :center, :right].detect {|align| found_arg = args.detect { |arg| SWTProxy[align] == SWTProxy[arg] } }
    args.delete(found_arg)
  end
  @alignment
end

#alignment=(value) ⇒ Object



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

def alignment=(value)
  # TODO consider storing swt value in the future instead
  @alignment = value
  dom_element.css('text-align', @alignment.to_s)
end

#domObject



84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/glimmer/swt/label_proxy.rb', line 84

def dom
  label_id = id
  label_class = name
  label_style = "text-align: #{alignment}; "
  label_style += "border-top: 1px solid rgb(207, 207, 207); " if separator? && horizontal?
  label_style += "border-right: 1px solid rgb(207, 207, 207); height: 100%; " if separator? && vertical?
  @dom ||= html {
    label(id: label_id, class: label_class, style: label_style) {
      html_text
    }
  }.to_s
end

#elementObject



65
66
67
# File 'lib/glimmer/swt/label_proxy.rb', line 65

def element
  'label'
end

#horizontalObject Also known as: horizontal?



38
39
40
# File 'lib/glimmer/swt/label_proxy.rb', line 38

def horizontal
  !vertical
end

#html_textObject



48
49
50
# File 'lib/glimmer/swt/label_proxy.rb', line 48

def html_text
  text && CGI.escape_html(text).gsub("\n", '<br />')
end