Thread Tools Display Modes
10-08-23, 01:41 PM   #1
Blandros
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Sep 2023
Posts: 13
Use „MaximizeMinimizeButtonFrameTemplate“

Hi,

is there a way to use „MaximizeMinimizeButtonFrameTemplate“ for simply OnClick Show/Hide a Frame?
  Reply With Quote
10-08-23, 02:53 PM   #2
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,879
You can't mouse click a hidden frame (button) in order to show it and this type of frame should already have a close (click X to hide) button.

Or maybe you mean something else?
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 10-08-23 at 03:16 PM.
  Reply With Quote
10-09-23, 12:59 AM   #3
Blandros
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Sep 2023
Posts: 13
Originally Posted by Fizzlemizz View Post
Or maybe you mean something else?
I want to use it this way. But it doesnt work.

Lua Code:
  1. Controls.Open = CreateFrame("Button", nil, Keyboard, "MaximizeMinimizeButtonFrameTemplate ")
  2.     Controls.Open:SetSize(25, 25)
  3.     Controls.Open:SetPoint("RIGHT", Keyboard.Close, "LEFT", 0, 0)
  4.     Controls.Open:SetScript("OnClick", function(s)
  5.         if Controls:IsShown() then
  6.             Controls:Hide()
  7.         else
  8.             Controls:Show()
  9.         end
  10.     end)

The Button with the template „ MaximizeMinimizeButtonFrameTemplate“ does show up and is clickable. It does change the texture on click but doesnt do the script.

I want it so badly because its the only template fitting the default close button in style.

Last edited by Blandros : 10-09-23 at 01:05 AM.
  Reply With Quote
10-09-23, 05:16 AM   #4
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,934
I see you are using "Button" as it's type. But, based on Blizzards code it is a "Frame".

Lua Code:
  1. <Frame name="MaximizeMinimizeButtonFrameTemplate" parentKey="MaxMinButtonFrame" mixin="MaximizeMinimizeButtonFrameMixin" frameLevel="510" virtual="true">

Link to line in file :
https://github.com/tomrus88/Blizzard...15C2-L1615C155
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  Reply With Quote
10-09-23, 07:29 AM   #5
Blandros
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Sep 2023
Posts: 13
Originally Posted by Xrystal View Post
I see you are using "Button" as it's type. But, based on Blizzards code it is a "Frame".
Is it possible to use it as a frame and make it clickable?
Sorry for asking but i am new to coding and addon stuff
  Reply With Quote
10-09-23, 07:53 AM   #6
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,934
It should be just the case of changing "Button" to "Frame". But I haven't seen this frame personally to see how it works and looks out of the box. Code wise it already handles Minimize and Maximize functionality for the parent frame it is on.

I'll see if I can rig up an addon to see what it is like to make sure this is the case.


Okay, this is a really rough addon that shows how those buttons work with minimal coding.

This is the one and only lua file for a very simple addon. The issue is that where the minmax button is linked to the frame, once you hide it you can never show it again. But, you can resize the frame to suit. Which is what I did here. However, you can't resize to smaller than the minmax button or it will disappear anyway. The X close button in my example works straight out of the box and closes the frame automatically, never to be open again until the game is restarted.

I used a different trick with my portals addon by having a *header* frame that is always displayed and had it control whether the bigger portals frame *content* was displayed or not.

Lua Code:
  1. local displayFrame = CreateFrame("Frame",nil,nil,"BasicFrameTemplate")
  2. displayFrame:SetSize(200,100)
  3. displayFrame:SetPoint("CENTER")
  4.  
  5. local function OnMaximize()
  6.     displayFrame:SetSize(200,100)
  7. end
  8.  
  9. local function OnMinimize()
  10.     displayFrame:SetSize(30,30)
  11. end
  12.  
  13. displayFrame.MinMax = CreateFrame("Frame",nil,displayFrame, "MaximizeMinimizeButtonFrameTemplate")
  14. displayFrame.MinMax:SetPoint("TOPRIGHT",displayFrame,0,30)
  15.  
  16. displayFrame.MinMax:SetOnMaximizedCallback(OnMaximize)
  17. displayFrame.MinMax:SetOnMinimizedCallback(OnMinimize)
  18.  
  19. displayFrame:Show()
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818

Last edited by Xrystal : 10-09-23 at 08:26 AM.
  Reply With Quote
10-09-23, 10:11 AM   #7
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,879
Originally Posted by Blandros View Post
I want it so badly because its the only template fitting the default close button in style.
The UIPanelCloseButton template is the default close (X) button
Code:
<Button name="$parentCloseButton" inherits="UIPanelCloseButton">
that runs this function when clicked:
Lua Code:
  1. -- A bit ugly, we want the talent frame to display a dialog box in certain conditions.
  2. function UIPanelCloseButton_OnClick(self)
  3.     local parent = self:GetParent();
  4.     if parent then
  5.         local continueHide = true;
  6.         if parent.onCloseCallback then
  7.             continueHide = parent.onCloseCallback(self);
  8.         end
  9.  
  10.         if continueHide then
  11.             HideUIPanel(parent);
  12.         end
  13.     end
  14. end

It relies on the frame you want to hide being the direct parent of the button.

It hides the frame but as before, once hidden you can't click the close button with the mouse to show the parent frame again.

