#include "ui_defs.lua" function Ui.GetTextSize(str) if not str then return 0, 0 end local text = str if string.sub(str, 1,4) == "loc@" then text = GetTranslatedStringByKey(str) end return UiGetTextSize(text) end function Ui.Text(obj) local text = Ui.Object:new { text = "text", color = 0xFFFFFFFF, font = { "regular.ttf", 22 }, wrapWidth = nil, underline = false, linesAlignment = Ui.TextAlignment.Left, fixedSize = false, outlineColor = { 0, 0, 0, 0}, outlineThickness = 0, draw = function(self) UiFrameOccupy(self.w, self.h) UiFrameSkipItem(true) UiPush() UiColor(hexrgb(self.color)) self.outlineColor[5] = self.outlineThickness UiTextOutline(unpack(self.outlineColor)) UiTextUnderline(self.underline) UiTextAlignment(self.linesAlignment) local scale = 1.23 local name, size = unpack(self.font) UiFont(name, size * scale) if self.wrapWidth then UiWordWrap(self.wrapWidth) end if self.fixedSize then UiTextUniformHeight(true) end local linkId = nil self.w, self.h, _, _, linkId = UiText(self.text) if linkId then self:onLinkClicked(linkId) end UiPop() UiFrameSkipItem(false) end, -- NOTE: Almost the same as in the drawing function, need to somehow generalize getSize = function(self) UiPush() UiTextUnderline(self.underline) UiTextAlignment(self.linesAlignment) local scale = 1.23 local name, size = unpack(self.font) UiFont(name, size * scale) if self.wrapWidth then UiWordWrap(self.wrapWidth) end if self.fixedSize then UiTextUniformHeight(true) end self.w, self.h = Ui.GetTextSize(self.text) UiPop() return self.w, self.h end, onLinkClicked = function(self) end, } return text:new(obj) end