mirror of
https://github.com/TangentFoxy/Pop.Box.git
synced 2024-12-15 12:44:20 +00:00
wip #42 (window element needs to be converted!)
This commit is contained in:
parent
01d2b0d171
commit
acf3972401
@ -6,12 +6,31 @@ element = require "#{path}/element"
|
||||
|
||||
class box extends element
|
||||
new: (parent, background=false) =>
|
||||
super parent
|
||||
--TODO clean this up (duplicated code is buggy and annoying!)
|
||||
|
||||
-- if table, check that it is exactly only 3 or 4 numeric values, anything else is data
|
||||
if type(background) == "table"
|
||||
for k,v in pairs background
|
||||
if type(k) != "number"
|
||||
super parent, background -- background is actually a data table!
|
||||
if not background.w
|
||||
@data.w = 20
|
||||
if not background.h
|
||||
@data.h = 20
|
||||
if not @data.background
|
||||
@data.background = false
|
||||
return
|
||||
--if #background < 3 or #background > 4
|
||||
-- super parent, background -- background has too many or too few values to be a color...though this makes NO SENSE
|
||||
-- -- would need to do the same things as above here, but it makes no sense to have this, even though it is possible, it MUST be user error
|
||||
|
||||
@data.background = background
|
||||
super parent
|
||||
if not background.w
|
||||
@data.w = 20
|
||||
if not background.h
|
||||
@data.h = 20
|
||||
if not @data.background
|
||||
@data.background = background -- we can only assume it is userdata (some LOVE object) or a color table (or the false default)
|
||||
|
||||
draw: =>
|
||||
if @data.background
|
||||
|
@ -4,9 +4,9 @@ import insert, remove from table
|
||||
tonumber = tonumber
|
||||
|
||||
class element
|
||||
new: (parent) =>
|
||||
new: (parent, data) =>
|
||||
|
||||
@data = {
|
||||
default = {
|
||||
parent: parent
|
||||
child: {}
|
||||
|
||||
@ -24,9 +24,17 @@ class element
|
||||
move: true
|
||||
}
|
||||
|
||||
if parent
|
||||
@data.x = parent.data.x
|
||||
@data.y = parent.data.y
|
||||
if type(data) == "table"
|
||||
@data = data
|
||||
for k, v in pairs default
|
||||
if type(@data[k]) == "nil"
|
||||
@data[k] = v
|
||||
else
|
||||
@data = default
|
||||
|
||||
if @data.parent
|
||||
@data.x = @data.parent.data.x
|
||||
@data.y = @data.parent.data.y
|
||||
--@data.horizontal = parent.data.horizontal
|
||||
--@data.vertical = parent.data.vertical
|
||||
--@align!
|
||||
|
@ -14,12 +14,21 @@ class text extends element
|
||||
return pop.create("text", parent, ...)
|
||||
|
||||
new: (parent, text="", color={255,255,255,255}) =>
|
||||
if type(text) == "table"
|
||||
super parent, text
|
||||
else
|
||||
super parent
|
||||
|
||||
if not @data.font
|
||||
@data.font = graphics.newFont 14
|
||||
@setText text
|
||||
if not @data.color
|
||||
@data.color = color
|
||||
|
||||
if type(text) == "string"
|
||||
@setText text
|
||||
else
|
||||
@setSize! -- if the user put invalid data in a table, we fix it
|
||||
|
||||
draw: =>
|
||||
graphics.setColor @data.color
|
||||
graphics.setFont @data.font
|
||||
|
@ -35,6 +35,9 @@ class window extends element
|
||||
-- pop_ref = pop
|
||||
|
||||
new: (parent, title="window", tBackground={25, 180, 230, 255}, tColor={255, 255, 255, 255}, wBackground={200, 200, 210, 255}) =>
|
||||
--TODO title could be a data table, rewrite this to accomidate that
|
||||
--NOTE we don't care if the data table already had a head, title, area, or close value, we're wiping them out
|
||||
--NOTE it may be better to move the internal elements of a window out of the data...?
|
||||
super parent
|
||||
|
||||
-- NOTE @data.title having @data.head as its parent might break things horribly
|
||||
|
Loading…
Reference in New Issue
Block a user