Quantcast Show and Hide frames on button click - WoWInterface
Thread Tools Display Modes
06-01-19, 10:21 PM   #1
twin_tania
A Defias Bandit
Join Date: Jun 2019
Posts: 2
Show and Hide frames on button click

I recently started to learn LUA and have been slowly picking a few stuff up and currently am stuck trying to progress further with what I want to do. So far I've learned to create a frame, add a button, and a couple widgets to it. I've also been able to turn the button into something like a macro using SetAttribute("macrotext1", "/wave") but I have been unsuccessful trying to figure out how to press a button that shows a new frame while hiding the current frame. Basically like almost turning a page.

I have managed to create a new frame by pressing the button but this creates a new frame outside of the existing one by doing something like this.

Code:
frame.sBtn:SetScript("OnClick", function()
		local newFrames = CreateFrame("Frame", "DragFrame", UIParent, "TranslucentFrameTemplate")
		newFrames:SetWidth(150)
		newFrames:SetHeight(320)
		newFrames:SetFrameStrata("MEDIUM")
		newFrames:SetPoint("CENTER",  UIParent, "CENTER",0,-20)			
end)
But as mentioned this only created a brand new frame. I would appreciate any help or if there is somewhere I can get this info that is easy to digest. I tried looking at other addons but the amount of code inside those folders is very overwhelming since I am not quite sure what I need to be looking for.
  Reply With Quote
06-01-19, 11:04 PM   #2
twin_tania
A Defias Bandit
Join Date: Jun 2019
Posts: 2
Ok, after finally taking a break my mind was finally able to make a bit more progress but it is still incomplete from what I am trying to do. I managed to show and hide on demand by pressing the button a secondary frame I created within the file doing the following.

Code:
local newFrameHidden = false
frame.sBtn:SetScript("OnClick", function(self)
				
	if newFrameHidden == false then
		newFrame:Hide()
		newFrameHidden = true
	else
		newFrame:Show()
		newFrameHidden = false
	end
	
end)
Now this is probably an ugly approach to someone who is experienced but so far is what I was able to think off at the moment.
  Reply With Quote
06-01-19, 11:28 PM   #3
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,106
Lua Code:
  1. frame.sBtn:SetScript("OnClick", function(self)
  2.     newFrame:SetShown(not newFrame:IsShown())  
  3. end)

Essentially, change the frame's shown state to what it is not now.

If you wanted to hide frame at the same time, add
Code:
self:GetParent():SetShown(not self:GetParent()IsShown())
to the above script. This assumes you have created the button (sBtn) with "frame" as its parent.

If you have a button on newFrame to toggle back, use the same script in its OnClick handler only replace newFrame with frame
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 06-02-19 at 06:15 AM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Show and Hide frames on button click

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