Restrict frame size to follow grid (otherwise what's the point)

This commit is contained in:
2025-01-06 18:00:54 +01:00
parent cdd859ba50
commit e8e15444c9

View File

@@ -8,20 +8,24 @@ local addonname, shared = ...
---@field frame Frame
---@field cellWidth number
---@field cellHeight number
---@field allowOverflow boolean
---@field columnCursors table<number, number>
GridFrame = {
---@param name string
---@param parent Frame
---@param columns number
---@param cellHeight number
---@param size {w: number, h:number}
---@param size {w: number, h:number}?
---@return GridFrame
new = function(name, parent, columns, cellHeight, size)
local self = setmetatable({}, {
__index = GridFrame
})
self.frame = CreateFrame("Frame", name, parent)
self.frame:SetSize(size.w, size.h)
size = size or {}
if size.w then self.frame:SetWidth(size.w) end
if size.h then self.frame:SetHeight(size.h) end
self.allowOverflow = false
self.frame:SetPoint("CENTER", UIParent, "CENTER")
self.frame:SetBackdrop({
bgFile = "Interface/Tooltips/UI-Tooltip-Background",
@@ -38,6 +42,14 @@ GridFrame = {
for i = 1, columns do
self.columnCursors[i] = 0
end
local previousSetWidth = self.frame.SetWidth
self.frame.SetWidth = function(frame, width)
if not width then return end
previousSetWidth(frame, width)
self.cellWidth = self.frame:GetWidth() / self.columns
end
return self
end,
---@param self GridFrame
@@ -61,9 +73,17 @@ GridFrame = {
end
end
if not self.allowOverflow then
if bestMaxY + self.cellHeight * rowspan > self.frame:GetHeight() then
print("Frame is too tall")
return
end
end
if bestStartColumn then
local x = (bestStartColumn - 1) * self.cellWidth
local y = -bestMaxY
print("Adding frame to grid", x, y, self.cellWidth * colspan, self.cellHeight * rowspan)
frame:SetWidth(self.cellWidth * colspan)
frame:SetHeight(self.cellHeight * rowspan)
frame:SetPoint("TOPLEFT", self.frame, "TOPLEFT", x, y)
@@ -80,9 +100,13 @@ GridFrame = {
local configFrame = GridFrame.new("HeimdallConfig",
UIParent,
6, 32,
12, 20,
{ w = 512, h = 512 + 256 })
local innerFrame = GridFrame.new("HeimdallConfigInner",
configFrame.frame, 6, 20)
configFrame:Add(innerFrame.frame, 6, 6)
local colors = {
{ 1, 0, 0, 1 },
{ 0, 1, 0, 1 },
@@ -92,7 +116,7 @@ local colors = {
{ 0, 1, 1, 1 },
{ 1, 1, 1, 1 },
}
for i = 1, 100 do
for i = 1, 20 do
local frame = CreateFrame("Frame", "HeimdallConfigFrame" .. i, UIParent)
frame:SetBackdrop({
bgFile = "Interface/Tooltips/UI-Tooltip-Background",
@@ -101,7 +125,7 @@ for i = 1, 100 do
})
frame:SetBackdropColor(unpack(colors[i % #colors + 1]))
frame:SetBackdropBorderColor(0.5, 0.5, 0.5, 1)
configFrame:Add(frame, 1, 12)
innerFrame:Add(frame, 4, 2)
end
---@diagnostic disable-next-line: missing-fields
shared.Config = {}
@@ -197,25 +221,26 @@ function shared.Config.Init()
--configFrame:SetBackdropColor(0, 0, 0, 0.8)
--configFrame:SetBackdropBorderColor(0.5, 0.5, 0.5, 1)
configFrame.frame:SetMovable(true)
configFrame.frame:EnableMouse(true)
configFrame.frame:RegisterForDrag("LeftButton")
configFrame.frame:SetScript("OnDragStart", function(self)
self:StartMoving()
end)
configFrame.frame:SetScript("OnDragStop", function(self)
self:StopMovingOrSizing()
end)
configFrame.frame:SetScript("OnShow", function(self)
self:SetScale(1)
end)
-- configFrame.frame:SetMovable(true)
-- configFrame.frame:EnableMouse(true)
-- configFrame.frame:RegisterForDrag("LeftButton")
-- configFrame.frame:SetScript("OnDragStart", function(self)
-- self:StartMoving()
-- end)
-- configFrame.frame:SetScript("OnDragStop", function(self)
-- self:StopMovingOrSizing()
-- end)
-- configFrame.frame:SetScript("OnShow", function(self)
-- self:SetScale(1)
-- end)
--
-- local title = configFrame.frame:CreateFontString(nil, "ARTWORK", "GameFontNormal")
-- title:SetText("Heimdall Config")
-- configFrame:Add(title, 1, 12)
local title = configFrame.frame:CreateFontString(nil, "ARTWORK", "GameFontNormal")
title:SetText("Heimdall Config")
--configFrame:Add(title, 1, 12)
-- local spotterConfigFrame = GridFrame.new("HeimdallSpotterConfig", configFrame.frame, 12, 12)
-- --configFrame:Add(spotterConfigFrame.frame, 12, 6)
-- local spotterConfigFrame = GridFrame.new("HeimdallSpotterConfig",
-- configFrame.frame, 12, 20, { w: 0,h: 0 })
-- configFrame:Add(spotterConfigFrame.frame, 12, 6)
-- spotterConfigFrame.frame:SetBackdrop({
-- bgFile = "Interface/Tooltips/UI-Tooltip-Background",
-- edgeFile = "Interface/Tooltips/UI-Tooltip-Border",
@@ -229,8 +254,9 @@ function shared.Config.Init()
-- bottom = 4
-- }
-- })
-- spotterConfigFrame.frame:SetBackdropColor(0, 0, 0, 0.8)
-- spotterConfigFrame.frame:SetBackdropColor(1, 0, 0, 0.8)
-- spotterConfigFrame.frame:SetBackdropBorderColor(0.5, 0.5, 0.5, 1)
-- spotterConfigFrame:Show()
--local spotterEnableButton = BasicButton("HeimdallSpotterEnable", spotterConfigFrame, "Enable Spotter",
-- function(state)