diff --git a/docs/elements/box.md b/docs/elements/box.md index e69de29..e2ec304 100644 --- a/docs/elements/box.md +++ b/docs/elements/box.md @@ -0,0 +1,17 @@ +# box + +The box element is a rectangle that has a [supported Drawable][1] as its +background. + +## Methods + +- `setBackground(background)` Using a supported Drawable (see above), set the + background. +- `getBackground()` Returns the background in use. +- `setColor(red, green, blue, alpha)` Sets the background to the specified + color. `alpha` is optional and defaults to `255`. Alternately, pass a table of + color values (ex: `{red, green, blue, alpha}`). +- `getColor()` Returns red, green, blue, and alpha color values of background. + Errors if the background is not a color. + +[1]: ../Drawables.md diff --git a/docs/elements/text.md b/docs/elements/text.md index e69de29..fd68c2b 100644 --- a/docs/elements/text.md +++ b/docs/elements/text.md @@ -0,0 +1,22 @@ +# text + +The text element is plain text in one color. Nothing special. + +(**Note**: Other, more advanced text elements are planned, with support for + things like line-wrapping and custom coloring and formatting of text.) + +## Methods + +- `setSize()` Unlike other elements, a size cannot be set. If this is called, it + will fix the size of the text if it somehow was modified incorrectly. +- `setWidth()` Width cannot be set. If called, will fix the size of the text. +- `setHeight()` Height cannot be set. If called, will fix the size of the text. +- `setText(text)` Sets the text of the element. Will resize element to fit text. + Newlines are supported. Defaults to an empty string. +- `getText()` Returns the text of the element. +- `setFont()` Sets the font to be used on this element. Will resize to fit the + text and font. +- `setColor(red, green, blue, alpha)` Sets color of text. `alpha` is optional + and defaults to `255`. Alternately, pass a table of color values (ex: `{red, + green, blue, alpha}`). +- `getColor()` Returns red, green, blue, and alpha values of color. diff --git a/docs/elements/window.md b/docs/elements/window.md index e69de29..dc443bd 100644 --- a/docs/elements/window.md +++ b/docs/elements/window.md @@ -0,0 +1,4 @@ +# window + +Documentation has not been written yet, as this element is still under heavy +development. diff --git a/src/pop/extensions/streamlined_get_set.moon b/src/pop/extensions/streamlined_get_set.moon index 29213aa..5391baf 100644 --- a/src/pop/extensions/streamlined_get_set.moon +++ b/src/pop/extensions/streamlined_get_set.moon @@ -6,6 +6,7 @@ import sub, len from string path = sub ..., 1, len(...) - len "/extensions/streamlined_get_set" element = require "#{path}/elements/element" +box = require "#{path}/elements/box" text = require "#{path}/elements/text" element.__base.position = (x, y) => @@ -56,10 +57,30 @@ element.__base.margin = (m) => -- print ... -- } +element.__base.resize = element.__base.adjustSize + +-- box.__base.background -- can't be done! + +box.__base.color = (r, g, b, a) => + if r or g or b or a + return @setColor r, g, b, a + else + return @getColor! + text.__base.text = (text) => if text return @setText text else return @getText! --- size probably needs redefine here, elemental size won't fall through...or will it? +text.__base.font = (font) => + if font + return @setFont font + else + return @getFont! + +text.__base.color = (r, g, b, a) => + if r or g or b or a + return @setColor r, g, b, a + else + return @getColor!