WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   General Authoring Discussion (https://www.wowinterface.com/forums/forumdisplay.php?f=20)
-   -   Button to dynamically resize a parent frame? (https://www.wowinterface.com/forums/showthread.php?t=57575)

Zax 10-04-19 09:47 AM

Button to dynamically resize a parent frame?
 
Hello,

I'm trying to make a handler in the bottom right of a main frame in order to dynamically resize this frame and its contents.
With the following script, only the main frame is resized, not its content (all its children, like subframes, buttons, etc). :confused:
I guess I forgot something important...
Code:

frame:SetClampedToScreen(true)
frame:SetMovable(true)
frame:SetUserPlaced(true)
frame:SetResizable(true)
frame:SetMaxResize(frame.width * 1.5, frame.height * 1.5)
frame:SetMinResize(frame.width / 1.5, frame.height / 1.5)

local handlerBtn = CreateFrame("Button", "$parent_handler", frame)
handlerBtn:SetSize(16, 16)
handlerBtn:SetPoint("TOPLEFT", frame, "BOTTOMRIGHT", -16, 16)
local texture = handlerBtn:CreateTexture(nil,"BACKGROUND")
texture:SetAllPoints(true)
texture:SetColorTexture(1, 0, 0, 0.6)
handlerBtn.texture = texture

handlerBtn:EnableMouse(true)
handlerBtn:SetScript("OnMouseDown", function(self, mouse)
        if (mouse == "LeftButton" and not frame.isResizing) then
                self:GetParent().isResizing = true;
                self:GetParent():StartSizing("BOTTOMRIGHT")
        end
end)
handlerBtn:SetScript("OnMouseUp", function(self, mouse)
        if (mouse == "LeftButton" and frame.isResizing) then
                self:GetParent():StopMovingOrSizing()
                self:GetParent().isResizing = false
        end
end)

Thank you.

Seerah 10-04-19 01:49 PM

If you were changing its scale, it would perform as you wish it to. Children inherit the scale of their parent. But if you're changing the width/height, you're going to have to do that manually on the children inside.

/edit: There is a slight workaround for this, but I'm not certain if it will work for what your frame looks like. If a child has two anchor points set, then it will resize accordingly.

Zax 10-05-19 02:58 AM

Sorry, I wasn't very clear: I would like to scale the frame and its content.
It actually works as intended if I manually perform:
Code:

frame:SetScale(0.8);
But my handler button doesn't scale the frame's content. Maybe it's due to a child that could be something like "locked"?

fyehu43 10-06-19 12:57 AM

Quote:

Originally Posted by Zax (Post 334153)
Sorry, I wasn't very clear: I would like to scale the frame and its content.
It actually works as intended if I manually perform:
Code:

frame:SetScale(0.8);
But my handler button doesn't scale the frame's content. Maybe it's due to a child that could be something like "locked"?

yup seems like something isn't tied properly to its origin.

Seerah 10-06-19 02:52 PM

It sounds like :StartSizing() adjusts the frame's size, not its scale.

MooreaTv 10-06-19 04:33 PM

You can add your own scaling on mouse wheel?
(that's what I do for some frames; it's just a bit complicated with text as it doesn't scale the same way as non text so you need to recalculate string width to keep for instance a perfect distance between text and border)

Seerah 10-06-19 09:27 PM

Quote:

Originally Posted by MooreaTv (Post 334171)
so you need to recalculate string width

Have you tried using multiple anchor points? (For example, :SetPoint() the left of your fontstring to the left of your frame and the right of the fontstring to the right of the frame.)

Zax 10-07-19 02:36 AM

Quote:

Originally Posted by Seerah (Post 334169)
It sounds like :StartSizing() adjusts the frame's size, not its scale.

Right! I just realised this point. :(

@MooreaTv: yep, that what I finally did, but the effect is a little creepy.
Anyhow, thanks for your answers.


All times are GMT -6. The time now is 04:35 PM.

vBulletin © 2020, Jelsoft Enterprises Ltd
© 2004 - 2020 MMOUI