what is the coding proper and standard way to place, keep and drag a minimap button in…
- User
what is the coding proper and standard way to place, keep and drag a minimap button in world of warcraft addon? For example, it appears on the edge, stayes there and mover around the circle when dragging, etc.
- Assistant
Below you’ll find two approaches that are considered “best practice” in the WoW-addon scene:
A) “The standard way” – use LibDataBroker + LibDBIcon (99 % of modern addons do this).
B) “Roll-your-own” – if you have a good reason to avoid external libs.Feel free to copy-paste the snippets; they work in Dragonflight/WotLK-C as-is.
(ReplaceMyAddonand the icon with your own data.)
A) USING LIBDATABROKER + LIBDBICON (RECOMMENDED)
Why this is the de-facto standard
• Handles round & square minimaps automatically (GetMinimapShape())
• Dragging along the rim, saving angle, hiding/showing – all implemented
• Plays nicely with UI replacements such as SexyMap
• Only ±30 lines of glue code for your addon- Add the libs
youraddon
├─ youraddon.toc
├─ libs\LibStub\LibStub.lua
├─ libs\LibDataBroker-1.1\ …
└─ libs\LibDBIcon-1.0\ …
Inside the TOC:
## OptionalDeps: LibStub LibDataBroker-1.1 LibDBIcon-1.0 AceDB-3.0 libs\LibStub\LibStub.lua libs\LibDataBroker-1.1\LibDataBroker-1.1.lua libs\LibDBIcon-1.0\LibDBIcon-1.0.lua libs\Ace3\AceDB-3.0\AceDB-3.0.lua ## only if you don't already ship Ace3 core.lua ## your file- Glue code (core.lua)
local addonName, addon = ... ------------------------------------------------- -- 1) Create the LDB object (= the “data source”) ------------------------------------------------- local LDB = LibStub("LibDataBroker-1.1"):NewDataObject(addonName, { type = "launcher", icon = "Interface\\Icons\\INV_Misc_QuestionMark", OnClick = function(_, button) if button == "LeftButton" then print("Left click -> open your main frame here") elseif button == "RightButton" then print("Right click -> maybe open config") end end, OnTooltipShow = function(tt) tt:AddLine("MyAddon", 1, 1, 1) tt:AddLine("Left-click to open", 0.8, 0.8, 0.8) tt:AddLine("Right-click for options", 0.8, 0.8, 0.8) end, }) ------------------------------------------------- -- 2) Register it with LibDBIcon and a saved db ------------------------------------------------- local icon = LibStub("LibDBIcon-1.0") -- simple AceDB profile just to store minimap settings addon.db = LibStub("AceDB-3.0"):New("MyAddonDB", { profile = { minimap = { hide = false, minimapPos = 220 } } }) -- actually create + show the button icon:Register(addonName, LDB, addon.db.profile.minimap) ------------------------------------------------- -- 3) Convenience helpers ------------------------------------------------- function addon:ToggleMinimapButton() local db = self.db.profile.minimap db.hide = not db.hide if db.hide then icon:Hide(addonName) else icon:Show(addonName) end endThat’s literally it.
• LibDBIcon will anchor the button to Minimap, keep it on the edge and write the angle (0-360°) intodb.minimap.minimapPos.
• Dragging with the mouse automatically updates that number; upon /reload it will re-use the saved value.
• Callingaddon:ToggleMinimapButton()from your options panel lets the user hide/show it.
B) HAND-ROLLING IT (IF YOU REALLY MUST)
You’ll implement: create a frame, let it be dragged, compute angle, clamp it to the minimap shape, and save a SavedVariable yourself.
- SavedVariable in TOC
## SavedVariablesPerCharacter: MyAddonDB- Code
local addonName, addon = ... local defaults = { minimapAngle = 220 } -- Load / init saved vars local db = _G.MyAddonDB or {} for k,v in pairs(defaults) do if db[k] == nil then db[k] = v end end _G.MyAddonDB = db ------------------------------------------------- -- Create the button ------------------------------------------------- local btn = CreateFrame("Button", "MyAddon_MinimapButton", Minimap) btn:SetSize(32, 32) btn:SetMovable(true) btn:EnableMouse(true) btn:RegisterForDrag("LeftButton") btn:RegisterForClicks("LeftButtonUp", "RightButtonUp") -- texture btn.icon = btn:CreateTexture(nil, "BACKGROUND") btn.icon:SetAllPoints() btn.icon:SetTexture("Interface\\Icons\\INV_Misc_QuestionMark") ------------------------------------------------- -- Position helper ------------------------------------------------- local function PlaceButton(angle) local radius = (Minimap:GetWidth()/2) + 4 -- 4px offset so it touches the rim local x, y = math.cos(angle) * radius, math.sin(angle) * radius btn:ClearAllPoints() btn:SetPoint("CENTER", Minimap, "CENTER", x, y) end -- set initial pos PlaceButton(math.rad(db.minimapAngle)) ------------------------------------------------- -- Dragging ------------------------------------------------- local dragFrame local function OnUpdate(self) local mx, my = Minimap:GetCenter() local cx, cy = GetCursorPosition() local scale = UIParent:GetEffectiveScale() cx, cy = cx/scale, cy/scale local angle = math.atan2(cy - my, cx - mx) -- radians db.minimapAngle = math.deg(angle) -- save in degrees (easy to read) PlaceButton(angle) end btn:SetScript("OnDragStart", function(self) self:SetScript("OnUpdate", OnUpdate) end) btn:SetScript("OnDragStop", function(self) self:SetScript("OnUpdate", nil) end) ------------------------------------------------- -- Click behaviour ------------------------------------------------- btn:SetScript("OnClick", function(self, button) if button == "LeftButton" then print("Left click -> open main window") else print("Right click -> config") end end)Minimap shapes
If you want to be thorough, querylocal shape = GetMinimapShape and GetMinimapShape() or "ROUND"and clamp positions to the allowed segments (Blizzard sample function
isInZone). LibDBIcon already does that for you – yet another reason to use it!
WHICH ONE SHOULD I PICK?
• Want to write the least code and be future proof? → LibDataBroker + LibDBIcon (approach A).
• Writing a learning project with zero dependencies? → Hand-roll (approach B).Either way the end-user gets a button that:
✓ spawns on the rim, ✓ remembers its spot, ✓ can be dragged, ✓ doesn’t break SexyMap or square minimaps.Happy coding and have fun in Azeroth!
- Add the libs
youraddon
- User
i am specfically asking about retail wow in 2025
- Assistant
Below is the “2025-proof” answer for Retail WoW (11.x/The War Within and whatever comes next).
Nothing fundamental changed in Dragonflight → TWW regarding minimap buttons, and the community still converges on one solution:• Public-facing addon code = LibDataBroker-1.1 + LibDBIcon-1.0
• Internal Blizzard code = TemplateMinimalMinimapButtonTemplate, but it has no drag-around-the-edge logic and no persistence, so almost nobody ships it to users.In short: if you ship an addon in 2025, 99 % of the other addons your users have installed expect an LDB launcher, and UI replacements such as SexyMap/BasicMinimap still key off LibDBIcon.
────────────────────────────────────────
- Setting it up (Retail 2025, 11.x+) ──────────────────────────────────────── Directory:
MyAddon\ ├── MyAddon.toc ├── core.lua └── libs\ ├── LibStub\LibStub.lua ├── LibDataBroker-1.1\LibDataBroker-1.1.lua ├── LibDBIcon-1.0\LibDBIcon-1.0.lua └── AceDB-3.0\AceDB-3.0.lua ← only if you don’t already use Ace3Toc snippet (unchanged since 2008, still valid in 2025):
## Interface: 110100 # 11.1.0 (War Within beta) – bump every patch ## Title: MyAddon ## Author: You ## Version: 1.0.0 ## OptionalDeps: LibStub LibDataBroker-1.1 LibDBIcon-1.0 AceDB-3.0 libs\LibStub\LibStub.lua libs\LibDataBroker-1.1\LibDataBroker-1.1.lua libs\LibDBIcon-1.0\LibDBIcon-1.0.lua libs\AceDB-3.0\AceDB-3.0.lua core.lua──────────────────────────────────────── 2. Core.lua – 2025 minimal example ────────────────────────────────────────
local addonName, addon = ... ----------------------------------------------------------- -- SavedVariables (AceDB for brevity; any SV system works) ----------------------------------------------------------- addon.db = LibStub("AceDB-3.0"):New("MyAddonDB", { profile = { minimap = { hide = false, minimapPos = 215 } } }) ----------------------------------------------------------- -- 1) Create your DataBroker launcher ----------------------------------------------------------- local LDB = LibStub("LibDataBroker-1.1"):NewDataObject(addonName, { type = "launcher", icon = 134414, -- fileID for INV_Misc_QuestionMark OnClick = function(_, btn) if btn == "LeftButton" then addon:ToggleMainUI() elseif btn == "RightButton" then addon:OpenConfig() end end, OnTooltipShow = function(tt) tt:AddLine("MyAddon", 1, 1, 1) tt:AddLine("Left-click: Open window", 0.8, 0.8, 0.8) tt:AddLine("Right-click: Options", 0.8, 0.8, 0.8) end, }) ----------------------------------------------------------- -- 2) Register it with LibDBIcon (handles edge-snapping) ----------------------------------------------------------- local Icon = LibStub("LibDBIcon-1.0") Icon:Register(addonName, LDB, addon.db.profile.minimap) ----------------------------------------------------------- -- 3) Optional helper (checkbox in your options panel) ----------------------------------------------------------- function addon:SetMinimapShown(flag) addon.db.profile.minimap.hide = not flag if flag then Icon:Show(addonName) else Icon:Hide(addonName) end endWhat LibDBIcon still gives you in 2025 • Reads the current minimap shape via
GetMinimapShape(), supports ROUND, SQUARE, RING, etc.
• Lets the user drag the button; writes the polar angle (0-360) intodb.minimap.minimapPos.
• Saves “hidden” state.
• Inter-operates automatically with SexyMap, BasicMinimap, Blizz default, ElvUI, Tukui, etc.──────────────────────────────────────── 3. FAQ (11.x era) ──────────────────────────────────────── Q: Didn’t Blizzard add
MinimalMinimapButtonTemplatein DF?
A: They did. It’s nice for internal purposes (the template has hover highlight, push textures and adherence to the 18-pixel button size Standard). But it offers none of: • Rim-clamping
• Dragging
• Persistence across reloads
• Compatibility shims for non-round minimaps
Hence the ecosystem still ships LibDBIcon on top.Q: Are the libraries still maintained?
A: Yes. The repos on Curseforge and WoWI received DF & TWW TOC bumps. Their code is tiny (≈300 lines), so bit-rot is minimal.Q: Can I get rid of AceDB?
A: Replace the fewaddon.db.profile.minimapcalls with your own SavedVariables table. LibDBIcon only needs a table containingminimapPosandhide.Q: What about secure code in combat?
A: The launcher is a normal, clickableButtonand not secure; users can drag it in combat. That’s the accepted behaviour since classic TBC.──────────────────────────────────────── 4. If you must avoid external libs (rare) ──────────────────────────────────────── Blizzard hasn’t added anything new in 2024/2025, so the DIY recipe is still:
• CreateFrame("Button", …, Minimap, "BackdropTemplate"?)
• Size 32×32, register for drag.
• OnUpdate while dragging →atan2to find angle, store it, clamp to shape (see LibDBIcon’supdatePosition).
• On PLAYER_LOGIN call your positioning function with the stored angle.You can literally open LibDBIcon-1.0.lua (≈250 lines) and copy its logic.
──────────────────────────────────────── Bottom line for Retail 2025 ──────────────────────────────────────── Use LibDataBroker + LibDBIcon exactly like in 2023; nothing new in The War Within changes that recommendation. The snippet above is all you need for a modern, edge-hugging, drag-to-move minimap button that survives into 2026 without edits.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.