If you intend to leave the button on-screen (by parenting it to the "Keyboard" or some frame not parented to "Control") then you could replace it's OnClick script with the one you posted.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 10-09-23 at 11:16 AM.
  Reply With Quote
10-11-23, 02:43 AM   #8
Blandros
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Sep 2023
Posts: 13
Thank you @Fizzlemizz and @Xrystal
I am on the right track now. But i still got problems.

The frame "controls" is the header of the frame "keyboard". But when i open "keyboard" the frame "controls" dont show up. I need to click "MaximizeMinimizeButtonFrameTemplate" once so it shows up minimized.

How can i add "controls" as minimized when the frame "keyboard" loads/shows?

On the other hand i cant get the buttons etc. in the control frame to work with the flag "if maximizeFlag then".

Thank you for your replies and time!

Lua Code:
  1. local name, addon = ...
  2.  
  3. function addon:CreateKeyboard()
  4.     local Keyboard = CreateFrame("Frame", 'KeyUIMainFrame', UIParent, "TooltipBorderedFrameTemplate") -- the frame holding the keys
  5.     _G["Keyboard"] = Keyboard
  6.     tinsert(UISpecialFrames, "Keyboard")
  7.  
  8.     Keyboard:SetWidth(1099)
  9.     Keyboard:SetHeight(448)
  10.     Keyboard:SetBackdropColor(0, 0, 0, 0.9)
  11.     Keyboard:SetPoint("CENTER", UIParent, "CENTER", -300, 50)
  12.     Keyboard:SetScript("OnMouseDown", function(self) self:StartMoving() end)
  13.     Keyboard:SetScript("OnMouseUp", function(self) self:StopMovingOrSizing() end)
  14.     Keyboard:SetMovable(true) -- make the keyboard moveable
  15.     Keyboard:SetScale(1)
  16.     Keyboard:Hide()
  17.  
  18.     Keyboard.Close = CreateFrame("Button", nil, Keyboard, "UIPanelCloseButton")
  19.     Keyboard.Close:SetSize(25, 25)
  20.     Keyboard.Close:SetPoint("BOTTOMRIGHT", Keyboard, "TOPRIGHT", 0, 0)
  21.     Keyboard.Close:SetScript("OnClick", function(s) Keyboard:Hide() end)
  22.  
  23.     addon.keyboardFrame = Keyboard
  24.  
  25.     return Keyboard
  26. end
  27.  
  28. function addon:CreateControls()
  29.     local Controls = CreateFrame("Frame", 'KBControlsFrame', UIParent, "TooltipBorderedFrameTemplate")
  30.     _G["Controls"] = Controls
  31.     tinsert(UISpecialFrames, "Controls")
  32.     local Keyboard = addon.keyboardFrame
  33.     local Mouse = addon.MouseFrame
  34.     local modif = self.modif
  35.     Controls:SetBackdropColor(0, 0, 0, 1)
  36.     Controls:SetPoint("BOTTOM", Keyboard, "TOP", 0, -2)
  37.     Controls:Hide()
  38.  
  39.     local function OnMaximize()
  40.         Controls:SetHeight(100)
  41.         Controls:SetWidth(Keyboard:GetWidth())
  42.         maximizeFlag = true
  43.     end
  44.      
  45.     local function OnMinimize()
  46.         Controls:SetHeight(26)
  47.         Controls:SetWidth(Keyboard:GetWidth())
  48.         maximizeFlag = false
  49.     end
  50.  
  51.     Controls.MinMax = CreateFrame("Frame", nil, Keyboard, "MaximizeMinimizeButtonFrameTemplate")
  52.     Controls.MinMax:SetPoint("RIGHT", Keyboard.Close, "LEFT", 0, 0)
  53.     Controls.MinMax:SetOnMaximizedCallback(OnMaximize)
  54.     Controls.MinMax:SetOnMinimizedCallback(OnMinimize)
  55.  
  56.     if maximizeFlag then
  57.  
  58.         Controls.Close = CreateFrame("Button", nil, Controls, "UIPanelCloseButton")
  59.         Controls.Close:SetSize(20, 20)
  60.         Controls.Close:SetPoint("TOPRIGHT", Controls, "TOPRIGHT", -1, -1)
  61.         Controls.Close:SetScript("OnClick", function(s) Controls:Hide() end)
  62.  
  63.         Controls.Refresh = CreateFrame("Button", nil, Controls, "RefreshButtonTemplate")
  64.         Controls.Refresh:SetSize(24, 24)
  65.         Controls.Refresh:SetPoint("TOP", Controls.Close, "BOTTOM", 0, 4)
  66.         Controls.Refresh:SetScript("OnClick", function(s) addon:RefreshKeys() end)
  67.  
  68.         Controls.Slider = CreateFrame("Slider", "KUI_Slider1", Controls, "OptionsSliderTemplate")
  69.         Controls.Slider:SetMinMaxValues(0.5, 1)
  70.         Controls.Slider:SetValueStep(0.05)
  71.         Controls.Slider:SetValue(1)
  72.         _G[Controls.Slider:GetName().."Low"]:SetText("0.5")
  73.         _G[Controls.Slider:GetName().."High"]:SetText("1")
  74.         Controls.Slider:SetScript("OnValueChanged", function(self) Keyboard:SetScale(self:GetValue()) Controls:SetScale(self:GetValue()) end)
  75.         Controls.Slider:SetWidth(224)
  76.         Controls.Slider:SetHeight(20)
  77.         Controls.Slider:SetPoint("BOTTOMLEFT", Controls, "BOTTOMLEFT", 15, 55)
  78.  
  79.         Controls.ShiftCB = CreateFrame("CheckButton", "KeyBindShiftCB", Controls, "ChatConfigCheckButtonTemplate", BackdropTemplateMixin and "BackdropTemplate")
  80.         _G[Controls.ShiftCB:GetName().."Text"]:SetText("Shift")
  81.         Controls.ShiftCB:SetHitRectInsets(0, -40, 0, 0)
  82.         Controls.ShiftCB:SetPoint("TOP", Controls, "TOPLEFT", 26, -84)
  83.         Controls.ShiftCB:SetScript("OnClick", function(s)
  84.             if s:GetChecked() then
  85.                 modif.SHIFT = "SHIFT-"
  86.             else
  87.                 modif.SHIFT = ""
  88.             end
  89.             addon:RefreshKeys()
  90.         end)
  91.         Controls.ShiftCB:SetSize(30, 30)
  92.  
  93.         Controls.CtrlCB = CreateFrame("CheckButton", "KeyBindCtrlCB", Controls, "ChatConfigCheckButtonTemplate", BackdropTemplateMixin and "BackdropTemplate")
  94.         _G[Controls.CtrlCB:GetName().."Text"]:SetText("Ctrl")
  95.         Controls.CtrlCB:SetHitRectInsets(0, -40, 0, 0)
  96.         Controls.CtrlCB:SetPoint("TOP", Controls, "TOP", 0, -84)
  97.         Controls.CtrlCB:SetScript("OnClick", function(s)
  98.             if s:GetChecked() then
  99.                 modif.CTRL = "CTRL-"
  100.             else
  101.                 modif.CTRL = ""
  102.             end
  103.             addon:RefreshKeys()
  104.         end)
  105.         Controls.CtrlCB:SetSize(30, 30)
  106.  
  107.         Controls.AltCB = CreateFrame("CheckButton", "KeyBindAltCB", Controls, "ChatConfigCheckButtonTemplate", BackdropTemplateMixin and "BackdropTemplate")
  108.         _G[Controls.AltCB:GetName().."Text"]:SetText("Alt")
  109.         Controls.AltCB:SetHitRectInsets(0, -40, 0, 0)
  110.         Controls.AltCB:SetPoint("TOP", Controls, "TOPRIGHT", -46, -84)
  111.         Controls.AltCB:SetScript("OnClick", function(s)
  112.             if s:GetChecked() then
  113.                 modif.ALT = "ALT-"
  114.             else
  115.                 modif.ALT = ""
  116.             end
  117.             addon:RefreshKeys()
  118.         end)
  119.         Controls.AltCB:SetSize(30, 30)
  120.  
  121.     else
  122.  
  123.         if Controls.Close then
  124.             Controls.Close:Hide()
  125.         end
  126.    
  127.         if Controls.Refresh then
  128.             Controls.Refresh:Hide()
  129.         end
  130.  
  131.         if Controls.Slider then
  132.             Controls.Slider:Hide()
  133.         end
  134.  
  135.         if Controls.ShiftCB then
  136.             Controls.ShiftCB:Hide()
  137.         end
  138.  
  139.         if Controls.CtrlCB then
  140.             Controls.CtrlCB:Hide()
  141.         end
  142.        
  143.         if Controls.AltCB then
  144.             Controls.AltCB:Hide()
  145.         end
  146.        
  147.     end
  148.  
  149.     addon.controlsFrame = Controls
  150.     return Controls
  151. end
  Reply With Quote
