Class: GuindillaGUI::Svg

Inherits:
Element show all
Defined in:
lib/guindilla_gui/guindilla_classes.rb

Overview

—————————————————————————-#

Svg                                         #

—————————————————————————-#

Instance Attribute Summary collapse

Attributes inherited from Element

#attributes, #id

Attributes inherited from Guindilla

#active_id, #blocks, #elements, #inputs, #socket

Instance Method Summary collapse

Methods inherited from Element

#get_position

Methods inherited from Guindilla

#after, #alert, #align, #append, #attributes, #audio_out, #background, #border, #border_color, #border_radius, #border_width, #bullet_list, #button, #canvas, #chart, #checkbox, #circle, #color, #color_input, #container, #display, #every, #file_input, #font, #font_family, #font_size, #h_box, #h_rule, #heading, #height, #hide, #image, #justify, #line_break, #link, #margin, #move_to, #number_input, #on_click, #on_hover, #on_leave, #on_mouse_move, #opacity, #ordered_list, #padding, #para, #polygon, #radio_button, #range_slider, #rectangle, #rotate, #show, #size, #source, #square, #style, #sub_script, #sup_script, #text, #text_align, #text_input, #toggle, #transition, #triangle, #url_input, #v_box, #video_out, #web_frame, #width

Constructor Details

#initialize(type, attributes, &block) ⇒ Svg

Returns a new instance of Svg.



522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
# File 'lib/guindilla_gui/guindilla_classes.rb', line 522

def initialize(type, attributes, &block)
  attributes[:fill] = attributes.delete(:color) if attributes.has_key?(:color)
  if attributes.has_key?(:r)
    attributes[:width] = attributes[:r] * 2
    attributes[:height] = attributes[:r] * 2
  end
  @type = type
  hidden = attributes.delete(:hidden)
  @id = "svg_#{Time.now.hash.to_s.gsub('-', 'x')}"
  svg_ns = "http://www.w3.org/2000/svg"

  send_js(%Q~
    const #{@id} = document.createElementNS("#{svg_ns}", "svg");
    #{@id}.id = "#{@id}";
    #{@id}.setAttribute("width", #{attributes[:width]});
    #{@id}.setAttribute("height", #{attributes[:height]});
    const #{type}_#{@id} = document.createElementNS("#{svg_ns}", "#{type}");
    #{type}_#{@id}.id = "#{type}_#{@id}";
  ~)

  attributes.each do |key, value|
    send_js(%Q~
      #{type}_#{@id}.setAttribute("#{key}", "#{value}");
    ~)
  end

  send_js(%Q~ #{self.id}.appendChild(#{type}_#{@id}); ~)
  send_js(%Q~ #{@@gui.active_id}.append(#{@id}); ~)
  self.hide if hidden == true

  @attributes = attributes
  @@gui.elements[:"#{@id}"] = self
  return self  ###
end

Instance Attribute Details

#typeObject (readonly)

Returns the value of attribute type.



520
521
522
# File 'lib/guindilla_gui/guindilla_classes.rb', line 520

def type
  @type
end