This commit is contained in:
Josh
2018-06-03 13:49:35 -05:00
parent fee54d9d99
commit b896da0e44
12 changed files with 152 additions and 63 deletions

2
API.md
View File

@@ -32,7 +32,7 @@ Vector2D getAbsoluteSize() -- Always returns a Vector2D with the v
Methods:
```lua
Color getBackgroundColor()
Color getBackgroundColor()
Color getBorderColor()
number getCornerRounding()
number getBackgroundTransparency()

View File

@@ -1,9 +1,11 @@
love.filesystem.setRequirePath(love.filesystem.getRequirePath() .. ";JUI/?.lua")
return {
UIContainer = require("lib.classes.UIContainer"),
JUIScene = require("lib.classes.JUIScene"),
Frame = require("lib.classes.Frame"),
TextBox = require("lib.classes.TextBox"),
Label = require("lib.classes.Label"),
ImageLabel = require("lib.classes.ImageLabel"),
-- Datatypes
Vector2D = require("lib.datatypes.Vector2D"),

View File

@@ -1,12 +0,0 @@
local DataType = require("classes/DataType")
local RGBColor = require("classes/RGBColor")
local ColoredText = DataType:subclass("ColoredText")
function ColoredText:init(...)
local args = {...}
self.data = args
end
return ColoredText

View File

@@ -1,4 +0,0 @@
local UIRect = require("classes/UIRect")
local Image = UIRect:subclass("Image")

View File

@@ -0,0 +1,17 @@
local UIRect = require("classes/UIRect")
local ImageLabel = UIRect:subclass("ImageLabel")
function ImageLabel:init()
self.image = nil
end
function ImageLabel:getImage()
return self.image
end
function ImageLabel:setImage(image)
self.image = image
end
return ImageLabel

38
lib/classes/JUIScene.lua Normal file
View File

@@ -0,0 +1,38 @@
local UIBase = require("lib.classes.UIBase")
local Dimension = require("lib.datatypes.Dimension")
local Vector2D = require("lib.datatypes.Vector2D")
--[[
JUIScene class
Inherits UIBase
Internal properties:
Dimension size
Dimension position
Hidden methods:
Public methods:
Vector2D getAbsolutePosition()
Vector2D getAbsoluteSize()
Events:
]]
local JUIScene = UIBase:subclass("JUIScene")
function JUIScene:init()
self.super:init()
self.size = Dimension:new(1, 1)
self.position = Dimension:new(0, 0)
end
function JUIScene:getAbsolutePosition()
return Vector2D:new(0, 0)
end
function JUIScene:getAbsoluteSize()
return Vector2D:new(love.graphics.getWidth(), love.graphics.getHeight())
end
return JUIScene

View File

@@ -1,12 +1,12 @@
local UIRect = require("lib.classes.UIRect")
local RGBColor = require("lib.datatypes.RGBColor")
local TextBox = UIRect:subclass("TextBox")
local Label = UIRect:subclass("Label")
function TextBox:init()
function Label:init()
self.super:init()
self.text = "TextBox"
self.text = "Label"
self.textColor = RGBColor:new(0, 0, 0)
self.textAlignment = "left"
self.textSize = 12
@@ -14,7 +14,7 @@ function TextBox:init()
self.fontFace = nil
end
function TextBox:recalculateInternalFont()
function Label:recalculateInternalFont()
if self.fontFace then
self.font = love.graphics.newFont(self.font, self.textSize)
else
@@ -22,33 +22,33 @@ function TextBox:recalculateInternalFont()
end
end
function TextBox:getText()
function Label:getText()
return self.text
end
function TextBox:getFontFace()
function Label:getFontFace()
return self.fontFace
end
function TextBox:getTextSize()
function Label:getTextSize()
return self.textSize
end
function TextBox:setText(text)
function Label:setText(text)
self.text = text
end
function TextBox:setFontFace(fontface)
function Label:setFontFace(fontface)
self.fontFace = fontface
self:recalculateInternalFont()
end
function TextBox:setTextSize(size)
function Label:setTextSize(size)
self.textSize = (size >= 1) and size or 1
self:recalculateInternalFont()
end
function TextBox:render()
function Label:render()
local absPos = self:getAbsolutePosition()
@@ -64,4 +64,4 @@ function TextBox:render()
self:renderChildren()
end
return TextBox
return Label

View File

@@ -1,7 +1,31 @@
local newclass = require("lib.YACI")
local Dimension = require("lib.datatypes.Dimension")
local Vector2D = require("lib.datatypes.Vector2D")
-- Class --
--[[
UIBase class
Internal properties:
boolean isUIObject
boolean active
table<UIBase> children
UIBase parent
Hidden methods:
renderChildren()
updateChildren(number delta)
addChild(UIBase child)
setParent(UIBase parent)
Public methods:
table<UIBase> getChildren()
UIBase getParent()
render()
update(number delta)
Events:
]]
local UIBase = newclass("UIBase")
function UIBase:init()
@@ -12,7 +36,6 @@ function UIBase:init()
end
-- Hidden methods --
function UIBase:renderChildren()
for _, child in pairs(self.children) do
if child.isUIObject then
@@ -29,7 +52,6 @@ function UIBase:updateChildren(delta)
end
end
-- Shown API methods --
function UIBase:render()
--if not self.active then return end

11
lib/classes/UIButton.lua Normal file
View File

@@ -0,0 +1,11 @@
local UIRect = require("lib.classes.UIRect")
local UIButton = UIRect:subclass("UIButton")
function UIButton:init()
end
return UIButton

View File

@@ -1,26 +0,0 @@
local UIBase = require("lib.classes.UIBase")
local Dimension = require("lib.datatypes.Dimension")
local Vector2D = require("lib.datatypes.Vector2D")
local UIContainer = UIBase:subclass("UIContainer")
function UIContainer:init()
self.super:init()
self.size = Dimension:new(1, 1)
self.position = Dimension:new(0, 0)
end
function UIContainer:getAbsolutePosition()
return Vector2D:new(0, 0)
end
function UIContainer:render()
self.super:render()
self:renderChildren()
end
function UIContainer:getAbsoluteSize()
return Vector2D:new(love.graphics.getWidth(), love.graphics.getHeight())
end
return UIContainer

View File

@@ -4,6 +4,46 @@ local Vector2D = require("lib.datatypes.Vector2D")
local RGBColor = require("lib.datatypes.RGBColor")
local Event = require("lib.classes.Event")
--[[
UIRect class
Inherits UIBase
Internal properties:
Color backgroundColor
Color borderColor
number backgroundTransparency
number borderTransparency
number borderWidth
number cornerRounding
boolean mouseOver
boolean mouseExit
Hidden methods:
Public methods:
Color getBackgroundColor()
Color getBorderColor()
number getBackgroundTransparency()
number getBorderTransparency()
number getBorderWidth()
number getCornerRounding()
Dimension getPosition()
Dimension getSize()
boolean isMouseInside()
setBackgroundColor(Color bg)
setBorderColor(Color border)
setBackgroundTransparency(number alpha)
setBorderTransparency(number alpha)
setCornerRounding(number amount)
setPosition(Dimension pos)
setSize(Dimension size)
Events:
mouseEnter()
mouseExit()
]]
local UIRect = UIBase:subclass("UIRect")
function UIRect:init()
@@ -16,8 +56,9 @@ function UIRect:init()
self.cornerRounding = 1
self.size = Dimension:new(0.2, 0.12)
self.position = Dimension:new(0, 0)
self.mouseOver = false
-- events
self.mouseEnter = Event:new()
self.mouseExit = Event:new()
end

View File

@@ -7,14 +7,14 @@ local JUI = require("JUIlib")
local bigboy = JUI.Dimension:new(0.3, 0.2)
local mainmenu = JUI.UIContainer:fromFatboy()
local mainmenu = JUI.JUIScene:fromFatboy()
local background = JUI.Frame:new()
background:setSize(bigboy)
background:setPosition(bigboy)
background:setCornerRounding(0)
local emptyColor = JUI.TextBox:new()
local emptyColor = JUI.Label:new()
emptyColor:setSize(JUI.Dimension:new(0.3, 0.1))
emptyColor:setPosition(JUI.Dimension:new(0.2, 0.8))
emptyColor:setBackgroundColor(JUI.RGBColor:new(200, 69, 128))