Button Placement

Naive question here but here goes: I have a window with 4 buttons along the bottom edge. I want them to be equally placed and to remain so when the window is resized. Put more explicitly, button 1 and button 4 would be positioned at the corners (i.e., button 1 at BOTTOMLEFT, 10,10 and button 4 at BOTTOMRIGHT, 10,10) while buttons 2 and 3 would be positioned equidistant from the corners and each other.

I seem unable to grok gamepedia’s description of Region:SetPoint() and have been experimenting with all kinds of placements and offsets, but when I resize the window the buttons do not remain equally spaced. Here, for example, is a code fragment from my AddOn that places the buttons approximately the way I like. But when I resize the window the button’s placements all go to hell. :woozy_face:

createSelectButton(f, “BOTTOMRIGHT”, -30, 10)
createPrintButton(f, “BOTTOMRIGHT”, -215, 10)
createSummaryButton(f, “BOTTOM”, 0, 10)
createClearButton(f, “BOTTOMLEFT”, 220, 10)
createResetButton(f, “BOTTOMLEFT”, 10, 10)

Does some combination of placements and offsets exist that would cause the buttons 2 and 3 to remain proportionally the same distance apart when the window was resized?

Thanks,

Change the two middle button placements in the frames OnSizeChanged script

Thanks, again, Fizzlemizz, but my frames do not use OnSizeChanged script (I didn’t even know about it :roll_eyes: ). So, I looked up OnSizeChanged on gamepedia (under UIHANDLER) and… no joy. The page was not there.

So, I’m assuming I’ll have to write a handler that will recalculate the positions of the two buttons according to the size of the parent frame… something along the lines of…

f:SetScript(“OnSizeChanged”, function (self )
if self.isResizing then
local newWidth = self:GetWidth()
local interval = newWidth / 3
– use the interval to calculate the new x offsets
end

is this about right? Or is there a simpler approach?

Cheers,

frame:SetScript("OnSizeChanged", function(self)
    local size = self:GetWidth()/4
    PrintButton:ClearAllPoints()
    ClearButton:ClearAllPoints()
    PrintButton:Setpoint("BOTTOM", self,  -size, 10)
    ClearButton:Setpoint("BOTTOM", self,  size, 10)
end) 

Something like that.

Edited: for the Y offset.

Just wanted to close the loop. Your suggestion worked just fine and the buttons remain equally during/after resizing. Thanks, again, Fizzlemizz.

Cheers,