Skip to content
Adrian L Lange edited this page Feb 10, 2026 · 17 revisions

Note

Please browse the pages in the section to the right to see the available API.

Embedding

Please see the embedding page on how to include this library (and its dependencies) with your addon.

Loading

There are two ways to load and use LibEditMode:

Method 1: Namespace

This is the recommended way, as it avoids potential collisions with other addons also using LibEditMode, but it's slightly more wasteful in terms of resources.

MyAddon.toc:

## Interface: 120000, 120001
## Title: MyAddOn

# IMPORTANT: namespaced.lua must be loaded FIRST
libs\LibEditMode\namespaced.lua
libs\LibEditMode\embed.xml

MyAddon.lua

MyAddon.lua:

local _, ns = ...
local LibEditMode = ns.LibEditMode

Method 2: LibStub

This method is a bit more efficient in terms of resources as multiple addons can use the same library and it'd only load once, but is possibly prone to collisions with older versions loaded by other addons.

MyAddon.toc:

## Interface: 120000, 120001
## Title: MyAddOn

libs\LibStub\LibStub.lua
libs\LibEditMode\embed.xml

MyAddon.lua

MyAddon.lua:

local LibEditMode = LibStub("LibEditMode")

Example with a button:

local button = CreateFrame('Button', 'MyButton', UIParent)
button:SetSize(50, 50)
local texture = button:CreateTexture()
texture:SetAllPoints()
texture:SetColorTexture(0, 0, 1)

local defaultPosition = {
  point = 'CENTER',
  x = 0,
  y = 0,
}

local function onPositionChanged(frame, layoutName, point, x, y)
  -- from here you can save the position into a savedvariable
  MyButtonDB[layoutName].point = point
  MyButtonDB[layoutName].x = x
  MyButtonDB[layoutName].y = y
end

-- additional (anonymous) callbacks
LibEditMode:RegisterCallback('enter', function()
  -- from here you can show your button if it was hidden
end)
LibEditMode:RegisterCallback('exit', function()
  -- from here you can hide your button if it's supposed to be hidden
end)
LibEditMode:RegisterCallback('layout', function(layoutName)
  -- this will be called every time the Edit Mode layout is changed (which also happens at login),
  -- use it to load the saved button position from savedvariables and position it
  if not MyButtonDB then
    MyButtonDB = {}
  end
  if not MyButtonDB[layoutName] then
    MyButtonDB[layoutName] = CopyTable(defaultPosition)
  end

  button:ClearAllPoints()
  button:SetPoint(MyButtonDB[layoutName].point, MyButtonDB[layoutName].x, MyButtonDB[layoutName].y)
end)

-- NOTE: it is _highly_ adviced to use and support all the callbacks!

LibEditMode:AddFrame(button, onPositionChanged, defaultPosition)

Adding extra settings for a button:

LibEditMode:AddFrameSettings(button, {
  {
    name = 'Button scale',
    kind = LEM.SettingType.Slider,
    default = 1,
    get = function(layoutName)
      return MyButtonDB[layoutName].scale
    end,
    set = function(layoutName, value)
      MyButtonDB[layoutName].scale = value
      button:SetScale(value)
    end,
    minValue = 0.1,
    maxValue = 5,
    valueStep = 0.1,
    formatter = function(value)
      return FormatPercentage(value, true)
    end,
  }
})

Clone this wiki locally