Skip to content

TavernWorks/LibAnchorRegistry

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LibAnchorRegistry-1.0

Inter-addon frame anchoring system for World of Warcraft.

Installation

For Addon Users

This library is typically bundled with addons that use it. No manual installation required.

For Addon Developers

  1. Copy the LibAnchorRegistry-1.0 folder into your addon's Libs directory
  2. Add to your TOC file:
    Libs\LibAnchorRegistry-1.0\LibStub\LibStub.lua
    Libs\LibAnchorRegistry-1.0\LibAnchorRegistry-1.0.lua
    
  3. Or use as external dependency in .pkgmeta

Quick Start

local Anchor = LibStub("LibAnchorRegistry-1.0")

-- Register your frame
Anchor:Register("MyAddon", myMainFrame, {
    displayName = "My Addon",
    category = "misc",
})

-- Anchor to another addon
Anchor:AnchorTo(myFrame, "OtherAddon", "TOP", "BOTTOM", 0, -5)

Features

  • Simple Registration: Register frames with human-readable names
  • Deferred Anchoring: Automatically waits for target frames to load
  • Dual-Point Anchoring: Auto-size frames between two anchor points
  • Group Layout: Automatically layout multiple frames in rows/columns
  • Combat Safe: Queues operations during combat lockdown
  • Event System: Subscribe to anchor changes (move, resize, show, hide)
  • Fallback Support: Specify fallback anchors when primary target isn't available

Basic Usage

Registering a Frame

local Anchor = LibStub("LibAnchorRegistry-1.0")

-- Register a frame
Anchor:Register("MyCooldownManager", myCDMFrame, {
    displayName = "My Cooldown Manager",
    category = "cooldowns",
    description = "Main cooldown tracking bar",
})

Simple Anchoring

-- Simple one-liner
Anchor:AnchorTo(myFrame, "MyCooldownManager", "TOP", "BOTTOM", 0, -5)

-- With full config
Anchor:AnchorTo(myFrame, {
    target = "MyCooldownManager",
    point = "TOPLEFT",
    relativePoint = "BOTTOMLEFT",
    offsetX = 0,
    offsetY = -10,
    fallback = "UIParent",
    fallbackPoint = "CENTER",
    followVisibility = true,
})

Dual-Point Anchoring (Auto-Sizing)

-- Health bar fills parent with 2px padding
Anchor:AnchorDual(healthBar, {
    target = "MyUnitFrames.Player",
    point = "TOPLEFT",
    relativePoint = "TOPLEFT",
    offsetX = 2,
    offsetY = -2,
    
    target2 = "MyUnitFrames.Player",
    point2 = "BOTTOMRIGHT",
    relativePoint2 = "BOTTOMRIGHT",
    offsetX2 = -2,
    offsetY2 = 2,
})

-- Shorthand
Anchor:Fill(healthBar, "MyUnitFrames.Player", 2)

-- With per-side padding
Anchor:FillWithPadding(healthBar, "MyUnitFrames.Player", {
    left = 2,
    right = 2,
    top = 2,
    bottom = 2,
})

Group Layout

local partyFrames = { party1Frame, party2Frame, party3Frame, party4Frame }

local handle = Anchor:AnchorGroup(partyFrames, {
    target = "MyCooldownManager",
    point = "TOPLEFT",
    relativePoint = "BOTTOMLEFT",
    offsetY = -10,
    direction = "DOWN",
    spacing = 2,
    wrap = 2,  -- Wrap after 2 frames
    wrapDirection = "RIGHT",
})

-- Later, party size changes
handle:SetFrames({ party1Frame, party2Frame })

Subscribing to Changes

-- Watch specific anchor
local sub = Anchor:Subscribe("MyCooldownManager", function(name, event, frame, metadata)
    if event == "MOVED" then
        print("CDM moved!")
    elseif event == "RESIZED" then
        print("CDM resized!")
    end
end)

-- Watch all anchors
local globalSub = Anchor:SubscribeAll(function(name, event, frame, metadata)
    print(name .. " " .. event)
end)

-- Later
sub:Unsubscribe()
globalSub:Unsubscribe()

Discovery

-- Check if anchor exists
if Anchor:Exists("MyCooldownManager") then
    -- Get frame and metadata
    local frame, metadata = Anchor:Get("MyCooldownManager")
end

-- Get all anchors
local allAnchors = Anchor:GetAll()

-- Get by category
local cooldownAnchors = Anchor:GetByCategory("cooldowns")

-- Search
local results = Anchor:Search("cooldown")

-- Get dropdown data for config UI
local dropdownData = Anchor:GetDropdownData({
    categories = { "cooldowns", "unitframes" },
    persistent = true,
})

API Reference

Registration

  • Anchor:Register(name, frame, metadata) - Register a frame as an anchor target
  • Anchor:Unregister(name) - Remove a registered anchor
  • Anchor:UpdateMetadata(name, metadata) - Update metadata for an existing anchor

Discovery

  • Anchor:Get(name) - Get frame and metadata for an anchor
  • Anchor:Exists(name) - Check if anchor exists
  • Anchor:GetAll() - Get all registered anchors
  • Anchor:GetByCategory(category) - Get anchors by category
  • Anchor:Search(query) - Search anchors by name
  • Anchor:GetDropdownData(options) - Get formatted data for dropdowns

Anchoring

  • Anchor:AnchorTo(frame, target, point, relativePoint, offsetX, offsetY) - Simple anchor
  • Anchor:AnchorTo(frame, config) - Full config anchor
  • Anchor:AnchorDual(frame, config) - Dual-point anchor
  • Anchor:Fill(frame, target, inset) - Fill target with uniform inset
  • Anchor:FillWithPadding(frame, target, padding) - Fill with per-side padding
  • Anchor:AnchorGroup(frames, config) - Group layout

Handle Methods

  • handle:Update() - Force re-anchor
  • handle:Release() - Stop managing anchor
  • handle:SetOffset(x, y) - Update primary offset
  • handle:SetOffset2(x, y) - Update secondary offset (dual only)
  • handle:GetTarget() - Get primary target frame
  • handle:GetTarget2() - Get secondary target frame (dual only)
  • handle:GetConfig() - Get current config
  • handle:IsActive() - Check if anchor is active
  • handle:IsPending() - Check if waiting for target

Group Handle Methods

  • handle:SetFrames(frames) - Replace frame list
  • handle:AddFrame(frame) - Add frame to group
  • handle:RemoveFrame(frame) - Remove frame from group
  • handle:Refresh() - Recalculate layout
  • handle:GetFrames() - Get current frame list

Events

  • Anchor:Subscribe(name, callback) - Subscribe to specific anchor
  • Anchor:SubscribeAll(callback) - Subscribe to all anchors

Events: "REGISTERED", "UNREGISTERED", "MOVED", "RESIZED", "SHOWN", "HIDDEN"

Utilities

  • Anchor:Debug() - Print debug information
  • Anchor:SetDebug(enabled) - Enable/disable debug warnings
  • Anchor:GetVersion() - Get library version

Categories

Standard categories:

  • "unitframes" - Player, target, party, raid frames
  • "cooldowns" - Cooldown tracking addons
  • "bars" - Action bars, status bars
  • "misc" - Everything else

Naming Conventions

  • Single main frame: "AddonName"
  • Multiple frames: "AddonName.FrameType" or "AddonName.FrameType.Specific"

Examples:

  • "BetterCDM"
  • "BetterCDM.Bar1"
  • "YourUnitFrames.Player"
  • "Details.Window1"

License

GPL-2.0

About

Inter-addon frame anchoring system for World of Warcraft.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors