lib/cyberarm_engine/ui/element.rb in cyberarm_engine-0.13.1 vs lib/cyberarm_engine/ui/element.rb in cyberarm_engine-0.14.0

- old
+ new

@@ -2,11 +2,11 @@ class Element include Theme include Event include Common - attr_accessor :x, :y, :z, :enabled + attr_accessor :x, :y, :z, :enabled, :tip attr_reader :parent, :options, :style, :event_handler, :background_canvas, :border_canvas def initialize(options = {}, block = nil) @parent = options.delete(:parent) # parent Container (i.e. flow/stack) options = theme_defaults(options) @@ -14,10 +14,11 @@ @block = block @focus = false @enabled = true @visible = true + @tip = @options[:tip] ? @options[:tip] : "" @style = Style.new(options) @x = @style.x @y = @style.y @@ -108,10 +109,12 @@ event(:enter) event(:hover) event(:leave) event(:blur) + + event(:changed) end def enabled? @enabled end @@ -150,10 +153,14 @@ end def button_up(id) end + def draggable?(button) + false + end + def render end def hit?(x, y) x.between?(@x, @x + width) && @@ -210,11 +217,11 @@ private def dimensional_size(size, dimension) raise "dimension must be either :width or :height" unless dimension == :width || dimension == :height if size && size.is_a?(Numeric) if size.between?(0.0, 1.0) - ((@parent.send(:"content_#{dimension}") - self.send(:"noncontent_#{dimension}") - 1) * size).round + ((@parent.send(:"content_#{dimension}") - self.send(:"noncontent_#{dimension}")) * size).round else size end else nil @@ -237,10 +244,12 @@ @style.border_canvas.update end def root + return self if is_root? + unless @root && @root.parent.nil? @root = parent loop do if @root.parent.nil? @@ -269,8 +278,12 @@ raise "#{self.class}#value was not overridden!" end def value=(value) raise "#{self.class}#value= was not overridden!" + end + + def to_s + "#{self.class} x=#{x} y=#{y} width=#{width} height=#{height} value=#{ value.is_a?(String) ? "\"#{value}\"" : value }" end end end \ No newline at end of file