wip #42 (window element needs to be converted!)

This commit is contained in:
Paul Liverman III 2016-05-04 14:40:15 -07:00
parent 01d2b0d171
commit acf3972401
4 changed files with 53 additions and 14 deletions

View File

@ -6,12 +6,31 @@ element = require "#{path}/element"
class box extends element
new: (parent, background=false) =>
--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
super parent
@data.w = 20
@data.h = 20
@data.background = background
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

View File

@ -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!

View File

@ -14,11 +14,20 @@ class text extends element
return pop.create("text", parent, ...)
new: (parent, text="", color={255,255,255,255}) =>
super parent
if type(text) == "table"
super parent, text
else
super parent
@data.font = graphics.newFont 14
@setText text
@data.color = color
if not @data.font
@data.font = graphics.newFont 14
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

View File

@ -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