Thread Tools Display Modes
10-04-19, 09:47 AM   #1
Zax
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Aug 2006
Posts: 147
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).
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.
  Reply With Quote
10-04-19, 01:49 PM   #2
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
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.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
10-05-19, 02:58 AM   #3
Zax
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Aug 2006
Posts: 147
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"?
  Reply With Quote
10-06-19, 12:57 AM   #4
fyehu43
A Deviate Faerie Dragon
Join Date: Sep 2019
Posts: 12
Originally Posted by Zax View Post
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.
__________________
Shaman Raid Tank & expert in off-meta specs: Melee Hunter, Support Warrior, Priest Tank, etc...
  Reply With Quote
10-06-19, 02:52 PM   #5
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
It sounds like :StartSizing() adjusts the frame's size, not its scale.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
10-06-19, 04:33 PM   #6
MooreaTv
An Aku'mai Servant
AddOn Author - Click to view addons
Join Date: May 2019
Posts: 38
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)
  Reply With Quote
10-06-19, 09:27 PM   #7
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Originally Posted by MooreaTv View Post
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.)
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
10-07-19, 02:36 AM   #8
Zax
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Aug 2006
Posts: 147
Originally Posted by Seerah View Post
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.
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » Button to dynamically resize a parent frame?

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off