Download
(5 Kb)
Download
Updated: 04/10/14 10:24 PM
Pictures
File Info
Compatibility:
Live (1.0)
Updated:04/10/14 10:24 PM
Created:04/08/14 07:11 PM
Monthly downloads:21
Total downloads:2,312
Favorites:10
MD5:
LibDragWin
Version: 1.0 r2
by: Kith [More]
LibDragWin-1.0 is a library to aid addon authors in adding draggable frames to their UI. Each frame that the library attaches to can be dragged around the screen via the mouse as well as scaled using the mouse wheel with an optional ability for frames to "snap to grid" during movement.

How To Use:

-- Including the library with your addon --
You can either embed the library and LibStub in your addon and load them via your text file, or have the library installed standalone like any other addon.

If you embed the library, you may place this line in your loading text file incase a standalone version is installed:
Code:
## OptionalDependsOn: LibDragWin-1.0
If you are depending on the library being installed separately and are not embedding it, you must include this line in your loading text file:
Code:
## DependsOn: LibDragWin-1.0
Either way you choose, LibStub will ensure only one copy of the library (the newest revision) is loaded into memory.


-- Loading the library (with LibStub) and registering your addon (required) --
Lua Code:
  1. local LDW = LibStub("LibDragWin-1.0"):Register(addonName, callbackFunc)
  2.     -- addonName = string; a unique name for your addon registration
  3.     -- callbackFunc = function; the function to call with new position|scaling data
  4.     -- callbackFunc returns: frame, point, rel, relPoint, x, y, scale
  5.     -- returns an instance of the library table
The callback function you specify will be called during frame scaling as well as after user movement of a frame has finished. The position given will always be relative to GuiRoot's (the UI base frame) nearest edge or the center if none are close.
Lua Code:
  1. SampleAddon = {}
  2.  
  3. local LDW = LibStub("LibDragWin-1.0"):Register("SampleAddon", self.SavePosition)
  4.  
  5. function SampleAddon:SavePosition(frame, point, rel, relPoint, x, y, scale)
  6.     self.savedVars[frame] = {
  7.         point = point,
  8.         rel = rel,
  9.         relPoint = relPoint,
  10.         x = x,
  11.         y = y,
  12.         scale = scale
  13.     }
  14. end


** LibDragWin API **

-- Attaching a drag overlay to a target frame --
Lua Code:
  1. local drag = LDW:Attach(targetFrame, label)
  2.     -- targetFrame = frame; the frame to attach to for dragging|scaling
  3.     -- label = string; a label to show on the overlay for this frame (default: "", optional)
  4.     -- returns an instance of Attach owned by your library instance


-- Resyncing a drag overlay to its target frame --
Lua Code:
  1. LDW:Resync(targetFrame)
  2.     -- targetFrame = frame; the frame to resync to
This function allows the movement overlay to be resynced to its target's location when that target has been moved outside of the library; such as a reset-to-defaults setting in the parent addon.


-- Retrieving your addon reference --
Lua Code:
  1. local LDW = LibStub("LibDragWin-1.0"):Retrieve(addonName)
  2.     -- addonName = string; a unique name for your addon registraction
  3.     -- returns an existing instance of the library table


-- Retrieving a list of all attachments --
Lua Code:
  1. local allDrag = LDW:GetAttachments()
  2.     -- returns a table containing references to all attachments


-- Show (or Hide) all attachment overlays --
Lua Code:
  1. LDW:ShowAll()
  2. --OR--
  3. LDW:HideAll()


-- Set whether frames should snap-to-grid while being moved --
Lua Code:
  1. LDW:SnapToGrid(snap, gridSize)
  2.     -- snap = boolean; whether or not frames should snap-to-grid
  3.     -- gridSize = number; the size of the grid (default: 10, optional)


-- Set whether frames can be scaled using the MouseWheel --
Lua Code:
  1. LDW:AllowScaling(allow)
  2.     -- allow = boolean; whether frames can be scaled


** Attach API **
For control and access to individual attachment overlays.

-- Get the target frame of this attachment overlay --
Lua Code:
  1. local target = drag:GetTarget()
  2.     -- returns the frame being moved by this overlay


-- Show (or Hide) this attachment overlay --
Lua Code:
  1. drag:Show()
  2. --OR--
  3. drag:Hide()


-- Get elements of the attachment overlay --
Lua Code:
  1. local overlay = drag:GetOverlay()
  2.     -- returns a CT_BACKDROP control
  3.     -- for use when you wish to change the overlay appearance
  4. --AND--
  5. local label = drag:GetLabel()
  6.     -- returns a CT_LABEL control
  7.     -- for use when you wish to change the label appearance


-- Change the label of this attachment overlay --
Lua Code:
  1. drag:SetLabelText(text)
  2.     -- text = string; text to display on overlay (default: "", optional)
-- 1.0r2 --
  • Adding a new API, LibDragWin:Resync(targetFrame) to allow a resync of the overlay to the target's location in the event the two become desynced.
  • Internally set the lib.targets table to hold a reference to the new overlay as opposed to just an existence indication, this is to support the new Resync API.

-- 1.0r1 --
Release
Archived Files (1)
File Name
Version
Size
Uploader
Date
1.0 r1
5kB
04/08/14 07:11 PM


There have been no comments posted to this file.
Be the first to add one.



Category Jump: