mirror of
https://github.com/TangentFoxy/Pop.Box.git
synced 2024-12-15 12:44:20 +00:00
mid-redesign
This commit is contained in:
parent
486f307274
commit
723997fe7a
@ -16,7 +16,7 @@ local pop = require "pop"
|
|||||||
local box = pop.box()
|
local box = pop.box()
|
||||||
```
|
```
|
||||||
|
|
||||||
* `box` is a box for containing things.
|
* `box` is a box (class) for containing things.
|
||||||
* `text` is a class for handling text.
|
* `text` is a class for handling text.
|
||||||
* Nothing else! Is alpha, just started.
|
* Nothing else! Is alpha, just started.
|
||||||
|
|
||||||
|
8
main.lua
8
main.lua
@ -1,4 +1,4 @@
|
|||||||
local pop = require "pop"
|
local pop = require "pop" --TODO tell user that pop must be required with SLASHES
|
||||||
|
|
||||||
function love.load()
|
function love.load()
|
||||||
pop.box() -- returns the box element
|
pop.box() -- returns the box element
|
||||||
@ -16,3 +16,9 @@ end
|
|||||||
function love.mousereleased(button, x, y)
|
function love.mousereleased(button, x, y)
|
||||||
pop.mousereleased(button, x, y)
|
pop.mousereleased(button, x, y)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function love.keypressed(key)
|
||||||
|
if key == "escape" then
|
||||||
|
love.event.quit()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
@ -9,11 +9,11 @@ function box:initialize(pop, parent)
|
|||||||
self.sizeControl = "specified"
|
self.sizeControl = "specified"
|
||||||
self.outerWidth = 300
|
self.outerWidth = 300
|
||||||
self.outerHeight = 250
|
self.outerHeight = 250
|
||||||
self.innerWidth = self.outerWidth - self.style.borderSize
|
self.innerWidth = self.outerWidth - self.skin.style.borderSize
|
||||||
self.innerHeight = self.outerHeight - self.style.borderSize
|
self.innerHeight = self.outerHeight - self.skin.style.borderSize
|
||||||
end
|
end
|
||||||
|
|
||||||
function box:update(pop)
|
function box:update()
|
||||||
--
|
--
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1,15 +1,14 @@
|
|||||||
local path = string.sub(..., 1, string.len(...) - string.len(".elements.element"))
|
local path = string.sub(..., 1, string.len(...) - string.len(".elements.element"))
|
||||||
local class = require(path .. ".lib.middleclass")
|
local class = require(path .. ".lib.middleclass")
|
||||||
|
--TODO determine if these requires can break because of slashes / subdirectories
|
||||||
|
|
||||||
local element = class("pop.element") --NOTE are periods allowed in middleclass class names?
|
local element = class("pop.element")
|
||||||
|
|
||||||
--TODO setting widths and heights need to call update()
|
|
||||||
--TODO setters and getters for just width/height, aliases for outerWidth/outerHeight
|
|
||||||
|
|
||||||
function element:initialize(pop, parent)
|
function element:initialize(pop, parent)
|
||||||
self.x = 0
|
self.ax = 0 -- absolute locations
|
||||||
self.y = 0
|
self.ay = 0
|
||||||
self.alignPoint = 1 -- 1 to 9, how aligned relative to x/y, see docs
|
self.rx = 0 -- relative to parent locations
|
||||||
|
self.ry = 0
|
||||||
|
|
||||||
self.sizeControl = "fromInner" -- fromInner, fromOuter, specified
|
self.sizeControl = "fromInner" -- fromInner, fromOuter, specified
|
||||||
self.outerWidth = 0
|
self.outerWidth = 0
|
||||||
@ -17,7 +16,7 @@ function element:initialize(pop, parent)
|
|||||||
self.innerWidth = 0
|
self.innerWidth = 0
|
||||||
self.innerHeight = 0
|
self.innerHeight = 0
|
||||||
|
|
||||||
self.style = pop.style
|
self.skin = pop.skins[pop.currentSkin]
|
||||||
self.visible = true
|
self.visible = true
|
||||||
|
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
@ -26,11 +25,20 @@ function element:initialize(pop, parent)
|
|||||||
parent.child[self] = self -- add ourselves to the parent's children
|
parent.child[self] = self -- add ourselves to the parent's children
|
||||||
end
|
end
|
||||||
|
|
||||||
function element:getAlignPoint()
|
--TODO completely redefine interface based on what we should expect users to do
|
||||||
return self.alignPoint
|
-- REMEMBER the goal is minimal effort on their part
|
||||||
|
-- THEREFORE, we should reduce this interface, they should rely on skins for borderSize (and thus, differences in outer/inner sizes)
|
||||||
|
-- all calls should be based on sizing the outside, and update() should update inners (including children!) based on outers
|
||||||
|
|
||||||
|
function element:getSize()
|
||||||
|
return self.outerWidth, self.outerHeight
|
||||||
end
|
end
|
||||||
function element:setAlignPoint(point)
|
function element:setSize(width, height)
|
||||||
self.alignPoint = point
|
assert(width > 0, "width must be above 0")
|
||||||
|
assert(height > 0, "height must be above 0")
|
||||||
|
self.outerWidth = width
|
||||||
|
self.outerHeight = height
|
||||||
|
self.sizeControl = "specified"
|
||||||
end
|
end
|
||||||
|
|
||||||
function element:getOuterWidth()
|
function element:getOuterWidth()
|
||||||
@ -39,6 +47,8 @@ end
|
|||||||
function element:setOuterWidth(width)
|
function element:setOuterWidth(width)
|
||||||
assert(width > 0, "width must be above 0")
|
assert(width > 0, "width must be above 0")
|
||||||
self.outerWidth = width
|
self.outerWidth = width
|
||||||
|
self.sizeControl = "specified"
|
||||||
|
--TODO needs to update() to update inner size based on borderSize ???
|
||||||
end
|
end
|
||||||
|
|
||||||
function element:getOuterHeight()
|
function element:getOuterHeight()
|
||||||
@ -47,6 +57,8 @@ end
|
|||||||
function element:setOuterHeight(height)
|
function element:setOuterHeight(height)
|
||||||
assert(height > 0, "height must be above 0")
|
assert(height > 0, "height must be above 0")
|
||||||
self.outerHeight = height
|
self.outerHeight = height
|
||||||
|
self.sizeControl = "specified"
|
||||||
|
--TODO needs to update() to update inner size based on borderSize ???
|
||||||
end
|
end
|
||||||
|
|
||||||
function element:getInnerWidth()
|
function element:getInnerWidth()
|
||||||
@ -55,6 +67,8 @@ end
|
|||||||
function element:setInnerWidth(width)
|
function element:setInnerWidth(width)
|
||||||
assert(width > 0, "width must be above 0")
|
assert(width > 0, "width must be above 0")
|
||||||
self.innerWidth = width
|
self.innerWidth = width
|
||||||
|
self.sizeControl = "specified"
|
||||||
|
--TODO needs to update outerWidth ???
|
||||||
end
|
end
|
||||||
|
|
||||||
function element:getInnerHeight()
|
function element:getInnerHeight()
|
||||||
@ -63,6 +77,8 @@ end
|
|||||||
function element:setInnerHeight(height)
|
function element:setInnerHeight(height)
|
||||||
assert(height > 0, "height must be above 0")
|
assert(height > 0, "height must be above 0")
|
||||||
self.innerHeight = height
|
self.innerHeight = height
|
||||||
|
self.sizeControl = "specified"
|
||||||
|
--TODO needs to update outerHeight ??
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[ TODO determine how to write these better (consistency motherfucker)
|
--[[ TODO determine how to write these better (consistency motherfucker)
|
||||||
|
44
pop/init.lua
44
pop/init.lua
@ -1,12 +1,23 @@
|
|||||||
|
local lf = love.filesystem
|
||||||
|
local lg = love.graphics
|
||||||
|
|
||||||
local pop = {}
|
local pop = {}
|
||||||
local path = ... -- this only works as long as the require() does't specify init.lua..which it shouldn't
|
local path = ... --NOTE Pop.Box must be required as its directory name (w SLASHES)!
|
||||||
|
|
||||||
-- elements are local
|
-- elements are local
|
||||||
|
--TODO require these how skins are required
|
||||||
local box = require(path .. ".elements.box")
|
local box = require(path .. ".elements.box")
|
||||||
local text = require(path .. ".elements.text")
|
local text = require(path .. ".elements.text")
|
||||||
|
|
||||||
-- style defines how elements are drawn
|
-- skins define how elements are drawn
|
||||||
pop.style = require(path .. ".skins.clear")
|
pop.skins = {}
|
||||||
|
local skins = lf.getDirectoryItems(path .. "/skins") --NOTE Pop.Box must be required with SLASHES!
|
||||||
|
for _, v in ipairs(skins) do
|
||||||
|
local name = v:sub(1,-5)
|
||||||
|
pop.skins[name] = require(path .. "/skins/" .. name)
|
||||||
|
pop.skins[name].name = name
|
||||||
|
end
|
||||||
|
pop.currentSkin = "clearspace" --default skin
|
||||||
|
|
||||||
-- everything has one parent element (initialized at the end)
|
-- everything has one parent element (initialized at the end)
|
||||||
pop.parentElement = false
|
pop.parentElement = false
|
||||||
@ -30,34 +41,41 @@ function pop.create(elementType, parent, ...)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- pretty wrappers to call pop.element() instead of pop.create("element")
|
-- pretty wrappers to call pop.element() instead of pop.create("element")
|
||||||
pop.box = function() return pop.create("box", ...) end
|
pop.box = function(...) return pop.create("box", ...) end
|
||||||
pop.text = function() return pop.create("text", ...) end
|
pop.text = function(...) return pop.create("text", ...) end
|
||||||
|
|
||||||
function pop.draw(element)
|
function pop.draw(element)
|
||||||
if not element then
|
if not element then
|
||||||
element = pop.parentElement
|
element = pop.parentElement
|
||||||
end
|
end
|
||||||
|
|
||||||
for _, childElements in pairs(element.child) do
|
|
||||||
--pop.draw(childElements, element.x, element.y)
|
|
||||||
pop.draw(childElements)
|
|
||||||
end
|
|
||||||
|
|
||||||
element:draw()
|
element:draw()
|
||||||
|
|
||||||
|
for _, childElement in pairs(element.child) do
|
||||||
|
--pop.draw(childElement, element.x, element.y)
|
||||||
|
pop.draw(childElement)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- TODO decide if we should track mouse movement
|
-- TODO decide if we should track mouse movement
|
||||||
|
|
||||||
|
function pop.onMousePress(button, x, y) end
|
||||||
|
function pop.onMouseRelease(button, x, y) end
|
||||||
|
|
||||||
function pop.mousepressed(button, x, y)
|
function pop.mousepressed(button, x, y)
|
||||||
--
|
--TODO find which element it belongs to and if that element has a callback set,
|
||||||
|
-- if it does, use that, else, use the global callback (defined above..as nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
function pop.mousereleased(button, x, y)
|
function pop.mousereleased(button, x, y)
|
||||||
--
|
--TODO find which element it belongs to and if that element has a callback set,
|
||||||
|
-- if it does, use that, else, use the global callback (defined above..as nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- initialize the top element
|
-- initialize the top element
|
||||||
pop.parentElement = box(pop, nil) -- nil because it has no parent
|
pop.parentElement = box(pop, {child={}}) -- dummy object because it has no parent
|
||||||
|
--pop.parentElement:setSizeControl("specified") -- make it not try to update itself (TODO or based on outro, and custom code to check top parent against screen size)
|
||||||
|
--pop.parentElement:setSize(lg.getWidth(), lg.getHeight()) -- fill window size
|
||||||
--pop.parentElement:setVisible(false) -- uneeded since its clear...
|
--pop.parentElement:setVisible(false) -- uneeded since its clear...
|
||||||
|
|
||||||
return pop
|
return pop
|
||||||
|
10
pop/skins/clearspace.lua
Normal file
10
pop/skins/clearspace.lua
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
local skin = {}
|
||||||
|
|
||||||
|
skin.style = {
|
||||||
|
background = false, -- color table, image, or false
|
||||||
|
foreground = {0,0,0,1}, -- color table
|
||||||
|
borderSize = 2, -- integer (minimum 0)
|
||||||
|
borderStyle = false -- color table, image, or false
|
||||||
|
}
|
||||||
|
|
||||||
|
return skin
|
Loading…
Reference in New Issue
Block a user