Skip to content

Commit

Permalink
Offset logic fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Scott Lewis committed Sep 16, 2015
1 parent 4b4361f commit 8d9d8d6
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 25 deletions.
4 changes: 2 additions & 2 deletions lib/cura/attributes/has_relative_coordinates.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ def initialize(attributes={})
#
# @return [Integer]
def absolute_x
parent? && parent.respond_to?(:absolute_x) ? @x + parent.offsets.left + parent.padding.left + parent.absolute_x : @x
parent? && parent.respond_to?(:absolute_x) ? @x + parent.offsets.left + parent.absolute_x : @x
end

# Get the absolute Y coordinate of this object.
#
# @return [Integer]
def absolute_y
parent? && parent.respond_to?(:absolute_y) ? @y + parent.offsets.top + parent.padding.top + parent.absolute_y : @y
parent? && parent.respond_to?(:absolute_y) ? @y + parent.offsets.top + parent.absolute_y : @y
end

end
Expand Down
22 changes: 3 additions & 19 deletions lib/cura/component/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,8 @@ class Base
include Attributes::HasOffsets
include Attributes::HasRelativeCoordinates

# Get the outer width of this component.
# This is the dimension including any borders, margins, or padding sizes.
#
# @return [Integer]
def outer_width # TODO: Remove
width + offsets.width + padding.width
end

# Get the outer width of this component.
# This is the dimension including any borders, margins, or padding sizes.
#
# @return [Integer]
def outer_height # TODO: Remove
height + offsets.height + padding.height
end

# Get the cursor for this application.
# TODO: Delegate
# TODO: Delegate something like: def_delegate(:cursor) { application }
#
# @return [Cursor]
def cursor
Expand Down Expand Up @@ -149,8 +133,8 @@ def inspect

# Draw the background of this component.
def draw_background
x = absolute_x + @offsets.left
y = absolute_y + @offsets.top
x = absolute_x + @margin.left + @border.left
y = absolute_y + @margin.top + @border.top
width = self.width + @padding.width
height = self.height + @padding.height
color = background
Expand Down
4 changes: 2 additions & 2 deletions lib/cura/component/group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def width
return @width unless @width == :auto
return 0 if children.empty?

children.collect { |child| child.x + child.width + child.offsets.width + child.padding.width }.max
children.collect { |child| child.x + child.width + child.offsets.width }.max
end

# Get the height of this group.
Expand All @@ -29,7 +29,7 @@ def height
return @height unless @height == :auto
return 0 if children.empty?

children.collect { |child| child.y + child.height + child.offsets.height + child.padding.height }.max
children.collect { |child| child.y + child.height + child.offsets.height }.max
end

# Add a child to this group and set it's parent to this Group.
Expand Down
4 changes: 2 additions & 2 deletions lib/cura/component/pack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,12 @@ def pack_children
children.each do |child|
if horizontal?
child.x = child_x
child_x += child.outer_width + spacing
child_x += child.width + child.offsets.width + spacing

child.height = height if fill?
elsif vertical?
child.y = child_y if vertical?
child_y += child.outer_height + spacing
child_y += child.height + child.offsets.height + spacing

child.width = width if fill?
end
Expand Down

0 comments on commit 8d9d8d6

Please sign in to comment.