10-11-23, 12:15 PM   #9
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,879
Given you haven 't added your startup code, I may be misunderstanding the question but I think this may be closer to what you're trying to do,

Lua Code:
  1. local name, addon = ...
  2.  
  3. function addon:CreateKeyboard()
  4.     local Keyboard = CreateFrame("Frame", 'KeyUIMainFrame', UIParent, "TooltipBorderedFrameTemplate") -- the frame holding the keys
  5. --    _G["Keyboard"] = Keyboard
  6.     tinsert(UISpecialFrames, "KeyUIMainFrame")
  7.  
  8.     Keyboard:SetWidth(1099)
  9.     Keyboard:SetHeight(448)
  10.     Keyboard:SetBackdropColor(0, 0, 0, 0.9)
  11.     Keyboard:SetPoint("CENTER", UIParent, "CENTER", -300, 50)
  12.  
  13.     Keyboard:SetScript("OnMouseDown", function(self) self:StartMoving() end)
  14.     Keyboard:SetScript("OnMouseUp", function(self) self:StopMovingOrSizing() end)
  15.     Keyboard:SetMovable(true) -- make the keyboard moveable
  16.     Keyboard:SetScale(1)
  17. --    Keyboard:Hide()
  18. --    Keyboard.Close = CreateFrame("Button", "$parentClose", Keyboard, "UIPanelCloseButton") -- Close button is on the Controls frame
  19. --    Keyboard.Close:SetSize(25, 25)
  20. --    Keyboard.Close:SetPoint("TOPRIGHT", Keyboard, "TOPRIGHT", 0, 0)
  21. --    Keyboard.Close:SetScript("OnClick", function(self) print(self:GetParent():GetName(), KBControlsFrame:GetParent():GetName()) end)
  22.  
  23.     addon.keyboardFrame = Keyboard
  24.  
  25.     return Keyboard
  26. end
  27.  
  28. function addon:CreateControls()
  29.     local Controls = CreateFrame("Frame", 'KBControlsFrame', UIParent, "TooltipBorderedFrameTemplate")
  30. --    _G["Controls"] = Controls
  31. --    tinsert(UISpecialFrames, "KBControlsFrame")
  32.     local Keyboard = addon.keyboardFrame
  33.     local Mouse = addon.MouseFrame
  34.     local modif = self.modif
  35.     Controls:SetBackdropColor(0, 0, 0, 1)
  36.     Controls:SetPoint("BOTTOM", Keyboard, "TOP", 0, -2)
  37. --    Controls:Hide()
  38.  
  39.     local function OnMaximize()
  40.         Controls:SetHeight(100)
  41.         Controls:SetWidth(Keyboard:GetWidth())
  42.         maximizeFlag = true
  43.     end
  44.      
  45.     local function OnMinimize()
  46.         Controls:SetHeight(26)
  47.         Controls:SetWidth(Keyboard:GetWidth())
  48.         maximizeFlag = false
  49.     end
  50.  
  51.     Controls.Close = CreateFrame("Button", "$parentClose", Controls, "UIPanelCloseButton")
  52.     Controls.Close:SetSize(20, 20)
  53.     Controls.Close:SetPoint("TOPRIGHT", -2, -2)
  54.     Controls.Close:SetScript("OnClick", function(s) KeyUIMainFrame:SetShown(not KeyUIMainFrame:IsShown())  end) -- Toggle the Keyboard frame show/hide
  55.  
  56.     Controls.MinMax = CreateFrame("Frame", "#parentMinMax", Controls, "MaximizeMinimizeButtonFrameTemplate")
  57.     Controls.MinMax:SetPoint("RIGHT", Controls.Close, "LEFT", 0, 0)
  58.     Controls.MinMax:SetOnMaximizedCallback(OnMaximize)
  59.     Controls.MinMax:SetOnMinimizedCallback(OnMinimize)
  60.    
  61.     if maximizeFlag then
  62.  
  63.         Controls.Refresh = CreateFrame("Button", nil, Controls, "RefreshButtonTemplate")
  64.         Controls.Refresh:SetSize(24, 24)
  65.         Controls.Refresh:SetPoint("TOP", Controls.Close, "BOTTOM", 0, 4)
  66.         Controls.Refresh:SetScript("OnClick", function(s) addon:RefreshKeys() end)
  67.  
  68.         Controls.Slider = CreateFrame("Slider", "KUI_Slider1", Controls, "OptionsSliderTemplate")
  69.         Controls.Slider:SetMinMaxValues(0.5, 1)
  70.         Controls.Slider:SetValueStep(0.05)
  71.         Controls.Slider:SetValue(1)
  72.         _G[Controls.Slider:GetName().."Low"]:SetText("0.5")
  73.         _G[Controls.Slider:GetName().."High"]:SetText("1")
  74.         Controls.Slider:SetScript("OnValueChanged", function(self) Keyboard:SetScale(self:GetValue()) Controls:SetScale(self:GetValue()) end)
  75.         Controls.Slider:SetWidth(224)
  76.         Controls.Slider:SetHeight(20)
  77.         Controls.Slider:SetPoint("BOTTOMLEFT", Controls, "BOTTOMLEFT", 15, 55)
  78.  
  79.         Controls.ShiftCB = CreateFrame("CheckButton", "KeyBindShiftCB", Controls, "ChatConfigCheckButtonTemplate", BackdropTemplateMixin and "BackdropTemplate")
  80.         _G[Controls.ShiftCB:GetName().."Text"]:SetText("Shift")
  81.         Controls.ShiftCB:SetHitRectInsets(0, -40, 0, 0)
  82.         Controls.ShiftCB:SetPoint("TOP", Controls, "TOPLEFT", 26, -84)
  83.         Controls.ShiftCB:SetScript("OnClick", function(s)
  84.             if s:GetChecked() then
  85.                 modif.SHIFT = "SHIFT-"
  86.             else
  87.                 modif.SHIFT = ""
  88.             end
  89.             addon:RefreshKeys()
  90.         end)
  91.         Controls.ShiftCB:SetSize(30, 30)
  92.  
  93.         Controls.CtrlCB = CreateFrame("CheckButton", "KeyBindCtrlCB", Controls, "ChatConfigCheckButtonTemplate", BackdropTemplateMixin and "BackdropTemplate")
  94.         _G[Controls.CtrlCB:GetName().."Text"]:SetText("Ctrl")
  95.         Controls.CtrlCB:SetHitRectInsets(0, -40, 0, 0)
  96.         Controls.CtrlCB:SetPoint("TOP", Controls, "TOP", 0, -84)
  97.         Controls.CtrlCB:SetScript("OnClick", function(s)
  98.             if s:GetChecked() then
  99.                 modif.CTRL = "CTRL-"
  100.             else
  101.                 modif.CTRL = ""
  102.             end
  103.             addon:RefreshKeys()
  104.         end)
  105.         Controls.CtrlCB:SetSize(30, 30)
  106.  
  107.         Controls.AltCB = CreateFrame("CheckButton", "KeyBindAltCB", Controls, "ChatConfigCheckButtonTemplate", BackdropTemplateMixin and "BackdropTemplate")
  108.         _G[Controls.AltCB:GetName().."Text"]:SetText("Alt")
  109.         Controls.AltCB:SetHitRectInsets(0, -40, 0, 0)
  110.         Controls.AltCB:SetPoint("TOP", Controls, "TOPRIGHT", -46, -84)
  111.         Controls.AltCB:SetScript("OnClick", function(s)
  112.             if s:GetChecked() then
  113.                 modif.ALT = "ALT-"
  114.             else
  115.                 modif.ALT = ""
  116.             end
  117.             addon:RefreshKeys()
  118.         end)
  119.         Controls.AltCB:SetSize(30, 30)
  120.  
  121.     else
  122.  
  123. --        if Controls.Close then
  124. --            Controls.Close:Hide()
  125. --        end
  126.    
  127.         if Controls.Refresh then
  128.             Controls.Refresh:Hide()
  129.         end
  130.  
  131.         if Controls.Slider then
  132.             Controls.Slider:Hide()
  133.         end
  134.  
  135.         if Controls.ShiftCB then
  136.             Controls.ShiftCB:Hide()
  137.         end
  138.  
  139.         if Controls.CtrlCB then
  140.             Controls.CtrlCB:Hide()
  141.         end
  142.        
  143.         if Controls.AltCB then
  144.             Controls.AltCB:Hide()
  145.         end
  146.        
  147.     end
  148.     Controls.MinMax.isMinimized = false -- Set the MinMax button & control frame size to Minimize
  149.     Controls.MinMax:Minimize() -- Set the MinMax button & control frame size to Minimize
  150.     Controls.MinMax:SetMaximizedLook() -- Set the MinMax button & control frame size to Minimize
  151.  
  152.     return Controls
  153. end
  154. addon:CreateKeyboard()
  155. local ctl = addon:CreateControls()
  156.  
  157. ctl:SetScript("OnEvent", function(self, isInitialLogin, isReloadingUi)
  158.     if isInitialLogin or isReloadingUi then
  159.         self:Show()
  160.         addon.keyboardFrame:Show()
  161.     end
  162. end)
  163. ctl:RegisterEvent("PLAYER_ENTERING_WORLD")

