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.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!
|
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)
|
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)
|
--c:move(100)
|
||||||
|
@ -180,19 +180,19 @@ do
|
|||||||
self.y = self.parent.y
|
self.y = self.parent.y
|
||||||
local _exp_0 = self.horizontal
|
local _exp_0 = self.horizontal
|
||||||
if "left" == _exp_0 then
|
if "left" == _exp_0 then
|
||||||
self.x = self.x + self.margin
|
self.x = self.x + self.spacing
|
||||||
elseif "center" == _exp_0 then
|
elseif "center" == _exp_0 then
|
||||||
self.x = self.x + ((self.parent.w - self.w) / 2)
|
self.x = self.x + ((self.parent.w - self.w) / 2)
|
||||||
elseif "right" == _exp_0 then
|
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
|
end
|
||||||
local _exp_1 = self.vertical
|
local _exp_1 = self.vertical
|
||||||
if "top" == _exp_1 then
|
if "top" == _exp_1 then
|
||||||
self.y = self.y + self.margin
|
self.y = self.y + self.spacing
|
||||||
elseif "center" == _exp_1 then
|
elseif "center" == _exp_1 then
|
||||||
self.y = self.y + ((self.parent.h - self.h) / 2)
|
self.y = self.y + ((self.parent.h - self.h) / 2)
|
||||||
elseif "bottom" == _exp_1 then
|
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
|
end
|
||||||
if toPixel then
|
if toPixel then
|
||||||
self.x = floor(self.x)
|
self.x = floor(self.x)
|
||||||
@ -222,19 +222,19 @@ do
|
|||||||
getAlignment = function(self)
|
getAlignment = function(self)
|
||||||
return self.horizontal, self.vertical
|
return self.horizontal, self.vertical
|
||||||
end,
|
end,
|
||||||
setMargin = function(self, margin)
|
setMargin = function(self, spacing)
|
||||||
self.margin = margin
|
self.spacing = spacing
|
||||||
self:align()
|
self:align()
|
||||||
return self
|
return self
|
||||||
end,
|
end,
|
||||||
getMargin = function(self)
|
getMargin = function(self)
|
||||||
return self.margin
|
return self.spacing
|
||||||
end,
|
end,
|
||||||
fill = function(self)
|
fill = function(self)
|
||||||
self.x = self.parent.x + self.margin
|
self.x = self.parent.x + self.spacing
|
||||||
self.y = self.parent.y + self.margin
|
self.y = self.parent.y + self.spacing
|
||||||
self.w = self.parent.w - self.margin * 2
|
self.w = self.parent.w - self.spacing * 2
|
||||||
self.h = self.parent.h - self.margin * 2
|
self.h = self.parent.h - self.spacing * 2
|
||||||
end,
|
end,
|
||||||
delete = function(self)
|
delete = function(self)
|
||||||
for k, v in ipairs(self.child) do
|
for k, v in ipairs(self.child) do
|
||||||
@ -252,7 +252,7 @@ do
|
|||||||
self.child = { }
|
self.child = { }
|
||||||
self.w = 0
|
self.w = 0
|
||||||
self.h = 0
|
self.h = 0
|
||||||
self.margin = 0
|
self.spacing = 0
|
||||||
if parent then
|
if parent then
|
||||||
self.x = parent.x
|
self.x = parent.x
|
||||||
self.y = parent.y
|
self.y = parent.y
|
||||||
|
@ -35,13 +35,13 @@ do
|
|||||||
if "center" == _exp_0 then
|
if "center" == _exp_0 then
|
||||||
self.x = self.x - ((w - self.w) / 2)
|
self.x = self.x - ((w - self.w) / 2)
|
||||||
elseif "right" == _exp_0 then
|
elseif "right" == _exp_0 then
|
||||||
self.x = self.x - (w - self.w - self.margin)
|
self.x = self.x - (w - self.w - self.spacing)
|
||||||
end
|
end
|
||||||
local _exp_1 = self.vertical
|
local _exp_1 = self.vertical
|
||||||
if "center" == _exp_1 then
|
if "center" == _exp_1 then
|
||||||
self.y = self.y - ((h - self.h) / 2)
|
self.y = self.y - ((h - self.h) / 2)
|
||||||
elseif "bottom" == _exp_1 then
|
elseif "bottom" == _exp_1 then
|
||||||
self.y = self.y - (h - self.h - self.margin)
|
self.y = self.y - (h - self.h - self.spacing)
|
||||||
end
|
end
|
||||||
self.w = w
|
self.w = w
|
||||||
self.h = h
|
self.h = h
|
||||||
|
@ -180,19 +180,19 @@ do
|
|||||||
self.y = self.parent.y
|
self.y = self.parent.y
|
||||||
local _exp_0 = self.horizontal
|
local _exp_0 = self.horizontal
|
||||||
if "left" == _exp_0 then
|
if "left" == _exp_0 then
|
||||||
self.x = self.x + self.margin
|
self.x = self.x + self.spacing
|
||||||
elseif "center" == _exp_0 then
|
elseif "center" == _exp_0 then
|
||||||
self.x = self.x + ((self.parent.w - self.w) / 2)
|
self.x = self.x + ((self.parent.w - self.w) / 2)
|
||||||
elseif "right" == _exp_0 then
|
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
|
end
|
||||||
local _exp_1 = self.vertical
|
local _exp_1 = self.vertical
|
||||||
if "top" == _exp_1 then
|
if "top" == _exp_1 then
|
||||||
self.y = self.y + self.margin
|
self.y = self.y + self.spacing
|
||||||
elseif "center" == _exp_1 then
|
elseif "center" == _exp_1 then
|
||||||
self.y = self.y + ((self.parent.h - self.h) / 2)
|
self.y = self.y + ((self.parent.h - self.h) / 2)
|
||||||
elseif "bottom" == _exp_1 then
|
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
|
end
|
||||||
if toPixel then
|
if toPixel then
|
||||||
self.x = floor(self.x)
|
self.x = floor(self.x)
|
||||||
@ -222,19 +222,19 @@ do
|
|||||||
getAlignment = function(self)
|
getAlignment = function(self)
|
||||||
return self.horizontal, self.vertical
|
return self.horizontal, self.vertical
|
||||||
end,
|
end,
|
||||||
setMargin = function(self, margin)
|
setMargin = function(self, spacing)
|
||||||
self.margin = margin
|
self.spacing = spacing
|
||||||
self:align()
|
self:align()
|
||||||
return self
|
return self
|
||||||
end,
|
end,
|
||||||
getMargin = function(self)
|
getMargin = function(self)
|
||||||
return self.margin
|
return self.spacing
|
||||||
end,
|
end,
|
||||||
fill = function(self)
|
fill = function(self)
|
||||||
self.x = self.parent.x + self.margin
|
self.x = self.parent.x + self.spacing
|
||||||
self.y = self.parent.y + self.margin
|
self.y = self.parent.y + self.spacing
|
||||||
self.w = self.parent.w - self.margin * 2
|
self.w = self.parent.w - self.spacing * 2
|
||||||
self.h = self.parent.h - self.margin * 2
|
self.h = self.parent.h - self.spacing * 2
|
||||||
end,
|
end,
|
||||||
delete = function(self)
|
delete = function(self)
|
||||||
for k, v in ipairs(self.child) do
|
for k, v in ipairs(self.child) do
|
||||||
@ -252,7 +252,7 @@ do
|
|||||||
self.child = { }
|
self.child = { }
|
||||||
self.w = 0
|
self.w = 0
|
||||||
self.h = 0
|
self.h = 0
|
||||||
self.margin = 0
|
self.spacing = 0
|
||||||
if parent then
|
if parent then
|
||||||
self.x = parent.x
|
self.x = parent.x
|
||||||
self.y = parent.y
|
self.y = parent.y
|
||||||
|
@ -35,13 +35,13 @@ do
|
|||||||
if "center" == _exp_0 then
|
if "center" == _exp_0 then
|
||||||
self.x = self.x - ((w - self.w) / 2)
|
self.x = self.x - ((w - self.w) / 2)
|
||||||
elseif "right" == _exp_0 then
|
elseif "right" == _exp_0 then
|
||||||
self.x = self.x - (w - self.w - self.margin)
|
self.x = self.x - (w - self.w - self.spacing)
|
||||||
end
|
end
|
||||||
local _exp_1 = self.vertical
|
local _exp_1 = self.vertical
|
||||||
if "center" == _exp_1 then
|
if "center" == _exp_1 then
|
||||||
self.y = self.y - ((h - self.h) / 2)
|
self.y = self.y - ((h - self.h) / 2)
|
||||||
elseif "bottom" == _exp_1 then
|
elseif "bottom" == _exp_1 then
|
||||||
self.y = self.y - (h - self.h - self.margin)
|
self.y = self.y - (h - self.h - self.spacing)
|
||||||
end
|
end
|
||||||
self.w = w
|
self.w = w
|
||||||
self.h = h
|
self.h = h
|
||||||
|
@ -11,7 +11,7 @@ class element
|
|||||||
@w = 0
|
@w = 0
|
||||||
@h = 0
|
@h = 0
|
||||||
|
|
||||||
@margin = 0
|
@spacing = 0
|
||||||
|
|
||||||
if parent
|
if parent
|
||||||
@x = parent.x
|
@x = parent.x
|
||||||
@ -205,19 +205,19 @@ class element
|
|||||||
|
|
||||||
switch @horizontal
|
switch @horizontal
|
||||||
when "left"
|
when "left"
|
||||||
@x += @margin
|
@x += @spacing
|
||||||
when "center"
|
when "center"
|
||||||
@x += (@parent.w - @w)/2
|
@x += (@parent.w - @w)/2
|
||||||
when "right"
|
when "right"
|
||||||
@x += @parent.w - @w - @margin
|
@x += @parent.w - @w - @spacing
|
||||||
|
|
||||||
switch @vertical
|
switch @vertical
|
||||||
when "top"
|
when "top"
|
||||||
@y += @margin
|
@y += @spacing
|
||||||
when "center"
|
when "center"
|
||||||
@y += (@parent.h - @h)/2
|
@y += (@parent.h - @h)/2
|
||||||
when "bottom"
|
when "bottom"
|
||||||
@y += @parent.h - @h - @margin
|
@y += @parent.h - @h - @spacing
|
||||||
|
|
||||||
if toPixel
|
if toPixel
|
||||||
@x = floor @x
|
@x = floor @x
|
||||||
@ -246,19 +246,19 @@ class element
|
|||||||
getAlignment: =>
|
getAlignment: =>
|
||||||
return @horizontal, @vertical
|
return @horizontal, @vertical
|
||||||
|
|
||||||
setMargin: (margin) =>
|
setMargin: (spacing) =>
|
||||||
@margin = margin
|
@spacing = spacing
|
||||||
@align!
|
@align!
|
||||||
return @
|
return @
|
||||||
|
|
||||||
getMargin: =>
|
getMargin: =>
|
||||||
return @margin
|
return @spacing
|
||||||
|
|
||||||
fill: =>
|
fill: =>
|
||||||
@x = @parent.x + @margin
|
@x = @parent.x + @spacing
|
||||||
@y = @parent.y + @margin
|
@y = @parent.y + @spacing
|
||||||
@w = @parent.w - @margin*2
|
@w = @parent.w - @spacing*2
|
||||||
@h = @parent.h - @margin*2
|
@h = @parent.h - @spacing*2
|
||||||
|
|
||||||
delete: =>
|
delete: =>
|
||||||
for k,v in ipairs @child
|
for k,v in ipairs @child
|
||||||
|
@ -47,13 +47,13 @@ class text extends element
|
|||||||
when "center"
|
when "center"
|
||||||
@x -= (w - @w)/2
|
@x -= (w - @w)/2
|
||||||
when "right"
|
when "right"
|
||||||
@x -= w - @w - @margin
|
@x -= w - @w - @spacing
|
||||||
|
|
||||||
switch @vertical
|
switch @vertical
|
||||||
when "center"
|
when "center"
|
||||||
@y -= (h - @h)/2
|
@y -= (h - @h)/2
|
||||||
when "bottom"
|
when "bottom"
|
||||||
@y -= h - @h - @margin
|
@y -= h - @h - @spacing
|
||||||
|
|
||||||
@w = w
|
@w = w
|
||||||
@h = h
|
@h = h
|
||||||
|
@ -39,24 +39,12 @@ element.__base.alignment = (horizontal, vertical) =>
|
|||||||
else
|
else
|
||||||
return @getAlignment!
|
return @getAlignment!
|
||||||
|
|
||||||
-- why is this bit here? Oo
|
|
||||||
element.__base.margin = (m) =>
|
element.__base.margin = (m) =>
|
||||||
if m
|
if m
|
||||||
return @setMargin m
|
return @setMargin m
|
||||||
else
|
else
|
||||||
return @getMargin!
|
return @getMargin!
|
||||||
|
|
||||||
--oldinit = element.__init
|
|
||||||
--
|
|
||||||
--element.__init = (...) ->
|
|
||||||
-- object = oldinit ...
|
|
||||||
-- value = object.margin
|
|
||||||
--
|
|
||||||
-- object.margin = setmetatable {:value}, {
|
|
||||||
-- __call: (...) ->
|
|
||||||
-- print ...
|
|
||||||
-- }
|
|
||||||
|
|
||||||
element.__base.resize = element.__base.adjustSize
|
element.__base.resize = element.__base.adjustSize
|
||||||
|
|
||||||
-- box.__base.background -- can't be done!
|
-- box.__base.background -- can't be done!
|
||||||
|
Loading…
Reference in New Issue
Block a user