Skip to content

Commit

Permalink
add scroll frame
Browse files Browse the repository at this point in the history
  • Loading branch information
Krealle committed Sep 3, 2024
1 parent c61b57b commit 657588c
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions Menu/ColorTab.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ local Builder = CUF.Builder
local ColorTab = {}
ColorTab.id = "colorTab"
ColorTab.paneHeight = 17
ColorTab.sectionsHeight = 0

-------------------------------------------------
-- MARK: Import / Export
Expand Down Expand Up @@ -145,10 +146,19 @@ end

--- Create sections with color pickers for each color type
function ColorTab:CreateSections()
local heightPerCp = 30
local cpGap = (self.window:GetWidth() / 3) * 0.80
local sectionGap = 10

---@class ColorTab.colorSection: Frame
---@field scrollFrame CellScrollFrame
local colorSection = CUF:CreateFrame("CUF_Menu_ColorSection", self.window,
self.window:GetWidth(),
self.window:GetHeight() - self.importExportSection:GetHeight() - (sectionGap * 2), true, true)
colorSection:SetPoint("TOPLEFT", self.importExportSection, "BOTTOMLEFT", 0, -sectionGap)

Cell:CreateScrollFrame(colorSection)
colorSection.scrollFrame:SetScrollStep(50)

self.colorSections = {} ---@type CUF.ColorSection[]

local prevSection
Expand All @@ -157,8 +167,8 @@ function ColorTab:CreateSections()

for which, order in pairs(colorOrder) do
---@class CUF.ColorSection: Frame
local section = CUF:CreateFrame("ColorSection_" .. Util:ToTitleCase(which),
self.window, self.window:GetWidth(), 1, false, true)
local section = CUF:CreateFrame(colorSection:GetName() .. "_" .. Util:ToTitleCase(which),
colorSection.scrollFrame.content, self.window:GetWidth() - 10, 1, false, true)
section.id = which
section.cps = {} ---@type CUF.ColorSection.ColorPicker[]
section.dropdowns = {} ---@type CUF.ColorSection.Dropdown[]
Expand Down Expand Up @@ -248,19 +258,20 @@ function ColorTab:CreateSections()
gridLayout.currentColumn = gridLayout.currentColumn + 1
end

section:SetHeight(baseHeight --[[ + gridLayout.currentRow * heightPerCp ]])
section:SetHeight(baseHeight)
self.sectionsHeight = self.sectionsHeight + baseHeight + sectionGap

if not prevSection then
self.window:SetHeight(self.importExportSection:GetHeight() + section:GetHeight() + (sectionGap * 2))
section:SetPoint("TOPLEFT", self.importExportSection, "BOTTOMLEFT", 0, -sectionGap)
section:SetPoint("TOPLEFT", colorSection.scrollFrame.content)
else
self.window:SetHeight(self.window:GetHeight() + section:GetHeight() + sectionGap)
section:SetPoint("TOPLEFT", prevSection, "BOTTOMLEFT", 0, -sectionGap)
end

prevSection = section
tinsert(self.colorSections, section)
end

self.colorSection = colorSection
end

-------------------------------------------------
Expand All @@ -274,6 +285,9 @@ function ColorTab:ShowTab()
end

self.window:Show()

self.colorSection.scrollFrame:SetContentHeight(self.sectionsHeight)
self.colorSection.scrollFrame:ResetScroll()
end

function ColorTab:HideTab()
Expand All @@ -292,9 +306,9 @@ end
function ColorTab:Create()
local sectionWidth = Menu.tabAnchor:GetWidth()

self.window = CUF:CreateFrame("CUF_Menu_UnitFrame", Menu.window,
self.window = CUF:CreateFrame("CUF_Menu_Color", Menu.window,
sectionWidth,
0, true)
335, true)
self.window:SetPoint("TOPLEFT", Menu.tabAnchor, "TOPLEFT")

self:CreateImportExport()
Expand Down

0 comments on commit 657588c

Please sign in to comment.