As an aside, a frame with a name automatically has that name added to the global table as a reference to the frame so:
Code:
_G["Keyboard"] = Keyboard
is not required as you can refer to the frame via KeyUIMainFrame
Code:
KeyUIMainFrame:Show()
which is why it is best to make sure your frame names are unique by doing something like prefixing them with your addon name.

Blizzard will use the simplest/common names for things (including frames and globals) so words like Keyboard or Controls are not recommended on their own.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 10-11-23 at 01:31 PM.
  Reply With Quote
10-11-23, 01:33 PM   #10
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,879
After a bit more reading of your code I redid mine above to action the MinMax and Close buttons.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
10-11-23, 04:06 PM   #11
Blandros
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Sep 2023
Posts: 13
I appreciate your input! Thank you, @Fizzlemizz.
The only remaining issue I have is that, even when the "maximizeFlag" is set to true, "Controls.Slider," "Controls.ShiftCB," "Controls.CtrlCB," and "Controls.AltCB" don't appear.

If I declare "local maximizeFlag = true" at the beginning of the code, they always become visible. Conversely, when I declare "local maximizeFlag = false," they remain hidden consistently. The print statement indicates that the value is changing.


Lua Code:
  1. local name, addon = ...
  2.  
  3. function addon:CreateKeyboard()
  4.     local Keyboard = CreateFrame("Frame", 'KeyUIMainFrame', UIParent, "TooltipBorderedFrameTemplate") -- the frame holding the keys
  5.     tinsert(UISpecialFrames, "KeyUIMainFrame")
  6.  
  7.     Keyboard:SetWidth(1099)
  8.     Keyboard:SetHeight(448)
  9.     Keyboard:SetBackdropColor(0, 0, 0, 0.9)
  10.     Keyboard:SetPoint("CENTER", UIParent, "CENTER", -300, 50)
  11.  
  12.     Keyboard:SetScript("OnMouseDown", function(self) self:StartMoving() end)
  13.     Keyboard:SetScript("OnMouseUp", function(self) self:StopMovingOrSizing() end)
  14.     Keyboard:SetMovable(true) -- make the keyboard moveable
  15.     Keyboard:SetScale(1)
  16.  
  17.     addon.keyboardFrame = Keyboard
  18.  
  19.     return Keyboard
  20. end
  21.  
  22. function addon:CreateControls()
  23.     local Controls = CreateFrame("Frame", 'KBControlsFrame', UIParent, "TooltipBorderedFrameTemplate")
  24.     tinsert(UISpecialFrames, "KBControlsFrame")
  25.     local Keyboard = addon.keyboardFrame
  26.     local modif = self.modif
  27.     Controls:SetBackdropColor(0, 0, 0, 1)
  28.     Controls:SetPoint("BOTTOM", Keyboard, "TOP", 0, -2)
  29.  
  30.     local function OnMaximize()
  31.         Controls:SetHeight(100)
  32.         Controls:SetWidth(Keyboard:GetWidth())
  33.         maximizeFlag = true
  34.         print("maximizeFlag is true")
  35.     end
  36.    
  37.     local function OnMinimize()
  38.         Controls:SetHeight(26)
  39.         Controls:SetWidth(Keyboard:GetWidth())
  40.         maximizeFlag = false
  41.         print("maximizeFlag is false")
  42.     end
  43.    
  44.     Controls.Close = CreateFrame("Button", "$parentClose", Controls, "UIPanelCloseButton")
  45.     Controls.Close:SetSize(22, 22)
  46.     Controls.Close:SetPoint("TOPRIGHT", -2, -2)
  47.     Controls.Close:SetScript("OnClick", function(s) KeyUIMainFrame:Hide() KBControlsFrame:Hide() end) -- Toggle the Keyboard frame show/hide
  48.  
  49.     Controls.MinMax = CreateFrame("Frame", "#parentMinMax", Controls, "MaximizeMinimizeButtonFrameTemplate")
  50.     Controls.MinMax:SetSize(22, 22)
  51.     Controls.MinMax:SetPoint("RIGHT", Controls.Close, "LEFT", 0, 0)
  52.     Controls.MinMax:SetOnMaximizedCallback(OnMaximize)
  53.     Controls.MinMax:SetOnMinimizedCallback(OnMinimize)
  54.  
  55.     Controls.Refresh = CreateFrame("Button", "#parentRefresh", Controls, "RefreshButtonTemplate")
  56.     Controls.Refresh:SetSize(24, 24)
  57.     Controls.Refresh:SetPoint("RIGHT", Controls.MinMax, "LEFT", 0, 0)
  58.     Controls.Refresh:SetScript("OnClick", function(s) addon:RefreshKeys() end)
  59.    
  60.     if maximizeFlag then
  61.  
  62.         Controls.Slider = CreateFrame("Slider", "KUI_Slider1", Controls, "OptionsSliderTemplate")
  63.         Controls.Slider:SetMinMaxValues(0.5, 1)
  64.         Controls.Slider:SetValueStep(0.05)
  65.         Controls.Slider:SetValue(1)
  66.         _G[Controls.Slider:GetName().."Low"]:SetText("0.5")
  67.         _G[Controls.Slider:GetName().."High"]:SetText("1")
  68.         Controls.Slider:SetScript("OnValueChanged", function(self) Keyboard:SetScale(self:GetValue()) Controls:SetScale(self:GetValue()) end)
  69.         Controls.Slider:SetWidth(224)
  70.         Controls.Slider:SetHeight(20)
  71.         Controls.Slider:SetPoint("BOTTOM", Controls, "BOTTOM", 0, 0)
  72.  
  73.         Controls.ShiftCB = CreateFrame("CheckButton", "KeyBindShiftCB", Controls, "ChatConfigCheckButtonTemplate")
  74.         _G[Controls.ShiftCB:GetName().."Text"]:SetText("Shift")
  75.         Controls.ShiftCB:SetHitRectInsets(0, -40, 0, 0)
  76.         Controls.ShiftCB:SetPoint("TOP", Controls, "TOPLEFT", 26, -84)
  77.         Controls.ShiftCB:SetScript("OnClick", function(s)
  78.             if s:GetChecked() then
  79.                 modif.SHIFT = "SHIFT-"
  80.             else
  81.                 modif.SHIFT = ""
  82.             end
  83.             addon:RefreshKeys()
  84.         end)
  85.         Controls.ShiftCB:SetSize(30, 30)
  86.  
  87.         Controls.CtrlCB = CreateFrame("CheckButton", "KeyBindCtrlCB", Controls, "ChatConfigCheckButtonTemplate")
  88.         _G[Controls.CtrlCB:GetName().."Text"]:SetText("Ctrl")
  89.         Controls.CtrlCB:SetHitRectInsets(0, -40, 0, 0)
  90.         Controls.CtrlCB:SetPoint("TOP", Controls, "TOP", 0, -84)
  91.         Controls.CtrlCB:SetScript("OnClick", function(s)
  92.             if s:GetChecked() then
  93.                 modif.CTRL = "CTRL-"
  94.             else
  95.                 modif.CTRL = ""
  96.             end
  97.             addon:RefreshKeys()
  98.         end)
  99.         Controls.CtrlCB:SetSize(30, 30)
  100.  
  101.         Controls.AltCB = CreateFrame("CheckButton", "KeyBindAltCB", Controls, "ChatConfigCheckButtonTemplate")
  102.         _G[Controls.AltCB:GetName().."Text"]:SetText("Alt")
  103.         Controls.AltCB:SetHitRectInsets(0, -40, 0, 0)
  104.         Controls.AltCB:SetPoint("TOP", Controls, "TOPRIGHT", -46, -84)
  105.         Controls.AltCB:SetScript("OnClick", function(s)
  106.             if s:GetChecked() then
  107.                 modif.ALT = "ALT-"
  108.             else
  109.                 modif.ALT = ""
  110.             end
  111.             addon:RefreshKeys()
  112.         end)
  113.         Controls.AltCB:SetSize(30, 30)
  114.  
  115.     else
  116.  
  117.         if Controls.Slider then
  118.             Controls.Slider:Hide()
  119.         end
  120.  
  121.         if Controls.ShiftCB then
  122.             Controls.ShiftCB:Hide()
  123.         end
  124.  
  125.         if Controls.CtrlCB then
  126.             Controls.CtrlCB:Hide()
  127.         end
  128.        
  129.         if Controls.AltCB then
  130.             Controls.AltCB:Hide()
  131.         end
  132.        
  133.     end
  134.    
  135.     --Controls.MinMax.isMinimized = true -- Set the MinMax button & control frame size to Minimize  -- this seems to have no effect?
  136.     Controls.MinMax:Minimize() -- Set the MinMax button & control frame size to Minimize
  137.     Controls.MinMax:SetMaximizedLook() -- Set the MinMax button & control frame size to Minimize
  138.  
  139.     addon.controlsFrame = KBControlsFrame
  140.  
  141.     return Controls
  142. end
  Reply With Quote
