mirror of
https://github.com/TangentFoxy/Pop.Box.git
synced 2024-12-15 12:44:20 +00:00
close #29 renaming margin
This commit is contained in:
parent
d530dfc5e0
commit
d980e14c1b
@ -23,7 +23,7 @@ function love.load()
|
||||
pop.text(nil, "Here's some test text in the bottom right corner!"):align("right", "bottom")
|
||||
pop.skin(pop.text("Here's easier-to-code test text in the center!"):align("center", "center", true)) -- 'true' means align to pixel!
|
||||
w = pop.box(nil, {255, 255, 255, 255}):align(false, "bottom"):setSize(150, 150)
|
||||
b = pop.box(w, {0, 0, 0, 255}):setMargin(5):setSize(100, 100)
|
||||
b = pop.box(w, {0, 0, 0, 255}):margin(5):setSize(100, 100)
|
||||
--]]
|
||||
|
||||
--c:move(100)
|
||||
|
@ -180,19 +180,19 @@ do
|
||||
self.y = self.parent.y
|
||||
local _exp_0 = self.horizontal
|
||||
if "left" == _exp_0 then
|
||||
self.x = self.x + self.margin
|
||||
self.x = self.x + self.spacing
|
||||
elseif "center" == _exp_0 then
|
||||
self.x = self.x + ((self.parent.w - self.w) / 2)
|
||||
elseif "right" == _exp_0 then
|
||||
self.x = self.x + (self.parent.w - self.w - self.margin)
|
||||
self.x = self.x + (self.parent.w - self.w - self.spacing)
|
||||
end
|
||||
local _exp_1 = self.vertical
|
||||
if "top" == _exp_1 then
|
||||
self.y = self.y + self.margin
|
||||
self.y = self.y + self.spacing
|
||||
elseif "center" == _exp_1 then
|
||||
self.y = self.y + ((self.parent.h - self.h) / 2)
|
||||
elseif "bottom" == _exp_1 then
|
||||
self.y = self.y + (self.parent.h - self.h - self.margin)
|
||||
self.y = self.y + (self.parent.h - self.h - self.spacing)
|
||||
end
|
||||
if toPixel then
|
||||
self.x = floor(self.x)
|
||||
@ -222,19 +222,19 @@ do
|
||||
getAlignment = function(self)
|
||||
return self.horizontal, self.vertical
|
||||
end,
|
||||
setMargin = function(self, margin)
|
||||
self.margin = margin
|
||||
setMargin = function(self, spacing)
|
||||
self.spacing = spacing
|
||||
self:align()
|
||||
return self
|
||||
end,
|
||||
getMargin = function(self)
|
||||
return self.margin
|
||||
return self.spacing
|
||||
end,
|
||||
fill = function(self)
|
||||
self.x = self.parent.x + self.margin
|
||||
self.y = self.parent.y + self.margin
|
||||
self.w = self.parent.w - self.margin * 2
|
||||
self.h = self.parent.h - self.margin * 2
|
||||
self.x = self.parent.x + self.spacing
|
||||
self.y = self.parent.y + self.spacing
|
||||
self.w = self.parent.w - self.spacing * 2
|
||||
self.h = self.parent.h - self.spacing * 2
|
||||
end,
|
||||
delete = function(self)
|
||||
for k, v in ipairs(self.child) do
|
||||
@ -252,7 +252,7 @@ do
|
||||
self.child = { }
|
||||
self.w = 0
|
||||
self.h = 0
|
||||
self.margin = 0
|
||||
self.spacing = 0
|
||||
if parent then
|
||||
self.x = parent.x
|
||||
self.y = parent.y
|
||||
|
@ -35,13 +35,13 @@ do
|
||||
if "center" == _exp_0 then
|
||||
self.x = self.x - ((w - self.w) / 2)
|
||||
elseif "right" == _exp_0 then
|
||||
self.x = self.x - (w - self.w - self.margin)
|
||||
self.x = self.x - (w - self.w - self.spacing)
|
||||
end
|
||||
local _exp_1 = self.vertical
|
||||
if "center" == _exp_1 then
|
||||
self.y = self.y - ((h - self.h) / 2)
|
||||
elseif "bottom" == _exp_1 then
|
||||
self.y = self.y - (h - self.h - self.margin)
|
||||
self.y = self.y - (h - self.h - self.spacing)
|
||||
end
|
||||
self.w = w
|
||||
self.h = h
|
||||
|
@ -180,19 +180,19 @@ do
|
||||
self.y = self.parent.y
|
||||
local _exp_0 = self.horizontal
|
||||
if "left" == _exp_0 then
|
||||
self.x = self.x + self.margin
|
||||
self.x = self.x + self.spacing
|
||||
elseif "center" == _exp_0 then
|
||||
self.x = self.x + ((self.parent.w - self.w) / 2)
|
||||
elseif "right" == _exp_0 then
|
||||
self.x = self.x + (self.parent.w - self.w - self.margin)
|
||||
self.x = self.x + (self.parent.w - self.w - self.spacing)
|
||||
end
|
||||
local _exp_1 = self.vertical
|
||||
if "top" == _exp_1 then
|
||||
self.y = self.y + self.margin
|
||||
self.y = self.y + self.spacing
|
||||
elseif "center" == _exp_1 then
|
||||
self.y = self.y + ((self.parent.h - self.h) / 2)
|
||||
elseif "bottom" == _exp_1 then
|
||||
self.y = self.y + (self.parent.h - self.h - self.margin)
|
||||
self.y = self.y + (self.parent.h - self.h - self.spacing)
|
||||
end
|
||||
if toPixel then
|
||||
self.x = floor(self.x)
|
||||
@ -222,19 +222,19 @@ do
|
||||
getAlignment = function(self)
|
||||
return self.horizontal, self.vertical
|
||||
end,
|
||||
setMargin = function(self, margin)
|
||||
self.margin = margin
|
||||
setMargin = function(self, spacing)
|
||||
self.spacing = spacing
|
||||
self:align()
|
||||
return self
|
||||
end,
|
||||
getMargin = function(self)
|
||||
return self.margin
|
||||
return self.spacing
|
||||
end,
|
||||
fill = function(self)
|
||||
self.x = self.parent.x + self.margin
|
||||
self.y = self.parent.y + self.margin
|
||||
self.w = self.parent.w - self.margin * 2
|
||||
self.h = self.parent.h - self.margin * 2
|
||||
self.x = self.parent.x + self.spacing
|
||||
self.y = self.parent.y + self.spacing
|
||||
self.w = self.parent.w - self.spacing * 2
|
||||
self.h = self.parent.h - self.spacing * 2
|
||||
end,
|
||||
delete = function(self)
|
||||
for k, v in ipairs(self.child) do
|
||||
@ -252,7 +252,7 @@ do
|
||||
self.child = { }
|
||||
self.w = 0
|
||||
self.h = 0
|
||||
self.margin = 0
|
||||
self.spacing = 0
|
||||
if parent then
|
||||
self.x = parent.x
|
||||
self.y = parent.y
|
||||
|
@ -35,13 +35,13 @@ do
|
||||
if "center" == _exp_0 then
|
||||
self.x = self.x - ((w - self.w) / 2)
|
||||
elseif "right" == _exp_0 then
|
||||
self.x = self.x - (w - self.w - self.margin)
|
||||
self.x = self.x - (w - self.w - self.spacing)
|
||||
end
|
||||
local _exp_1 = self.vertical
|
||||
if "center" == _exp_1 then
|
||||
self.y = self.y - ((h - self.h) / 2)
|
||||
elseif "bottom" == _exp_1 then
|
||||
self.y = self.y - (h - self.h - self.margin)
|
||||
self.y = self.y - (h - self.h - self.spacing)
|
||||
end
|
||||
self.w = w
|
||||
self.h = h
|
||||
|
@ -11,7 +11,7 @@ class element
|
||||
@w = 0
|
||||
@h = 0
|
||||
|
||||
@margin = 0
|
||||
@spacing = 0
|
||||
|
||||
if parent
|
||||
@x = parent.x
|
||||
@ -205,19 +205,19 @@ class element
|
||||
|
||||
switch @horizontal
|
||||
when "left"
|
||||
@x += @margin
|
||||
@x += @spacing
|
||||
when "center"
|
||||
@x += (@parent.w - @w)/2
|
||||
when "right"
|
||||
@x += @parent.w - @w - @margin
|
||||
@x += @parent.w - @w - @spacing
|
||||
|
||||
switch @vertical
|
||||
when "top"
|
||||
@y += @margin
|
||||
@y += @spacing
|
||||
when "center"
|
||||
@y += (@parent.h - @h)/2
|
||||
when "bottom"
|
||||
@y += @parent.h - @h - @margin
|
||||
@y += @parent.h - @h - @spacing
|
||||
|
||||
if toPixel
|
||||
@x = floor @x
|
||||
@ -246,19 +246,19 @@ class element
|
||||
getAlignment: =>
|
||||
return @horizontal, @vertical
|
||||
|
||||
setMargin: (margin) =>
|
||||
@margin = margin
|
||||
setMargin: (spacing) =>
|
||||
@spacing = spacing
|
||||
@align!
|
||||
return @
|
||||
|
||||
getMargin: =>
|
||||
return @margin
|
||||
return @spacing
|
||||
|
||||
fill: =>
|
||||
@x = @parent.x + @margin
|
||||
@y = @parent.y + @margin
|
||||
@w = @parent.w - @margin*2
|
||||
@h = @parent.h - @margin*2
|
||||
@x = @parent.x + @spacing
|
||||
@y = @parent.y + @spacing
|
||||
@w = @parent.w - @spacing*2
|
||||
@h = @parent.h - @spacing*2
|
||||
|
||||
delete: =>
|
||||
for k,v in ipairs @child
|
||||
|
@ -47,13 +47,13 @@ class text extends element
|
||||
when "center"
|
||||
@x -= (w - @w)/2
|
||||
when "right"
|
||||
@x -= w - @w - @margin
|
||||
@x -= w - @w - @spacing
|
||||
|
||||
switch @vertical
|
||||
when "center"
|
||||
@y -= (h - @h)/2
|
||||
when "bottom"
|
||||
@y -= h - @h - @margin
|
||||
@y -= h - @h - @spacing
|
||||
|
||||
@w = w
|
||||
@h = h
|
||||
|
@ -39,24 +39,12 @@ element.__base.alignment = (horizontal, vertical) =>
|
||||
else
|
||||
return @getAlignment!
|
||||
|
||||
-- why is this bit here? Oo
|
||||
element.__base.margin = (m) =>
|
||||
if m
|
||||
return @setMargin m
|
||||
else
|
||||
return @getMargin!
|
||||
|
||||
--oldinit = element.__init
|
||||
--
|
||||
--element.__init = (...) ->
|
||||
-- object = oldinit ...
|
||||
-- value = object.margin
|
||||
--
|
||||
-- object.margin = setmetatable {:value}, {
|
||||
-- __call: (...) ->
|
||||
-- print ...
|
||||
-- }
|
||||
|
||||
element.__base.resize = element.__base.adjustSize
|
||||
|
||||
-- box.__base.background -- can't be done!
|
||||
|
Loading…
Reference in New Issue
Block a user