diff --git a/elements/element.lua b/elements/element.lua index 274e255..f4c5971 100644 --- a/elements/element.lua +++ b/elements/element.lua @@ -6,7 +6,7 @@ do floor, max = _obj_0.floor, _obj_0.max end local inheritsFromElement -inheritsFromElement = require(tostring((...):sub(1, -19)) .. "/util").inheritsFromElement +inheritsFromElement = require(tostring((...):sub(1, -18)) .. "/util").inheritsFromElement local element do local _class_0 diff --git a/elements/element.moon b/elements/element.moon index 12d11e7..a98edef 100644 --- a/elements/element.moon +++ b/elements/element.moon @@ -5,7 +5,7 @@ import graphics from love import floor, max from math -import inheritsFromElement from require "#{(...)\sub 1, -19}/util" +import inheritsFromElement from require "#{(...)\sub 1, -18}/util" class element --- Constructor expects nothing, or a data table describing it. diff --git a/elements/scrollbox.lua b/elements/scrollbox.lua index e9f86d2..0d2b844 100644 --- a/elements/scrollbox.lua +++ b/elements/scrollbox.lua @@ -5,7 +5,24 @@ local scrollbox do local _class_0 local _parent_0 = element - local _base_0 = { } + local _base_0 = { + draw = function(self) + graphics.setColor(self.data.color) + graphics.rectangle("fill", self.data.x, self.data.y, self.data.w, self.data.h) + return self + end, + setBackground = function(self, r, g, b, a) + if a == nil then + a = 255 + end + if "table" == type(r) then + self.data.color = r + else + self.data.color = r, g, b, a + end + return self + end + } _base_0.__index = _base_0 setmetatable(_base_0, _parent_0.__base) _class_0 = setmetatable({ @@ -18,6 +35,12 @@ do if self.data.type == "element" then self.data.type = "scrollbox" end + self.data.color = { + 0, + 0, + 0, + 255 + } end, __base = _base_0, __name = "scrollbox", diff --git a/elements/scrollbox.moon b/elements/scrollbox.moon index 428b35e..9249f14 100644 --- a/elements/scrollbox.moon +++ b/elements/scrollbox.moon @@ -1,9 +1,43 @@ +local pop import graphics from love element = require "#{(...)\sub 1, -10}/element" class scrollbox extends element - new: (@parent, @data={}) => - super @parent, @data + load: (pop_lib) -> + pop = pop_lib - @data.type = "scrollbox" if @data.type == "element" + new: (@parent, @data={}) => + super @parent, @data + + @data.type = "scrollbox" if @data.type == "element" + @data.color = {255, 255, 255, 255} + @data.background = {0, 0, 0, 255} + + draw: => + graphics.setColor @data.background + graphics.rectangle "fill", @data.x, @data.y, @data.w, @data.h + + --TODO do stuff to set up for drawing + for i=1, #@data.child + pop.draw @data.child[i] + --TODO undo for regular drawing + --TODO return something to cancel drawing children + + return @ + + setColor: (r, g, b, a=255) => + if "table" == type r + @data.color = r + else + @data.color = r, g, b, a + + return @ + + setBackground: (r, g, b, a=255) => + if "table" == type r + @data.background = r + else + @data.background = r, g, b, a + + return @