opal/browser/canvas.rb in opal-browser-0.2.0 vs opal/browser/canvas.rb in opal-browser-0.3.0
- old
+ new
@@ -1,16 +1,14 @@
-require 'promise'
-
require 'browser/canvas/style'
require 'browser/canvas/text'
require 'browser/canvas/data'
require 'browser/canvas/gradient'
module Browser
class Canvas
- include Native
+ include Native::Wrapper
attr_reader :element, :style, :text
def initialize(*args)
if DOM::Element === args.first
@@ -57,10 +55,18 @@
def height
@element[:height].to_i
end
+ def width=(new_width)
+ @element[:width] = new_width.to_i
+ end
+
+ def height=(new_height)
+ @element[:height] = new_height.to_i
+ end
+
def append_to(parent)
@element.append_to(parent)
end
def load(path)
@@ -310,9 +316,17 @@
end
def to_data(type = undefined)
`#{@element.to_n}.toDataUrl(type)`
end
+
+ def to_dom(*)
+ @element
+ end
+
+ def on(*args, &block); @element.on(*args, &block); end
+ def one(*args, &block); @element.one(*args, &block); end
+ def off(*args, &block); @element.off(*args, &block); end
end
Browser::DOM::Builder.for Canvas do |b, item|
item.element
end