ruen-ui/RuenUI/LayoutPolicy.lua

87 lines
4.1 KiB
Lua
Raw Permalink Normal View History

local _, P = ...
-- Shared reservations used by placement AND diagnostics. Hidden/empty buttons
-- still occupy their block, so overlays cannot land in a temporarily blank slot.
P.layoutPolicy = {
gap = 12, actionRowGap = 4, utilityRowGap = 6,
chat = {maximumWidth = 620, minimumHeight = 190, maximumHeight = 260,
minimumWidth = 240, fontSize = 14, edgeGap = 16},
controls = {
{name="Center controls", "MainActionBar","MultiBarBottomLeft","MultiBarBottomRight","MultiBar5"},
{name="Right controls", "MultiBarLeft","MultiBarRight","BagsBar","MicroMenuContainer"},
{name="Left controls", "MultiBar6","MultiBar7"},
},
panels = {"BankFrame","GuildBankFrame","MerchantFrame","QuestFrame","GossipFrame","MailFrame","TradeFrame",
"ProfessionsFrame","TradeSkillFrame","PlayerSpellsFrame","SpellBookFrame","WorldMapFrame","QuestLogFrame",
"CharacterFrame","AuctionHouseFrame"},
}
P.controlFrameNames, P.controlFrameSet = {}, {}
for _, group in ipairs(P.layoutPolicy.controls) do
for _, name in ipairs(group) do
P.controlFrameNames[#P.controlFrameNames+1] = name
P.controlFrameSet[name] = true
end
end
function P.DefaultChatSize()
-- Use logical UI dimensions: a 4K screen with a larger UI scale may have
-- the same usable space as 1080p. Unchanged defaults can follow a viewport
-- resize; ordinary refreshes keep custom sizes. Core separately fits
-- the width against the actual combat row, including custom positions.
local chat=P.layoutPolicy.chat
local width=math.max(chat.minimumWidth,math.min(chat.maximumWidth,UIParent:GetWidth()*.30))
local height=math.max(chat.minimumHeight,math.min(chat.maximumHeight,UIParent:GetHeight()*.22))
return math.floor(width/10)*10,math.floor(height/10)*10
end
function P.DefaultChatOrigin()
-- The native chat selection includes its tabs/buttons. The engine clamps
-- the requested 20-unit anchor to 32 on this client; that is not a manual
-- move. Read native insets so another client/scale can use its own margin.
local frame=ChatFrame1
local x,y=20,45
if frame and frame.GetClampRectInsets then
local left,right,top,bottom=frame:GetClampRectInsets()
local scale=frame:GetEffectiveScale()/UIParent:GetEffectiveScale()
x=math.max(x,-(left or 0)*scale)
y=math.max(y,-(bottom or 0)*scale)
end
return x,y
end
function P.IsDefaultChatSystem(system)
local saved=RuenUIDB.chatDefaultSize
local a=system and system.anchorInfo
if not saved or not a or a.point~="BOTTOMLEFT" or a.relativeTo~="UIParent"
or a.relativePoint~="BOTTOMLEFT" then return false end
local x,y=P.DefaultChatOrigin()
-- Native saves can retain either the requested or the clamped origin.
if not (a.offsetX==20 or (a.offsetX and math.abs(a.offsetX-x)<.5))
or not (a.offsetY==45 or (a.offsetY and math.abs(a.offsetY-y)<.5)) then return false end
local S=Enum.EditModeChatFrameSetting
local values={}
for _,v in ipairs(system.settings or {}) do values[v.setting]=v.value end
return (values[S.WidthHundreds] or 0)*100+(values[S.WidthTensAndOnes] or 0)==saved.width
and (values[S.HeightHundreds] or 0)*100+(values[S.HeightTensAndOnes] or 0)==saved.height
end
function P.ApplyChatDefaults()
-- Fresh installs only. Do not overwrite an existing player's font choice.
if RuenUICharacter.chatDefaultsVersion or RuenUICharacter.version then return end
if ChatFrame1 and ChatFrame1.GetFont and FCF_SetChatWindowFontSize then
local font,size,flags=ChatFrame1:GetFont()
RuenUICharacter.chatFontOriginal={font=font,size=size,flags=flags}
FCF_SetChatWindowFontSize(nil,ChatFrame1,P.layoutPolicy.chat.fontSize)
end
RuenUICharacter.chatDefaultsVersion=1
end
function P.RestoreChatDefaults()
local old=RuenUICharacter.chatFontOriginal
if not old or not ChatFrame1 or not ChatFrame1.GetFont then return end
local font,size=ChatFrame1:GetFont()
if font==old.font and size==P.layoutPolicy.chat.fontSize and FCF_SetChatWindowFontSize then
FCF_SetChatWindowFontSize(nil,ChatFrame1,old.size)
end
end