You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

139 lines
5.0 KiB

1 year ago
---@type Diesal.GUI
local DiesalGUI = LibStub("DiesalGUI-2.0")
---@type Diesal.Tools
local DiesalTools = LibStub("DiesalTools-2.0")
---@type Diesal.Style
local DiesalStyle = LibStub("DiesalStyle-2.0")
-- ~~| Diesal Upvalues |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
local Colors = DiesalStyle.Colors
local HSL, ShadeColor, TintColor = DiesalTools.HSL, DiesalTools.ShadeColor, DiesalTools.TintColor
-- ~~| Lua Upvalues |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- | Input |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
local Type = "DiesalInput"
local Version = 1
-- | Stylesheets |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
local Stylesheet = {
["frame-background"] = {
type = "texture",
layer = "BACKGROUND",
color = "000000",
alpha = 0.6,
},
["editBox-outline"] = {
type = "outline",
layer = "BORDER",
color = "FFFFFF",
alpha = 0.02,
position = 1,
},
["editBox-inline"] = {
type = "outline",
layer = "BORDER",
color = "000000",
alpha = 0.7,
},
["editBox-hover"] = {
type = "texture",
layer = "HIGHLIGHT",
color = "ffffff",
alpha = 0.05,
position = -1,
},
["editBox-font"] = {
type = "Font",
color = Colors.UI_TEXT,
},
}
-- ~~| Spinner Methods |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
---@class Diesal.GUI.Input.Methods
local methods = {
---@param self Diesal.GUI.Object.Input
1 year ago
["OnAcquire"] = function(self)
self:SetStylesheet(Stylesheet)
self:ApplySettings()
self:Show()
end,
---@param self Diesal.GUI.Object.Input
1 year ago
["OnRelease"] = function(self) end,
---@param self Diesal.GUI.Object.Input
1 year ago
["ApplySettings"] = function(self)
self:SetWidth(self.settings.width)
self:SetHeight(self.settings.height)
end,
---@param self Diesal.GUI.Object.Input
1 year ago
["GetText"] = function(self)
return self.editBox:GetText()
end,
---@param self Diesal.GUI.Object.Input
1 year ago
["SetText"] = function(self, txt)
self.editBox:SetText(txt)
end,
---@param self Diesal.GUI.Object.Input
1 year ago
["SetTextColor"] = function(self, color, alpha)
alpha = alpha or 1
color = { DiesalTools.GetColor(color) }
self.editBox:SetTextColor(color[1], color[2], color[3], alpha)
end,
}
---@class DiesalInput : Diesal.GUI.Object.Input
-- | Constructor |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
local function Constructor()
---@class Diesal.GUI.Object.Input : Diesal.GUI.ObjectBase, Diesal.GUI.Input.Methods
---@field editBox EditBox
1 year ago
local self = DiesalGUI:Create(Type, true)
local frame = CreateFrame("Frame", nil, DiesalGUI.UIParent)
1 year ago
self.frame = frame
self.defaults = {
height = 16,
width = 50,
mouse = true,
}
-- ~~ Events ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- OnAcquire, OnRelease, OnHeightSet, OnWidthSet
-- OnEnter, OnLeave, OnEnterPressed, OnValueChanged
-- ~~ Construct ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
frame:SetScript("OnHide", function(this)
self:FireEvent("OnHide")
end)
local editBox = self:CreateRegion("EditBox", "editBox", frame) --[[@as Diesal.GUI.Region.EditBox]]
1 year ago
editBox:SetAllPoints()
editBox:SetAutoFocus(false)
editBox:SetJustifyH("LEFT")
8 months ago
editBox:SetJustifyV("MIDDLE")
1 year ago
editBox:SetTextInsets(3, 0, 2, 0)
editBox:SetScript("OnEnterPressed", function(this, ...)
self:FireEvent("OnEnterPressed", ...)
DiesalGUI:ClearFocus()
end)
editBox:HookScript("OnEscapePressed", function(this, ...)
self:FireEvent("OnEscapePressed", ...)
end)
editBox:HookScript("OnEditFocusLost", function(this, ...)
self:FireEvent("OnEditFocusLost", ...)
end)
editBox:HookScript("OnEditFocusGained", function(this, ...)
self:FireEvent("OnEditFocusGained", ...)
end)
editBox:SetScript("OnEnter", function(this, ...)
self:FireEvent("OnEnter", ...)
end)
editBox:SetScript("OnLeave", function(this, ...)
self:FireEvent("OnLeave", ...)
end)
-- ~~ Methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
self:SetMethods(methods)
8 months ago
self:SetObj(self.frame)
1 year ago
--[[ for method, func in pairs(methods) do
self[method] = func
end ]]
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
return self
end
DiesalGUI:RegisterObjectConstructor(Type, Constructor, Version)