From 204ac6a67119afad7191ca340475f411d36a579b Mon Sep 17 00:00:00 2001 From: Hendrik Leppkes Date: Sat, 21 Feb 2009 15:42:57 +0100 Subject: [PATCH] Fix the behaviour of snapping for the new bar positioning. --- Bar.lua | 24 +++++++++++++++++++++++- libs/SimpleSticky.lua | 4 ++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/Bar.lua b/Bar.lua index 9fabbef..2c5d3bc 100644 --- a/Bar.lua +++ b/Bar.lua @@ -43,10 +43,30 @@ do self:SetBackdropBorderColor(0, 0, 0, 0) 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) local parent = self:GetParent() if Bartender4.db.profile.snapping then 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) else parent:StartMoving() @@ -60,6 +80,7 @@ do if parent.isMoving then if Bartender4.db.profile.snapping then local sticky, stickTo = Sticky:StopMoving(parent) + barReAnchorNormal(parent) --Bartender4:Print(sticky, stickTo and stickTo:GetName() or nil) else 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) barregistry[id] = bar - table_insert(snapBars, bar) bar.id = 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) bar.overlay = overlay + overlay.bar = bar + table_insert(snapBars, overlay) overlay:EnableMouse(true) overlay:RegisterForDrag("LeftButton") overlay:RegisterForClicks("LeftButtonUp") diff --git a/libs/SimpleSticky.lua b/libs/SimpleSticky.lua index 43096ac..536622d 100644 --- a/libs/SimpleSticky.lua +++ b/libs/SimpleSticky.lua @@ -19,7 +19,7 @@ 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) if not StickyFrames then return end @@ -136,7 +136,7 @@ function StickyFrames:GetUpdateFunc(frame, frameList, xoffset, yoffset, left, to StickyFrames.sticky[frame] = nil for i = 1, #frameList do 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 StickyFrames.sticky[frame] = v break