From acf39724014870f0dd11444d32bf9a3bb5ebdb81 Mon Sep 17 00:00:00 2001 From: Paul Liverman III Date: Wed, 4 May 2016 14:40:15 -0700 Subject: [PATCH] wip #42 (window element needs to be converted!) --- src/pop/elements/box.moon | 29 ++++++++++++++++++++++++----- src/pop/elements/element.moon | 18 +++++++++++++----- src/pop/elements/text.moon | 17 +++++++++++++---- src/pop/elements/window.moon | 3 +++ 4 files changed, 53 insertions(+), 14 deletions(-) diff --git a/src/pop/elements/box.moon b/src/pop/elements/box.moon index a67ad8f..cdb592f 100644 --- a/src/pop/elements/box.moon +++ b/src/pop/elements/box.moon @@ -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 diff --git a/src/pop/elements/element.moon b/src/pop/elements/element.moon index a3c08a2..81ce210 100644 --- a/src/pop/elements/element.moon +++ b/src/pop/elements/element.moon @@ -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! diff --git a/src/pop/elements/text.moon b/src/pop/elements/text.moon index 28e60ff..affcee1 100644 --- a/src/pop/elements/text.moon +++ b/src/pop/elements/text.moon @@ -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 diff --git a/src/pop/elements/window.moon b/src/pop/elements/window.moon index f6323e2..b26e87c 100644 --- a/src/pop/elements/window.moon +++ b/src/pop/elements/window.moon @@ -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