Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Settings panel should allow opening to a subcategory #285

Open
Meorawr opened this issue Sep 24, 2022 · 3 comments
Open

Settings panel should allow opening to a subcategory #285

Meorawr opened this issue Sep 24, 2022 · 3 comments
Labels
Bug Something isn't working Mainline This issue affects the current live Retail client

Comments

@Meorawr
Copy link
Collaborator

Meorawr commented Sep 24, 2022

In Dragonflight the current incarnation of the settings APIs doesn't support directly opening the settings panel to any category that isn't a top-level one.

A test addon is provided that will register a tree of addon categories up to a depth of 3. Once the test addon is loaded, the command listed in the table below can be used to test it.

Meorawr_SettingsOpenSubcategoryTest.zip

Meorawr_SettingsOpenSubcategoryTest.lua
local g_counter = CreateCounter();

local function CreateTestCategory(color, parent)
    local frame = CreateFrame("Frame");
    local background = frame:CreateTexture();
    background:SetAllPoints(frame);
    background:SetColorTexture(color:GetRGBA());

    local category;
    if parent then
        local name = string.format("%s.%d", parent:GetName(), parent.counter());
        category = Settings.RegisterCanvasLayoutSubcategory(parent, frame, name);
    else
        local name = string.format("Test Category %d", g_counter());
        category = Settings.RegisterCanvasLayoutCategory(frame, name);
    end

    category.counter = CreateCounter();

    Settings.RegisterAddOnCategory(category);
    return category;
end

TestCategory1 = CreateTestCategory(RED_FONT_COLOR);
TestCategory1_1 = CreateTestCategory(BLUE_FONT_COLOR, TestCategory1);
TestCategory1_1_1 = CreateTestCategory(GREEN_FONT_COLOR, TestCategory1_1);
TestCategory1_1_2 = CreateTestCategory(GRAY_FONT_COLOR, TestCategory1_1);
TestCategory1_2 = CreateTestCategory(YELLOW_FONT_COLOR, TestCategory1);
TestCategory1_3 = CreateTestCategory(ORANGE_FONT_COLOR, TestCategory1);
TestCategory1_3_1 = CreateTestCategory(BATTLENET_FONT_COLOR, TestCategory1_3);
TestCategory1_3_2 = CreateTestCategory(TRANSMOGRIFY_FONT_COLOR, TestCategory1_3);
TestCategory2 = CreateTestCategory(GOLD_FONT_COLOR);
TestCategory2_1 = CreateTestCategory(DIM_GREEN_FONT_COLOR, TestCategory2);
TestCategory2_1_1 = CreateTestCategory(AREA_NAME_FONT_COLOR, TestCategory2_1);
Command Outcome Desired Result
/run Settings.OpenToCategory(TestCategory1:GetID()) The settings panel successfully opens to the first custom category. N/A
/run Settings.OpenToCategory(TestCategory2:GetID()) The settings panel successfully opens to the second custom category. N/A
/run Settings.OpenToCategory(TestCategory2_1:GetID()) The settings panel fails to open to the requested top-level category. The settings panel should open to the requested category by an ID.
/run Settings.OpenToCategory(TestCategory1_3_2:GetID()) The settings panel fails to open to the requested nested subcategory. The settings panel should open to the requested nested subcategory by an ID, and should recursively expand its parent hierarchy.
@Meorawr Meorawr added Feature Request Requests for features Mainline Beta labels Sep 24, 2022
@Meorawr Meorawr added the Mainline PTR This issue affects the Retail PTR client label Oct 10, 2022
@Meorawr Meorawr added Mainline This issue affects the current live Retail client Bug Something isn't working and removed Mainline PTR This issue affects the Retail PTR client Feature Request Requests for features labels Oct 25, 2022
@DFortun81
Copy link

Bumping this. It would be really nice to have this.

@DFortun81
Copy link

DFortun81 commented Feb 17, 2024

A modification to the function like this would possibly do as we need it to for this to function.

local function FindCategoryByCategoryID(categories, categoryID)
	if categories then
		for index, category in ipairs(categories) do
			if category:GetID() == categoryID then
				return category;
			else
				local subcategory = FindCategoryByCategoryID(category:GetSubcategories(), categoryID);
				if subcategory then return subcategory; end
			end
		end
	end
end

function SettingsPanelMixin:OpenToCategory(categoryID, scrollToElementName)
	self:Open();

	local categoryTbl = FindCategoryByCategoryID(self:GetAllCategories(), categoryID);
	if not categoryTbl then return false; end
	
	self:SelectCategory(categoryTbl);
	if scrollToElementName then
		self:GetSettingsList():ScrollToElementByName(scrollToElementName);
	end
	return true;
end

@thewowcollector

This comment was marked as off-topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Mainline This issue affects the current live Retail client
Projects
None yet
Development

No branches or pull requests

3 participants