mirror of
https://github.com/TangentFoxy/Pop.Box.git
synced 2024-12-15 12:44:20 +00:00
some trek-based improvements
This commit is contained in:
parent
84fe9f95f5
commit
92da91076e
@ -1,5 +1,7 @@
|
|||||||
local graphics
|
local graphics
|
||||||
graphics = love.graphics
|
graphics = love.graphics
|
||||||
|
local floor
|
||||||
|
floor = math.floor
|
||||||
local element
|
local element
|
||||||
do
|
do
|
||||||
local _class_0
|
local _class_0
|
||||||
@ -13,6 +15,39 @@ do
|
|||||||
graphics.setColor(200, 255, 200, 255)
|
graphics.setColor(200, 255, 200, 255)
|
||||||
return graphics.print("e", self.data.x, self.data.y)
|
return graphics.print("e", self.data.x, self.data.y)
|
||||||
end,
|
end,
|
||||||
|
align = function(self, horizontal, vertical, toPixel)
|
||||||
|
if toPixel == nil then
|
||||||
|
toPixel = true
|
||||||
|
end
|
||||||
|
if not (self.data.align) then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
if horizontal then
|
||||||
|
self.data.horizontal = horizontal
|
||||||
|
end
|
||||||
|
if vertical then
|
||||||
|
self.data.vertical = vertical
|
||||||
|
end
|
||||||
|
self.data.x = self.parent.data.x
|
||||||
|
self.data.y = self.parent.data.y
|
||||||
|
local _exp_0 = self.data.horizontal
|
||||||
|
if "center" == _exp_0 then
|
||||||
|
self.data.x = self.data.x + ((self.parent.data.w - self.data.w) / 2)
|
||||||
|
elseif "right" == _exp_0 then
|
||||||
|
self.data.x = self.data.x + (self.parent.data.w - self.data.w)
|
||||||
|
end
|
||||||
|
local _exp_1 = self.data.vertical
|
||||||
|
if "center" == _exp_1 then
|
||||||
|
self.data.y = self.data.y + ((self.parent.data.h - self.data.h) / 2)
|
||||||
|
elseif "right" == _exp_1 then
|
||||||
|
self.data.y = self.data.y + (self.parent.data.h - self.data.h)
|
||||||
|
end
|
||||||
|
if toPixel then
|
||||||
|
self.data.x = floor(self.data.x)
|
||||||
|
self.data.y = floor(self.data.y)
|
||||||
|
end
|
||||||
|
return self
|
||||||
|
end,
|
||||||
setSize = function(self, w, h)
|
setSize = function(self, w, h)
|
||||||
if w then
|
if w then
|
||||||
self.data.w = w
|
self.data.w = w
|
||||||
@ -47,7 +82,7 @@ do
|
|||||||
data = { }
|
data = { }
|
||||||
end
|
end
|
||||||
self.parent, self.data = parent, data
|
self.parent, self.data = parent, data
|
||||||
if type(self.data ~= "table") then
|
if type(self.data) ~= "table" then
|
||||||
self.data = { }
|
self.data = { }
|
||||||
end
|
end
|
||||||
if not (self.data.parent) then
|
if not (self.data.parent) then
|
||||||
@ -77,7 +112,17 @@ do
|
|||||||
if not (self.data.type) then
|
if not (self.data.type) then
|
||||||
self.data.type = "element"
|
self.data.type = "element"
|
||||||
end
|
end
|
||||||
|
if (self.data.align == nil) and self.parent then
|
||||||
|
self.data.align = true
|
||||||
|
end
|
||||||
|
if not (self.data.vertical) then
|
||||||
|
self.data.vertical = "top"
|
||||||
|
end
|
||||||
|
if not (self.data.horizontal) then
|
||||||
|
self.data.horizontal = "left"
|
||||||
|
end
|
||||||
self.child = { }
|
self.child = { }
|
||||||
|
return self:align()
|
||||||
end,
|
end,
|
||||||
__base = _base_0,
|
__base = _base_0,
|
||||||
__name = "element"
|
__name = "element"
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
--- @license The MIT License (MIT)
|
--- @license The MIT License (MIT)
|
||||||
|
|
||||||
import graphics from love
|
import graphics from love
|
||||||
|
import floor from math
|
||||||
|
|
||||||
class element
|
class element
|
||||||
--- Constructor expects nothing, or a data table describing it.
|
--- Constructor expects nothing, or a data table describing it.
|
||||||
@ -11,7 +12,7 @@ class element
|
|||||||
--- @tparam table data[opt] The data (state) for this element.
|
--- @tparam table data[opt] The data (state) for this element.
|
||||||
--- @treturn element self
|
--- @treturn element self
|
||||||
new: (@parent, @data={}) =>
|
new: (@parent, @data={}) =>
|
||||||
if type @data != "table"
|
if type(@data) != "table"
|
||||||
@data = {}
|
@data = {}
|
||||||
|
|
||||||
@data.parent = false unless @data.parent
|
@data.parent = false unless @data.parent
|
||||||
@ -23,9 +24,14 @@ class element
|
|||||||
@data.update = false if @data.update == nil
|
@data.update = false if @data.update == nil
|
||||||
@data.draw = true if @data.draw == nil
|
@data.draw = true if @data.draw == nil
|
||||||
@data.type = "element" unless @data.type
|
@data.type = "element" unless @data.type
|
||||||
|
@data.align = true if (@data.align == nil) and @parent
|
||||||
|
@data.vertical = "top" unless @data.vertical
|
||||||
|
@data.horizontal = "left" unless @data.horizontal
|
||||||
|
|
||||||
@child = {}
|
@child = {}
|
||||||
|
|
||||||
|
@align!
|
||||||
|
|
||||||
--- Slightly modified from pop.debugDraw
|
--- Slightly modified from pop.debugDraw
|
||||||
--- @see pop.debugDraw
|
--- @see pop.debugDraw
|
||||||
debugDraw: =>
|
debugDraw: =>
|
||||||
@ -37,6 +43,34 @@ class element
|
|||||||
graphics.setColor 200, 255, 200, 255
|
graphics.setColor 200, 255, 200, 255
|
||||||
graphics.print "e", @data.x, @data.y
|
graphics.print "e", @data.x, @data.y
|
||||||
|
|
||||||
|
--- @todo doc me
|
||||||
|
align: (horizontal, vertical, toPixel=true) =>
|
||||||
|
unless @data.align return false
|
||||||
|
|
||||||
|
@data.horizontal = horizontal if horizontal
|
||||||
|
@data.vertical = vertical if vertical
|
||||||
|
|
||||||
|
@data.x = @parent.data.x
|
||||||
|
@data.y = @parent.data.y
|
||||||
|
|
||||||
|
switch @data.horizontal
|
||||||
|
when "center"
|
||||||
|
@data.x += (@parent.data.w - @data.w) / 2
|
||||||
|
when "right"
|
||||||
|
@data.x += @parent.data.w - @data.w
|
||||||
|
|
||||||
|
switch @data.vertical
|
||||||
|
when "center"
|
||||||
|
@data.y += (@parent.data.h - @data.h) / 2
|
||||||
|
when "right"
|
||||||
|
@data.y += @parent.data.h - @data.h
|
||||||
|
|
||||||
|
if toPixel
|
||||||
|
@data.x = floor @data.x
|
||||||
|
@data.y = floor @data.y
|
||||||
|
|
||||||
|
return @
|
||||||
|
|
||||||
--- Sets an element's width/height.
|
--- Sets an element's width/height.
|
||||||
--- @tparam integer w[opt] Width.
|
--- @tparam integer w[opt] Width.
|
||||||
--- @tparam integer h[opt] Height.
|
--- @tparam integer h[opt] Height.
|
||||||
|
@ -15,9 +15,7 @@ do
|
|||||||
end
|
end
|
||||||
self.parent, self.data = parent, data
|
self.parent, self.data = parent, data
|
||||||
_class_0.__parent.__init(self, self.parent, self.data)
|
_class_0.__parent.__init(self, self.parent, self.data)
|
||||||
if self.data.type == "element" then
|
|
||||||
self.data.type = "window"
|
self.data.type = "window"
|
||||||
end
|
|
||||||
end,
|
end,
|
||||||
__base = _base_0,
|
__base = _base_0,
|
||||||
__name = "window",
|
__name = "window",
|
||||||
|
@ -10,7 +10,7 @@ class window extends element
|
|||||||
new: (@parent, @data={}) =>
|
new: (@parent, @data={}) =>
|
||||||
super @parent, @data
|
super @parent, @data
|
||||||
|
|
||||||
@data.type = "window" if @data.type == "element"
|
@data.type = "window"
|
||||||
|
|
||||||
--- @todo if data, do stuff about it
|
--- @todo if data, do stuff about it
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user