10-11-23, 04:56 PM   #12
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,879
Because you have the
Lua Code:
  1. if maximizeFlag then
  2.          Controls.Slider = CreateFrame("Slider", "KUI_Slider1", Controls, "OptionsSliderTemplate")
  3.          --...
  4. end
inside
Code:
function addon:CreateControls()
then maximizeFlag has to set BEFORE you call the function and create the Controls frame. I can only guess you are doing that when the addon loads.

That said, you only want to call the function once as frames (widgets in general including Textures and FontStrings) are not destroyed (deleted, removed...) until you exit the game (or logout or /reload) so once created you Show/Hide them as required.

Possibly what you want to do is
Lua Code:
  1. local function OnMaximize()
  2.         Controls:SetHeight(100)
  3.         Controls:SetWidth(Keyboard:GetWidth())
  4.         maximizeFlag = true
  5.         print("maximizeFlag is true")
  6.         if not Controls.Slider then -- if his is the first time maximized then create the slider etc.
  7.                 Controls.Slider = CreateFrame("Slider", "KUI_Slider1", Controls, "OptionsSliderTemplate")
  8.                 -- and all the other stuff
  9.         end
  10.         Controls.Slider:Show()
  11.         -- show all the other controls on maximize
  12. end
  13. local function OnMinimize()
  14.         Controls:SetHeight(26)
  15.         Controls:SetWidth(Keyboard:GetWidth())
  16.         maximizeFlag = false
  17.         print("maximizeFlag is false")
  18.         Controls.Slider:Hide()
  19.         -- hide all the other controls on minimize
  20. end

