Fixed margin not correctly applying to elements

This commit is contained in:
2019-03-04 19:59:43 -06:00
parent 85f35ee1f4
commit 7eae43d566
4 changed files with 20 additions and 24 deletions

View File

@@ -69,15 +69,11 @@ module CyberarmEngine
def recalculate
@current_position = Vector.new(@margin_left, @margin_top)
if @children.first
@current_position.x += @children.first.margin_left
@current_position.y += @children.first.margin_top
end
layout
@width = @max_width ? @max_width : (@children.map {|c| c.x + c.width }.max || 0).round
@height = @max_height ? @max_height : (@children.map {|c| c.y + c.height}.max || 0).round
@width = @max_width ? @max_width : (@children.map {|c| c.x + c.width + c.margin_right}.max || 0).round
@height = @max_height ? @max_height : (@children.map {|c| c.y + c.height+ c.margin_top }.max || 0).round
# Move child to parent after positioning
@children.each do |child|
@@ -104,8 +100,8 @@ module CyberarmEngine
end
def position_on_current_line(element)
element.x = @current_position.x
element.y = @current_position.y
element.x = element.margin_left + @current_position.x
element.y = element.margin_top + @current_position.y
element.recalculate
@@ -114,8 +110,8 @@ module CyberarmEngine
end
def move_to_next_line(element)
element.x = @current_position.x
element.y = @current_position.y
element.x = element.margin_left + @current_position.x
element.y = element.margin_top + @current_position.y
element.recalculate

View File

@@ -147,11 +147,11 @@ module CyberarmEngine
end
def width
@border_thickness_left + @padding_left + @width + @padding_right + @border_thickness_right
(@border_thickness_left + @padding_left) + @width + (@padding_right + @border_thickness_right)
end
def height
@border_thickness_top + @padding_top + @height + @padding_bottom + @border_thickness_bottom
(@border_thickness_top + @padding_top) + @height + (@padding_bottom + @border_thickness_bottom)
end
def background=(_background)

View File

@@ -10,8 +10,8 @@ module CyberarmEngine
@current_position.x = @margin_left + @x
@current_position.y += child.height + child.margin_bottom
child.x = @current_position.x
child.y = @current_position.y
child.x = element.margin_left + @current_position.x
child.y = element.margin_top + @current_position.y
child.recalculate

View File

@@ -36,17 +36,17 @@ module CyberarmEngine
height: 0,
color: Gosu::Color::WHITE,
background: Gosu::Color::NONE,
margin: 2,
padding: 2,
margin: 0,
padding: 0,
border_thickness: 0,
border_color: Gosu::Color::NONE,
border_radius: 0,
},
Button: {
margin: 2,
padding: 2,
border_thickness: 2,
margin: 1,
padding: 4,
border_thickness: 4,
border_color: ["ffd59674".hex, "ffff8746".hex],
border_radius: 0,
background: ["ffc75e61".to_i(16), "ffe26623".to_i(16)],
@@ -76,15 +76,15 @@ module CyberarmEngine
},
Label: {
text_size: 24,
text_size: 28,
text_shadow: false,
font: "Akaash"
font: "Arial",
margin: 0,
padding: 2
},
ToggleButton: {
checkmark: "",
padding_left: 0,
margin_left: 0
checkmark: ""
}
}
end