lib/glimmer/swt/custom/shape.rb in glimmer-dsl-swt-4.18.7.1 vs lib/glimmer/swt/custom/shape.rb in glimmer-dsl-swt-4.18.7.2

- old
+ new

@@ -212,16 +212,16 @@ # moves by x delta and y delta. Subclasses must implement # provdies a default implementation that assumes moving x and y is sufficient by default (not for polygons though, which must override) def move_by(x_delta, y_delta) if respond_to?(:x) && respond_to?(:y) && respond_to?(:x=) && respond_to?(:y=) if default_x? - self.default_x_delta += x_delta + self.x_delta += x_delta else self.x += x_delta end if default_y? - self.default_y_delta += y_delta + self.y_delta += y_delta else self.y += y_delta end end end @@ -481,10 +481,25 @@ else @properties.symbolize_keys[attribute_name.to_s.to_sym] end end + # Sets data just like SWT widgets + def set_data(key=nil, value) + @data ||= {} + @data[key] = value + end + alias setData set_data # for compatibility with SWT APIs + + # Gets data just like SWT widgets + def get_data(key=nil) + @data ||= {} + @data[key] + end + alias getData get_data # for compatibility with SWT APIs + alias data get_data # for compatibility with SWT APIs + def method_missing(method_name, *args, &block) if method_name.to_s.end_with?('=') set_attribute(method_name, *args) elsif has_attribute?(method_name) get_attribute(method_name) @@ -674,11 +689,11 @@ !!@calculated_args end # args translated to absolute coordinates def calculated_args - return @args if !default_x? && !default_y? && !default_width? && !default_height? && parent.is_a?(Drawable) + return @args if !default_x? && !default_y? && !default_width? && !default_height? && !max_width? && !max_height? && parent.is_a?(Drawable) # Note: Must set x and move_by because not all shapes have a real x and some must translate all their points with move_by # TODO change that by setting a bounding box for all shapes with a calculated top-left x, y and # a setter that does the moving inside them instead so that I could rely on absolute_x and absolute_y # here to get the job done of calculating absolute args @perform_redraw = false @@ -706,15 +721,15 @@ original_height = height self.height = max_height + height_delta end if default_x? original_x = x - self.x = default_x + default_x_delta + self.x = default_x + self.x_delta end if default_y? original_y = y - self.y = default_y + default_y_delta + self.y = default_y + self.y_delta end if parent.is_a?(Shape) move_by(@parent_absolute_x, @parent_absolute_y) result_args = @args.clone move_by(-1*@parent_absolute_x, -1*@parent_absolute_y) @@ -790,11 +805,13 @@ shape_width = shape.calculated_width.to_f shape_x = shape.default_x? ? 0 : shape.x.to_f shape_x + shape_width end end - if shapes.size == 1 && shapes.first.max_width? + if shapes.empty? + max_width + elsif shapes.size == 1 && shapes.first.max_width? self.parent.size.x else x_ends.max.to_f end end @@ -808,11 +825,13 @@ shape_height = shape.calculated_height.to_f shape_y = shape.default_y? ? 0 : shape.y.to_f shape_y + shape_height end end - if shapes.size == 1 && shapes.first.max_height? + if shapes.empty? + max_height + elsif shapes.size == 1 && shapes.first.max_height? self.parent.size.y else y_ends.max.to_f end end @@ -839,58 +858,62 @@ result_height = (default_height + height_delta) if default_height? result_height = (max_height + height_delta) if max_height? result_height end - def default_x_delta + def x_delta return 0 unless default_x? && x.is_a?(Array) x[1].to_f end - def default_y_delta + def y_delta return 0 unless default_y? && y.is_a?(Array) y[1].to_f end def width_delta - return 0 unless default_width? && width.is_a?(Array) + return 0 unless (default_width? || max_width?) && width.is_a?(Array) width[1].to_f end def height_delta - return 0 unless default_height? && height.is_a?(Array) + return 0 unless (default_height? || max_height?) && height.is_a?(Array) height[1].to_f end - def default_x_delta=(delta) + def x_delta=(delta) return unless default_x? - self.x = [:default, delta] + symbol = x.is_a?(Array) ? x.first : x + self.x = [symbol, delta] end - def default_y_delta=(delta) + def y_delta=(delta) return unless default_y? - self.y = [:default, delta] + symbol = y.is_a?(Array) ? y.first : y + self.y = [symbol, delta] end def width_delta=(delta) return unless default_width? - self.width = [:default, delta] + symbol = width.is_a?(Array) ? width.first : width + self.width = [symbol, delta] end def height_delta=(delta) return unless default_height? - self.height = [:default, delta] + symbol = height.is_a?(Array) ? height.first : height + self.height = [symbol, delta] end def calculated_x result = default_x? ? default_x : self.x - result += default_x_delta + result += self.x_delta result end def calculated_y result = default_y? ? default_y : self.y - result += default_y_delta + result += self.y_delta result end def absolute_x x = calculated_x