attempted to add margin capability

This commit is contained in:
Fox 2016-02-23 08:11:09 -08:00
parent a100f0f50c
commit 6cb3c23d09
4 changed files with 13 additions and 5 deletions

View File

@ -12,6 +12,7 @@ class element
@horizontal = "left" @horizontal = "left"
@vertical = "top" @vertical = "top"
@margin = 0
debugDraw: => debugDraw: =>
graphics.setLineWidth 0.5 graphics.setLineWidth 0.5
@ -120,16 +121,20 @@ class element
@y = @parent.y @y = @parent.y
switch @horizontal switch @horizontal
when "left"
@x += @margin
when "center" when "center"
@x += (@parent.w - @w)/2 @x += (@parent.w - @w)/2
when "right" when "right"
@x += @parent.w - @w @x += @parent.w - @w - @margin
switch @vertical switch @vertical
when "top"
@y += @margin
when "center" when "center"
@y += (@parent.h - @h)/2 @y += (@parent.h - @h)/2
when "bottom" when "bottom"
@y += @parent.h - @h @y += @parent.h - @h - @margin
return @ return @

View File

@ -38,13 +38,13 @@ class text extends element
when "center" when "center"
@x -= (w - @w)/2 @x -= (w - @w)/2
when "right" when "right"
@x -= w - @w @x -= w - @w - @margin
switch @vertical switch @vertical
when "center" when "center"
@y -= (h - @h)/2 @y -= (h - @h)/2
when "right" when "right"
@y -= h - @h @y -= h - @h - @margin
@w = w @w = w
@h = h @h = h

View File

@ -59,6 +59,8 @@ class Pop
error "Unimplemented." error "Unimplemented."
skin: (element, skin, apply_to_children=false) => skin: (element, skin, apply_to_children=false) =>
element.margin = skin.margin
if element.background if element.background
element.background = skin.background element.background = skin.background
if element.color if element.color

View File

@ -1,7 +1,8 @@
import graphics from love import graphics from love
return { skin = {
color: {255, 255, 255, 255} color: {255, 255, 255, 255}
background: false background: false
font: graphics.newFont(13) font: graphics.newFont(13)
margin: 2
} }