It might all look something like:
Lua Code:
  1. local name, addon = ...
  2.      
  3.     function addon:CreateKeyboard()
  4.         local Keyboard = CreateFrame("Frame", 'KeyUIMainFrame', UIParent, "TooltipBorderedFrameTemplate") -- the frame holding the keys
  5.         tinsert(UISpecialFrames, "KeyUIMainFrame")
  6.      
  7.         Keyboard:SetWidth(1099)
  8.         Keyboard:SetHeight(448)
  9.         Keyboard:SetBackdropColor(0, 0, 0, 0.9)
  10.         Keyboard:SetPoint("CENTER", UIParent, "CENTER", -300, 50)
  11.      
  12.         Keyboard:SetScript("OnMouseDown", function(self) self:StartMoving() end)
  13.         Keyboard:SetScript("OnMouseUp", function(self) self:StopMovingOrSizing() end)
  14.         Keyboard:SetMovable(true) -- make the keyboard moveable
  15.         Keyboard:SetScale(1)
  16.      
  17.         addon.keyboardFrame = Keyboard
  18.      
  19.         return Keyboard
  20.     end
  21.      
  22.     function addon:CreateControls()
  23.         local Controls = CreateFrame("Frame", 'KBControlsFrame', UIParent, "TooltipBorderedFrameTemplate")
  24.         tinsert(UISpecialFrames, "KBControlsFrame")
  25.         local Keyboard = addon.keyboardFrame
  26.         local modif = self.modif
  27.         Controls:SetBackdropColor(0, 0, 0, 1)
  28.         Controls:SetPoint("BOTTOM", Keyboard, "TOP", 0, -2)
  29.      
  30.         local function OnMaximize()
  31.             Controls:SetHeight(100)
  32.             Controls:SetWidth(Keyboard:GetWidth())
  33.             maximizeFlag = true
  34.             print("maximizeFlag is true")
  35.             if not Controls.Slider then
  36.                 Controls.Slider = CreateFrame("Slider", "KUI_Slider1", Controls, "OptionsSliderTemplate")
  37.                 Controls.Slider:SetMinMaxValues(0.5, 1)
  38.                 Controls.Slider:SetValueStep(0.05)
  39.                 Controls.Slider:SetValue(1)
  40.                 _G[Controls.Slider:GetName().."Low"]:SetText("0.5")
  41.                 _G[Controls.Slider:GetName().."High"]:SetText("1")
  42.                 Controls.Slider:SetScript("OnValueChanged", function(self) Keyboard:SetScale(self:GetValue()) Controls:SetScale(self:GetValue()) end)
  43.                 Controls.Slider:SetWidth(224)
  44.                 Controls.Slider:SetHeight(20)
  45.                 Controls.Slider:SetPoint("BOTTOM", Controls, "BOTTOM", 0, 0)
  46.      
  47.                 Controls.ShiftCB = CreateFrame("CheckButton", "KeyBindShiftCB", Controls, "ChatConfigCheckButtonTemplate")
  48.                 _G[Controls.ShiftCB:GetName().."Text"]:SetText("Shift")
  49.                 Controls.ShiftCB:SetHitRectInsets(0, -40, 0, 0)
  50.                 Controls.ShiftCB:SetPoint("TOP", Controls, "TOPLEFT", 26, -84)
  51.                 Controls.ShiftCB:SetScript("OnClick", function(s)
  52.                     if s:GetChecked() then
  53.                         modif.SHIFT = "SHIFT-"
  54.                     else
  55.                         modif.SHIFT = ""
  56.                     end
  57.                     addon:RefreshKeys()
  58.                 end)
  59.                 Controls.ShiftCB:SetSize(30, 30)
  60.      
  61.                 Controls.CtrlCB = CreateFrame("CheckButton", "KeyBindCtrlCB", Controls, "ChatConfigCheckButtonTemplate")
  62.                 _G[Controls.CtrlCB:GetName().."Text"]:SetText("Ctrl")
  63.                 Controls.CtrlCB:SetHitRectInsets(0, -40, 0, 0)
  64.                 Controls.CtrlCB:SetPoint("TOP", Controls, "TOP", 0, -84)
  65.                 Controls.CtrlCB:SetScript("OnClick", function(s)
  66.                     if s:GetChecked() then
  67.                         modif.CTRL = "CTRL-"
  68.                     else
  69.                         modif.CTRL = ""
  70.                     end
  71.                     addon:RefreshKeys()
  72.                 end)
  73.                 Controls.CtrlCB:SetSize(30, 30)
  74.      
  75.                 Controls.AltCB = CreateFrame("CheckButton", "KeyBindAltCB", Controls, "ChatConfigCheckButtonTemplate")
  76.                 _G[Controls.AltCB:GetName().."Text"]:SetText("Alt")
  77.                 Controls.AltCB:SetHitRectInsets(0, -40, 0, 0)
  78.                 Controls.AltCB:SetPoint("TOP", Controls, "TOPRIGHT", -46, -84)
  79.                 Controls.AltCB:SetScript("OnClick", function(s)
  80.                     if s:GetChecked() then
  81.                         modif.ALT = "ALT-"
  82.                     else
  83.                         modif.ALT = ""
  84.                     end
  85.                     addon:RefreshKeys()
  86.                 end)
  87.                 Controls.AltCB:SetSize(30, 30)
  88.              end
  89.              Controls.Slider:Show()
  90.              Controls.ShiftCB:Show()
  91.              Controls.CtrlCB:Show()
  92.              Controls.AltCB:Show()
  93.  
  94.         end
  95.        
  96.         local function OnMinimize()
  97.             Controls:SetHeight(26)
  98.             Controls:SetWidth(Keyboard:GetWidth())
  99.             maximizeFlag = false
  100.             print("maximizeFlag is false")
  101.             if Controls.Slider then
  102.                 Controls.Slider:Hide()
  103.                 Controls.ShiftCB:Hide()
  104.                 Controls.CtrlCB:Hide()
  105.                 Controls.AltCB:Hide()
  106.             end
  107.         end
  108.        
  109.         Controls.Close = CreateFrame("Button", "$parentClose", Controls, "UIPanelCloseButton")
  110.         Controls.Close:SetSize(22, 22)
  111.         Controls.Close:SetPoint("TOPRIGHT", -2, -2)
  112.         Controls.Close:SetScript("OnClick", function(s) KeyUIMainFrame:Hide() KBControlsFrame:Hide() end) -- Toggle the Keyboard frame show/hide
  113.      
  114.         Controls.MinMax = CreateFrame("Frame", "#parentMinMax", Controls, "MaximizeMinimizeButtonFrameTemplate")
  115.         Controls.MinMax:SetSize(22, 22)
  116.         Controls.MinMax:SetPoint("RIGHT", Controls.Close, "LEFT", 0, 0)
  117.         Controls.MinMax:SetOnMaximizedCallback(OnMaximize)
  118.         Controls.MinMax:SetOnMinimizedCallback(OnMinimize)
  119.      
  120.         Controls.Refresh = CreateFrame("Button", "#parentRefresh", Controls, "RefreshButtonTemplate")
  121.         Controls.Refresh:SetSize(24, 24)
  122.         Controls.Refresh:SetPoint("RIGHT", Controls.MinMax, "LEFT", 0, 0)
  123.         Controls.Refresh:SetScript("OnClick", function(s) addon:RefreshKeys() end)
  124.        
  125.        
  126.         --Controls.MinMax.isMinimized = true -- Set the MinMax button & control frame size to Minimize  -- this seems to have no effect?
  127.         Controls.MinMax:Minimize() -- Set the MinMax button & control frame size to Minimize
  128.         Controls.MinMax:SetMaximizedLook() -- Set the MinMax button & control frame size to Minimize
  129.      
  130.         addon.controlsFrame = KBControlsFrame
  131.      
  132.         return Controls
  133.     end
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 10-11-23 at 07:12 PM.
  Reply With Quote
10-20-23, 05:35 PM   #13
Blandros
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Sep 2023
Posts: 13
@Fizzlemizz thank you! It worked like a charm.

https://legacy.curseforge.com/wow/addons/keyui/files/4808314
(I hope linking this i allowed.)
Shoutout once again to you. Thank you!
  Reply With Quote
10-21-23, 01:15 PM   #14
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,879
Now what you are doing makes sense . Looks good!
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Use „MaximizeMinimizeButtonFrameTemplate“


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