From 70536bcbd65bd2993cc80cf4d4bd6749a183c9c3 Mon Sep 17 00:00:00 2001 From: Martin Konstantin Herrmann Date: Thu, 12 Nov 2026 00:54:29 +0100 Subject: [PATCH 1/2] Show frame toggle per unit Layout page gets a default-on Show frame toggle for every unit frame. Off drops oUF's unit watch (deferred until combat ends); copying the player style keeps each frame's own visibility. --- UnitFrames/Units/Definitions.lua | 10 +++++- UnitFrames/Units/Style.lua | 20 +++++++++++ tests/spec/units/shown_spec.lua | 58 ++++++++++++++++++++++++++++++++ 3 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 tests/spec/units/shown_spec.lua diff --git a/UnitFrames/Units/Definitions.lua b/UnitFrames/Units/Definitions.lua index c4583ca..a0dadcf 100644 --- a/UnitFrames/Units/Definitions.lua +++ b/UnitFrames/Units/Definitions.lua @@ -330,11 +330,19 @@ function Units:GetSpec(def, frame) return spec end +-- Whether the unit button is spawned visible at all (Style.lua ApplyShown). +-- Unit-level: the UnitFrame component and its previews never read it. +Units.SHOWN_OPTION = { key = "shown", type = "toggle", label = "Show frame", default = true, + tooltip = "Turn off to hide this frame entirely. Changes made in combat apply when combat ends." } + -- Frame-free style schema of a unit (cached; schemas are not mutated). function Units:GetSchema(unit) self.schemas = self.schemas or {} if not self.schemas[unit] then - self.schemas[unit] = ns.Schema.Build(ns.Components.UnitFrame.BuildSchema, self:GetSpec(self.definitions[unit])) + local schema = { Units.SHOWN_OPTION } + local style = ns.Schema.Build(ns.Components.UnitFrame.BuildSchema, self:GetSpec(self.definitions[unit])) + for _, opt in ipairs(style) do schema[#schema + 1] = opt end + self.schemas[unit] = schema end return self.schemas[unit] end diff --git a/UnitFrames/Units/Style.lua b/UnitFrames/Units/Style.lua index 5288106..f1f7792 100644 --- a/UnitFrames/Units/Style.lua +++ b/UnitFrames/Units/Style.lua @@ -214,6 +214,8 @@ function Units:CopyPlayerSettings(unit) copy.comboPoints = ns.Util.Copy(ns.Config:GetUnitConfig(unit).comboPoints) -- The player frame has no threat glow: each frame keeps its own. copy.threat = ns.Util.Copy(ns.Config:GetUnitConfig(unit).threat) + -- Hiding a frame is per frame, not part of its style. + copy.shown = ns.Config:GetUnitConfig(unit).shown return ns.Config:UnitStore(unit):Replace(copy) end @@ -256,6 +258,22 @@ oUF:RegisterStyle(Units.STYLE, function(frame, unit) Units:Bind(frame) end) +-- Visibility ------------------------------------------------------------------ + +-- A hidden frame drops oUF's unit watch, so the game no longer shows it. The +-- watch is protected: changes made in combat wait for it to end. +function Units:ApplyShown(unit) + local frame = self.frames[unit] + if not frame then return end + local shown = ns.Config:UnitStore(unit):Resolved().shown + if not shown == not frame:IsEnabled() then return end + if InCombatLockdown() then + ns.AfterCombat:Queue("layout", frame, function() self:ApplyShown(unit) end) + return + end + if shown then frame:Enable() else frame:Disable() end +end + -- Spawning -------------------------------------------------------------------- local function Spawn(factory, unit) @@ -264,6 +282,7 @@ local function Spawn(factory, unit) local name = "UnitFrames" .. unit:gsub("^%l", string.upper) local frame = factory:Spawn(unit, name) Units.frames[unit] = frame + Units:ApplyShown(unit) ns.Perf:End("unit spawn") ns.Perf:Begin("edit mode registration") ns.EditMode:Register(frame, unit, "UnitFrames: " .. def.label, def.defaultPosition) @@ -280,6 +299,7 @@ end) ns.Events.RegisterCallback(Units, "UnitConfigChanged", function(_, unit) Units:Refresh(unit) + Units:ApplyShown(unit) end) -- Colours come from the theme too (power colours, health gradient). diff --git a/tests/spec/units/shown_spec.lua b/tests/spec/units/shown_spec.lua new file mode 100644 index 0000000..703e29c --- /dev/null +++ b/tests/spec/units/shown_spec.lua @@ -0,0 +1,58 @@ +local Helpers = require("helpers") +local Mock = Helpers.Mock + +local function Watched(frame) + return frame:IsEnabled() and true or false +end + +describe("Show frame", function() + local ns + before_each(function() + ns = Helpers.LoadAddon(true, true) + end) + + after_each(function() + Mock.inCombat = false + end) + + it("is offered on every unit's layout page and on by default", function() + for _, unit in ipairs(ns.Units.order) do + local opt = ns.Schema.Find(ns.Units:GetSchema(unit), "shown") + assert.equals("toggle", opt.type, unit) + assert.is_true(opt.default, unit) + assert.is_true(Watched(ns.Units.frames[unit]), unit) + end + end) + + it("drops the unit watch when switched off and restores it when switched on", function() + local frame = ns.Units.frames.pet + ns.Config:SetUnitValue("pet", "shown", false) + assert.is_false(Watched(frame)) + assert.is_false(frame:IsShown()) + assert.is_true(Watched(ns.Units.frames.player)) + + ns.Config:SetUnitValue("pet", "shown", nil) + assert.is_true(Watched(frame)) + end) + + it("waits for combat to end", function() + local frame = ns.Units.frames.focus + Mock.inCombat = true + ns.Config:SetUnitValue("focus", "shown", false) + assert.is_true(Watched(frame)) + + Mock.inCombat = false + Mock.FireEvent("PLAYER_REGEN_ENABLED") + assert.is_false(Watched(frame)) + end) + + it("keeps each frame's own visibility when copying the player style", function() + ns.Config:SetUnitValue("player", "shown", false) + ns.Config:SetUnitValue("target", "shown", false) + ns.Units:CopyPlayerSettings("focus") + assert.is_nil(ns.Config:GetUnitConfig("focus").shown) + assert.is_true(Watched(ns.Units.frames.focus)) + ns.Units:CopyPlayerSettings("target") + assert.is_false(ns.Config:GetUnitConfig("target").shown) + end) +end) From e7958999cf10f9ff57410dc1fac39b984a8d3079 Mon Sep 17 00:00:00 2001 From: Martin Konstantin Herrmann Date: Thu, 12 Nov 2026 00:55:32 +0100 Subject: [PATCH 2/2] Proof scenario for hidden pet frame Renders the pet's Layout settings with Show frame switched off. --- tests/proof/workbench.lua | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/proof/workbench.lua b/tests/proof/workbench.lua index cd68e0e..d82995e 100644 --- a/tests/proof/workbench.lua +++ b/tests/proof/workbench.lua @@ -80,7 +80,22 @@ local function LargeSharedDebuffs(ns) ns.Config:SetThemeValue("auras.spacing", 4) end +local function HiddenPetLayout() + local ns, workbench = Helpers.LoadWorkbench() + ns.Config:SetUnitValue("pet", "shown", false) + workbench:Open("unit.pet") + workbench:SelectSection("layout") + local content = workbench.inspector.scroll:GetContent() + content:SetParent(UIParent) + content:ClearAllPoints() + content:SetPoint("TOPLEFT") + content:SetSize(420, 330) + workbench.inspector:Refresh() + return content +end + return { + { name = "workbench-pet-hidden", build = HiddenPetLayout }, { name = "workbench-global-settings-menu", build = GlobalSettingsMenu }, { name = "workbench-global-aura-icons", build = GlobalAuraIcons() }, { name = "workbench-global-aura-icons-changed", build = GlobalAuraIcons(LargeSharedDebuffs) },