Class: GuindillaGUI::Element

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

Overview

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

Element                                       #

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

‘Element` parent class that Guindilla methods use to create HTML elements.

Direct Known Subclasses

AudioVideo, Box, Canvas, Chart, Input, Svg

Instance Attribute Summary collapse

Attributes inherited from Guindilla

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

Instance Method Summary collapse

Methods inherited from Guindilla

#after, #alert, #align, #append, #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 = {}) ⇒ Element

Returns a new instance of Element.



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/guindilla_gui/guindilla_classes.rb', line 138

def initialize(type, attributes={})
  @id = "#{type}_#{Time.now.hash.to_s.gsub('-', 'x')}"
  send_js(%Q~
    const #{@id} = document.createElement("#{type}");
    #{@id}.id = "#{@id}";
  ~)

  hidden = attributes.delete(:hidden)
  self.hide if hidden == true
  send_js(%Q~ #{@@gui.active_id}.append(#{@id}); ~)

  if attributes.has_key?(:size)
    size = attributes[:size].split(",")
    attributes[:width] = size[0].to_i
    attributes[:height] = size[1].to_i
  end

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

Instance Attribute Details

#attributesObject

, :position



136
137
138
# File 'lib/guindilla_gui/guindilla_classes.rb', line 136

def attributes
  @attributes
end

#idObject (readonly)

Returns the value of attribute id.



135
136
137
# File 'lib/guindilla_gui/guindilla_classes.rb', line 135

def id
  @id
end

Instance Method Details

#get_position(&block) ⇒ Object

REVIEW: this is ugly



162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/guindilla_gui/guindilla_classes.rb', line 162

def get_position(&block)
  @@gui.blocks[:"#{self.id}_pos"] = block if block_given?
  send_js(%Q~
    var rect = #{@id}.getBoundingClientRect();
    var rect_string = ""
    for (var key in rect) {
      if(typeof rect[key] !== 'function') {
        rect_string += `${key}:${rect[key]},`;
      }
    }
    socket.send("#{id}:!!:position:!!:" + rect_string)
  ~)
end