main
jeffi 11 months ago
parent 892f29cd2b
commit d00e705bfe
  1. 3
      DiesalGUI-2.0/DiesalGUI-2.0.lua
  2. 67
      DiesalGUI-2.0/Objects/DropDown.lua
  3. 15
      DiesalGUI-2.0/Objects/DropDownItem.lua
  4. 7
      DiesalGUI-2.0/Objects/ObjectBase.lua
  5. 4
      DiesalGUI-2.0/Objects/Toggle.lua

@ -111,8 +111,7 @@ end
---|DiesalTree
---|DiesalWindow
---@diagnostic disable-next-line: undefined-field
_G.WorldFrame:HookScript("OnMouseDown", WorldFrameOnMouse)
WorldFrame:HookScript("OnMouseDown", WorldFrameOnMouse)
-- Objects (widgets) that are defined for use in DiesalGUI
---@alias Diesal.Object.Type

@ -100,6 +100,7 @@ local methods = {
self:SetStylesheet(Stylesheet)
-- self:SetStylesheet(wireFrameSheet)
self:Show()
self:SetFrameStrata("TOOLTIP")
end,
---@param self Diesal.GUI.Object.DropDown
@ -135,8 +136,10 @@ local methods = {
settings.list = list
local foldColor = "353535"
local expandColor = "5a5a5a"
self.dropdown:SetFrameStrata("TOOLTIP")
for position, item in ipairs(list) do
local dropdownItem = DiesalGUI:Create("DiesalDropDownItem")
DiesalGUI:OnMouse(dropdownItem.frame, "LeftButton")
self:AddChild(dropdownItem)
dropdownItem:SetParentObject(self)
dropdownItem:SetSettings({
@ -191,6 +194,7 @@ local methods = {
SetValue = function(self, key)
local selectionTable = {}
local selectedKey, dropdownText, selectedValue
local selectedCount = 0
if key ~= "CLEAR" then
if self.settings.multiSelect then
@ -200,6 +204,7 @@ local methods = {
self.children[i]:SetSelected(true)
end
if self.children[i].settings.selected then
selectedCount = selectedCount + 1
if dropdownText then
dropdownText = format("%s, %s", dropdownText, self.children[i].settings.value)
else
@ -225,6 +230,10 @@ local methods = {
self:ClearSelection()
end
if self.settings.multiSelect then
dropdownText = string.format("+%d", selectedCount)
end
if selectedKey then
self:SetText(dropdownText)
self:FireEvent("OnValueChanged", selectedKey, selectedValue, selectionTable)
@ -251,6 +260,7 @@ local methods = {
local selectionTable = {}
local selectedKey
local dropdownText
local selectedCount = 0
for i = 1, #dropdownItems do
local dropdownItem = dropdownItems[i]
@ -258,12 +268,18 @@ local methods = {
for _, key in ipairs(keyTable) do
if dropdownItem.settings.key == key then
dropdownItem:SetSelected(true)
selectedCount = selectedCount + 1
if not self.settings.multiSelect then
dropdownText = dropdownText and format("%s, %s", dropdownText, dropdownItem.settings.value) or dropdownItem.settings.value
end
selectionTable[#selectionTable + 1] = dropdownItem.settings.key
end
end
end
self:FireEvent("OnValueChanged", nil, nil, selectionTable)
if self.settings.multiSelect then
dropdownText = string.format("+%d", selectedCount)
end
self:SetText(dropdownText)
end,
@ -290,6 +306,7 @@ local methods = {
---@param self Diesal.GUI.Object.DropDown
ClearFocus = function(self)
self.dropdownShown = false
self.dropdown:Hide()
end,
@ -312,6 +329,27 @@ local methods = {
SetJustifyH = function(self, justify)
self.text:SetJustifyH(justify)
end,
---@param self Diesal.GUI.Object.DropDown
ShowDropDown = function(self)
self.dropdown:SetFrameStrata("TOOLTIP")
self.dropdown:SetParent(self.frame)
self.dropdown:Show()
self.dropdownShown = true
end,
---@param self Diesal.GUI.Object.DropDown
HideDropDown = function(self)
self.dropdown:Hide()
self.dropdownShown = false
end,
---@param self Diesal.GUI.Object.DropDown
ToggleDropDown = function(self)
print("ToggleDropDown", self.dropdown:IsShown())
if self.dropdownShown then
self:HideDropDown()
else
self:ShowDropDown()
end
end,
}
---@class Diesal.GUI.Obeject.DropDown.Settings
@ -327,6 +365,8 @@ local methods = {
---@class DiesalDropDown : Diesal.GUI.Object.DropDown
local f = CreateFrame("Button", nil, UIParent)
-- ~~| Dropdown Constructor |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
local function Constructor()
---@class Diesal.GUI.Object.DropDown : Diesal.GUI.ObjectBase, Diesal.GUI.DropDown.Methods
@ -337,8 +377,11 @@ local function Constructor()
---@field content Frame
---@field value string
local self = DiesalGUI:Create(Type, true)
self:SetMethods(methods)
self.dropdownShown = true
local frame = CreateFrame("Button", nil, UIParent)
frame:SetFrameStrata("TOOLTIP")
self.frame = frame
self.isContainer = true
@ -356,16 +399,16 @@ local function Constructor()
-- OnValueSelected(event,selectedKey,selectedValue,selectionTable)
-- OnEnter, OnLeave
-- ~~ Construct ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
frame:SetScript("OnMouseUp", function(this, button)
frame:SetScript("OnClick", function(this, button, down)
if button == "LeftButton" then
local dropdown = self.dropdown
local visible = dropdown:IsVisible()
if self.dropdown:IsVisible() then
self.dropdown:Hide()
else
DiesalGUI:OnMouse(this, button)
dropdown[visible and "Hide" or "Show"](dropdown)
self.dropdown:Show()
end
end)
frame:SetScript("OnClick", function(this, ...)
self:FireEvent("OnClick", ...)
end
self:FireEvent("OnClick", button, down)
end)
frame:SetScript("OnEnter", function(this, ...)
self:FireEvent("OnEnter", ...)
@ -382,18 +425,24 @@ local function Constructor()
text:SetJustifyH("LEFT")
local dropdown = self:CreateRegion("Frame", "dropdown", frame)
dropdown:SetFrameStrata("FULLSCREEN_DIALOG")
dropdown:SetFrameStrata("TOOLTIP")
dropdown:SetFrameLevel(998)
dropdown:SetToplevel(true)
dropdown:SetPoint("TOPRIGHT", frame, "BOTTOMRIGHT", 0, -2)
dropdown:SetPoint("TOPLEFT", frame, "BOTTOMLEFT", 0, -2)
dropdown:SetScript("OnShow", function(this)
self:SetFocus()
end)
dropdown:SetScript("OnHide", function(this)
self.dropdownShown = false
end)
dropdown:Hide()
self.dropdown = dropdown
self:CreateRegion("Frame", "content", dropdown)
-- ~~ Methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
self:SetMethods(methods)
--self:SetMethods(methods)
--[[ for method, func in pairs(methods) do
self[method] = func
end ]]

@ -44,7 +44,6 @@ local methods = {
local settings = self.settings
local dropdownSettings = settings.parentObject.settings
local text = self.text
if settings.position == 1 then
self:SetPoint("TOPLEFT")
else
@ -72,8 +71,11 @@ local methods = {
["OnClick"] = function(self)
local settings = self.settings
local dropdown = settings.parentObject
if dropdown then
---@cast dropdown Diesal.GUI.Object.DropDown
local dropdownSettings = dropdown.settings
local dropdownItems = dropdown.children
local selectedCount = 0
local selectionTable = {}
local dropdownText
@ -85,6 +87,7 @@ local methods = {
self:SetSelected(not settings.selected)
for i = 1, #dropdownItems do
if dropdownItems[i].settings.selected then
selectedCount = selectedCount + 1
dropdownText = dropdownText and format("%s, %s", dropdownText, dropdownItems[i].settings.value) or dropdownItems[i].settings.value
selectionTable[#selectionTable + 1] = dropdownItems[i].settings.key
end
@ -104,10 +107,13 @@ local methods = {
dropdown.dropdown:Hide()
dropdown:ClearSelection()
end
if dropdownSettings.multiSelect then
dropdownText = string.format("+%d", selectedCount)
end
dropdown:SetText(dropdownText)
dropdown:FireEvent("OnValueChanged", settings.key, settings.value, selectionTable)
dropdown:FireEvent("OnValueSelected", settings.key, settings.value, selectionTable)
end
end,
---@param self Diesal.GUI.Object.DropDown.Item
["SetSelected"] = function(self, selected)
@ -125,6 +131,7 @@ local methods = {
---@field clickable boolean
---@field indent number
---@field header boolean
---@field parentObject Diesal.GUI.Object.DropDown
---@class DiesalDropDownItem : Diesal.GUI.Object.DropDown.Item
@ -136,6 +143,10 @@ local function Constructor()
---@field settings Diesal.GUI.DropDownItem.Settings
local self = DiesalGUI:Create(Type, true)
local frame = CreateFrame("Button", nil, UIParent)
frame:SetToplevel(true)
frame:SetFrameLevel(999)
frame:SetFrameStrata("TOOLTIP")
frame:SetFixedFrameStrata(true)
self.frame = frame
self.defaults = {}
-- ~~ Construct ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

@ -30,6 +30,13 @@ local ObjectBase = {
self.frame:Show()
end,
---@generic T : Diesal.GUI.ObjectBase
---@param self T | Diesal.GUI.ObjectBase
---@param strata FrameStrata
SetFrameStrata = function(self, strata)
self.frame:SetFrameStrata(strata)
end,
---@generic T : Diesal.GUI.ObjectBase
---@param self T | Diesal.GUI.ObjectBase
---@param parent Frame

@ -226,6 +226,10 @@ local function Constructor()
frame:SetScript("OnEnable", function(this)
self:FireEvent("OnEnable")
end)
---@param this Frame
frame:SetScript("OnShow", function(this)
this:SetFrameStrata("FULLSCREEN")
end)
fontString:SetPoint("LEFT", frame, "RIGHT", 5, 0)
fontString:SetHeight(15)

Loading…
Cancel
Save