Fix the behaviour of snapping for the new bar positioning.

This commit is contained in:
Hendrik Leppkes
2009-02-21 15:42:57 +01:00
parent 571fe6cca4
commit 204ac6a671
2 changed files with 25 additions and 3 deletions
+23 -1
View File
@@ -43,10 +43,30 @@ do
self:SetBackdropBorderColor(0, 0, 0, 0) self:SetBackdropBorderColor(0, 0, 0, 0)
end end
local function barReAnchorForSnap(self)
local x,y,anchor = nil, nil, self:GetAnchor()
x = (self.config.position.growHorizontal == "RIGHT") and self:GetLeft() or self:GetRight()
y = (self.config.position.growVertical == "DOWN") and self:GetTop() or self:GetBottom()
self:ClearSetPoint(anchor, UIParent, "BOTTOMLEFT", x, y)
self:SetWidth(self.overlay:GetWidth())
self:SetHeight(self.overlay:GetHeight())
end
local function barReAnchorNormal(self)
local x,y,anchor = nil, nil, self:GetAnchor()
x = (self.config.position.growHorizontal == "RIGHT") and self:GetLeft() or self:GetRight()
y = (self.config.position.growVertical == "DOWN") and self:GetTop() or self:GetBottom()
self:ClearSetPoint(anchor, UIParent, "BOTTOMLEFT", x, y)
self:SetWidth(1)
self:SetHeight(1)
end
function barOnDragStart(self) function barOnDragStart(self)
local parent = self:GetParent() local parent = self:GetParent()
if Bartender4.db.profile.snapping then if Bartender4.db.profile.snapping then
local offset = 8 - (parent.config.padding or 0) local offset = 8 - (parent.config.padding or 0)
-- we need to re-anchor the bar and set its proper width for snaping to work properly
barReAnchorForSnap(parent)
Sticky:StartMoving(parent, snapBars, offset, offset, offset, offset) Sticky:StartMoving(parent, snapBars, offset, offset, offset, offset)
else else
parent:StartMoving() parent:StartMoving()
@@ -60,6 +80,7 @@ do
if parent.isMoving then if parent.isMoving then
if Bartender4.db.profile.snapping then if Bartender4.db.profile.snapping then
local sticky, stickTo = Sticky:StopMoving(parent) local sticky, stickTo = Sticky:StopMoving(parent)
barReAnchorNormal(parent)
--Bartender4:Print(sticky, stickTo and stickTo:GetName() or nil) --Bartender4:Print(sticky, stickTo and stickTo:GetName() or nil)
else else
parent:StopMovingOrSizing() parent:StopMovingOrSizing()
@@ -107,7 +128,6 @@ function Bartender4.Bar:Create(id, config, name)
local bar = setmetatable(CreateFrame("Frame", ("BT4Bar%s"):format(id), UIParent, "SecureHandlerStateTemplate"), Bar_MT) local bar = setmetatable(CreateFrame("Frame", ("BT4Bar%s"):format(id), UIParent, "SecureHandlerStateTemplate"), Bar_MT)
barregistry[id] = bar barregistry[id] = bar
table_insert(snapBars, bar)
bar.id = id bar.id = id
bar.name = name or id bar.name = name or id
@@ -120,6 +140,8 @@ function Bartender4.Bar:Create(id, config, name)
local overlay = CreateFrame("Button", bar:GetName() .. "Overlay", bar) local overlay = CreateFrame("Button", bar:GetName() .. "Overlay", bar)
bar.overlay = overlay bar.overlay = overlay
overlay.bar = bar
table_insert(snapBars, overlay)
overlay:EnableMouse(true) overlay:EnableMouse(true)
overlay:RegisterForDrag("LeftButton") overlay:RegisterForDrag("LeftButton")
overlay:RegisterForClicks("LeftButtonUp") overlay:RegisterForClicks("LeftButtonUp")
+2 -2
View File
@@ -19,7 +19,7 @@
This is a modified version by Nevcairiel for Bartender4 This is a modified version by Nevcairiel for Bartender4
------------------------------------------------------------------------------------]] ------------------------------------------------------------------------------------]]
local MAJOR, MINOR = "LibSimpleSticky-1.0", 1 local MAJOR, MINOR = "LibSimpleSticky-1.0", 2
local StickyFrames, oldminor = LibStub:NewLibrary(MAJOR, MINOR) local StickyFrames, oldminor = LibStub:NewLibrary(MAJOR, MINOR)
if not StickyFrames then return end if not StickyFrames then return end
@@ -136,7 +136,7 @@ function StickyFrames:GetUpdateFunc(frame, frameList, xoffset, yoffset, left, to
StickyFrames.sticky[frame] = nil StickyFrames.sticky[frame] = nil
for i = 1, #frameList do for i = 1, #frameList do
local v = frameList[i] local v = frameList[i]
if frame ~= v and not IsShiftKeyDown() and v:IsVisible() then if frame ~= v and frame ~= v:GetParent() and not IsShiftKeyDown() and v:IsVisible() then
if self:SnapFrame(frame, v, left, top, right, bottom) then if self:SnapFrame(frame, v, left, top, right, bottom) then
StickyFrames.sticky[frame] = v StickyFrames.sticky[frame] = v
break break