#include "ui_defs.lua" function Ui.Colorf(r,g,b,a) return { r = r, g = g, b = b, a = a or 1, set = function(self) UiColor(self.r,self.b,self.g,self.a) end } end function Ui.Rect(obj) local rect = Ui.Object:new { id = "rect", w = 40, h = 40, color = {1,0,0}, cornerRadius = 0, draw = function(self) UiPush() if type(self.color) == "table" then UiColor(unpack(self.color)) else UiColor(hexrgb(self.color)) end if self.cornerRadius == 0 then UiRect(self.w,self.h) else UiRoundedRect(self.w, self.h, self.cornerRadius) end UiPop() end } return rect:new(obj) end function Ui.RectOutline(obj) local outline = Ui.Object:new { id = "rectOutline", w = 40, h = 40, color = {1,0,0}, thickness = 1, cornerRadius = 0, draw = function(self) UiPush() if type(self.color) == "table" then UiColor(unpack(self.color)) else UiColor(hexrgb(self.color)) end if self.cornerRadius == 0 then UiRectOutline(self.w,self.h, self.thickness) else UiRoundedRectOutline(self.w, self.h, self.cornerRadius, self.thickness) end UiPop() end } return outline:new(obj) end function Ui.TitleBar(obj) local btn = function(obj) local button = Ui.Rect{ onClick = function(self) end, onMouseDown = function(self) UiColorFilter(0.5,0.5,0.5) end, } return button:new(obj) end local titleBar = Ui.Frame{ color = Ui.Style.Color.White, w = 1000, h = 40, Ui.Frame { hAlign = Ui.ContentLayout.Horizontal.Center, vAlign = Ui.ContentLayout.Vertical.Top, paddingLeft = 20, paddingTop = 10, color = Ui.Style.Color.White, Ui.Text{ text = obj.title, color = Ui.Style.Color.Black, } }, Ui.HorizontalLayout{ hAlign = Ui.ContentLayout.Horizontal.Right, vAlign = Ui.ContentLayout.Vertical.Top, btn{ color = Ui.Style.Color.Black, }, btn{ color = Ui.Style.Color.Yellow, }, btn{ color = Ui.Style.Color.Red, onMouseUp = function(self) self:hide() end }, } } return titleBar end function Ui.ImageBox(obj) local imageBox = Ui.Object:new { id = "imagebox", path = "", border = { width = 0, height = 0 }, color = 0xFFFFFFFF, draw = function(self) if type(self.color) == "table" then self.applyColor = function(self) UiColor(unpack(self.color)) end else self.applyColor = function(self) UiColor(hexrgb(self.color)) end end UiPush() self:applyColor() UiImageBox(self.path, self.w, self.h, self.border.width, self.border.height) UiPop() end, onCreate = function(self) end } return imageBox:new(obj) end function Ui.Image(obj) local img = Ui.Object:new { id = "image", color = 0xFFFFFFFF, draw = function(self) UiPush() if self.w ~= 0 and self.h ~= 0 then local iw, ih = UiGetImageSize(self.path) local scaleX, scaleY = self.w / iw, self.h / ih UiScale(scaleX, scaleY) end if type(self.color) == "table" then UiColor(unpack(self.color)) else UiColor(hexrgb(self.color)) end UiImage(self.path) UiPop() end, getSize = function(self) local w, h = UiGetImageSize(self.path) if self.w == 0 or self.h == 0 then return w, h end return self.w, self.h end } return img:new(obj) end function Ui.VSpacer(obj) local spacer = Ui.Object:new { id = "vspacer", draw = function(self) UiTranslate(0,self.h) end } return spacer:new(obj) end