mirror of
https://github.com/cyberarm/cyberarm_engine.git
synced 2025-12-16 13:12:34 +00:00
Fixed margin not correctly applying to elements
This commit is contained in:
@@ -69,15 +69,11 @@ module CyberarmEngine
|
|||||||
|
|
||||||
def recalculate
|
def recalculate
|
||||||
@current_position = Vector.new(@margin_left, @margin_top)
|
@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
|
layout
|
||||||
|
|
||||||
@width = @max_width ? @max_width : (@children.map {|c| c.x + c.width }.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}.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
|
# Move child to parent after positioning
|
||||||
@children.each do |child|
|
@children.each do |child|
|
||||||
@@ -104,8 +100,8 @@ module CyberarmEngine
|
|||||||
end
|
end
|
||||||
|
|
||||||
def position_on_current_line(element)
|
def position_on_current_line(element)
|
||||||
element.x = @current_position.x
|
element.x = element.margin_left + @current_position.x
|
||||||
element.y = @current_position.y
|
element.y = element.margin_top + @current_position.y
|
||||||
|
|
||||||
element.recalculate
|
element.recalculate
|
||||||
|
|
||||||
@@ -114,8 +110,8 @@ module CyberarmEngine
|
|||||||
end
|
end
|
||||||
|
|
||||||
def move_to_next_line(element)
|
def move_to_next_line(element)
|
||||||
element.x = @current_position.x
|
element.x = element.margin_left + @current_position.x
|
||||||
element.y = @current_position.y
|
element.y = element.margin_top + @current_position.y
|
||||||
|
|
||||||
element.recalculate
|
element.recalculate
|
||||||
|
|
||||||
|
|||||||
@@ -147,11 +147,11 @@ module CyberarmEngine
|
|||||||
end
|
end
|
||||||
|
|
||||||
def width
|
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
|
end
|
||||||
|
|
||||||
def height
|
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
|
end
|
||||||
|
|
||||||
def background=(_background)
|
def background=(_background)
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ module CyberarmEngine
|
|||||||
@current_position.x = @margin_left + @x
|
@current_position.x = @margin_left + @x
|
||||||
@current_position.y += child.height + child.margin_bottom
|
@current_position.y += child.height + child.margin_bottom
|
||||||
|
|
||||||
child.x = @current_position.x
|
child.x = element.margin_left + @current_position.x
|
||||||
child.y = @current_position.y
|
child.y = element.margin_top + @current_position.y
|
||||||
|
|
||||||
child.recalculate
|
child.recalculate
|
||||||
|
|
||||||
|
|||||||
@@ -36,17 +36,17 @@ module CyberarmEngine
|
|||||||
height: 0,
|
height: 0,
|
||||||
color: Gosu::Color::WHITE,
|
color: Gosu::Color::WHITE,
|
||||||
background: Gosu::Color::NONE,
|
background: Gosu::Color::NONE,
|
||||||
margin: 2,
|
margin: 0,
|
||||||
padding: 2,
|
padding: 0,
|
||||||
border_thickness: 0,
|
border_thickness: 0,
|
||||||
border_color: Gosu::Color::NONE,
|
border_color: Gosu::Color::NONE,
|
||||||
border_radius: 0,
|
border_radius: 0,
|
||||||
},
|
},
|
||||||
|
|
||||||
Button: {
|
Button: {
|
||||||
margin: 2,
|
margin: 1,
|
||||||
padding: 2,
|
padding: 4,
|
||||||
border_thickness: 2,
|
border_thickness: 4,
|
||||||
border_color: ["ffd59674".hex, "ffff8746".hex],
|
border_color: ["ffd59674".hex, "ffff8746".hex],
|
||||||
border_radius: 0,
|
border_radius: 0,
|
||||||
background: ["ffc75e61".to_i(16), "ffe26623".to_i(16)],
|
background: ["ffc75e61".to_i(16), "ffe26623".to_i(16)],
|
||||||
@@ -76,15 +76,15 @@ module CyberarmEngine
|
|||||||
},
|
},
|
||||||
|
|
||||||
Label: {
|
Label: {
|
||||||
text_size: 24,
|
text_size: 28,
|
||||||
text_shadow: false,
|
text_shadow: false,
|
||||||
font: "Akaash"
|
font: "Arial",
|
||||||
|
margin: 0,
|
||||||
|
padding: 2
|
||||||
},
|
},
|
||||||
|
|
||||||
ToggleButton: {
|
ToggleButton: {
|
||||||
checkmark: "√",
|
checkmark: "√"
|
||||||
padding_left: 0,
|
|
||||||
margin_left: 0
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user