Thread Tools Display Modes
09-09-24, 07:38 AM   #1
Zax
A Chromatic Dragonspawn
AddOn Author - Click to view addons
Join Date: Aug 2006
Posts: 164
New menu system with checkboxes?

Hello,

I would like to update the context popup menu of my SoundManager addon has it actually use the old deprecated menu system.



Though menu items looks like radio buttons in this old screen capture, items are checkboxes.

I tried to build a context popup menu with checkboxes (several can be checked or not) with this documentation:
https://www.townlong-yak.com/framexm...ationGuide.lua
But I can't manage the checkboxes' checked state.

I don't want tu use MenuUtil.CreateCheckboxContextMenu(ownerRegion, isSelected, setSelected, ...) because I would like to colorize some menu items.


Does anyone have a basic template for a context popup menu with checkboxes?
__________________
Zax - Addons List, not all maintained.
  Reply With Quote
09-09-24, 12:47 PM   #2
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 6,006
Not sure if this will help, I personally haven't coloured the text, but I am adjusting the font being used.

The OnClick part of my button that has the menu linked to it
Lua Code:
  1. nUI_MenuButton:SetScript("OnClick", function(self,button,down)
  2.     if button == "LeftButton" then
  3.        Settings.OpenToCategory(addonNS.Settings.Categories["Main"].Category:GetID())
  4.     elseif button == "RightButton" then  
  5.         MenuUtil.CreateContextMenu(UIParent, addonNS.Menu.Generate)
  6.     end
  7. end)



The first part of the addonNS.Menu.Generate function that creates the menu elements. Some are directly added here but the sub menus are in their own file.
No need to return
Lua Code:
  1. local title = rootDescription:CreateTitle(addonName .. " ( " .. nUI_Version .. " )")
  2.     addonNS.Menu.ApplyFontObject(title)
  3.    
  4.     rootDescription:CreateDivider()
  5.  
  6.  
  7. -- Sub Menu functions called here --
  8.  
  9.  
  10.     rootDescription:CreateDivider()
  11.  
  12.     local control = rootDescription:CreateCheckbox("No Hud",
  13.         function()
  14.             return nUI_Options.hud_nohud
  15.         end,
  16.         function()
  17.             addonNS.onNoHud()
  18.             hudMenu:SetEnabled(not nUI_Options.hud_nohud)
  19.         end
  20.     )
  21.     addonNS.Menu.ApplyFontObject(control)


This is the first part of one of the sub menus, the button you click to access the menu and then the controls that the 'button' creates. No need to return from any functions used for each sub menu. They are linked via the root description value.
Lua Code:
  1. local minimapMenu = rootDescription:CreateButton("Minimap")
  2.     minimapMenu:SetEnabled(nUI_Options.minimap)    
  3.     addonNS.Menu.ApplyFontObject(minimapMenu)
  4.    
  5.     local control = minimapMenu:CreateCheckbox("Round Map",
  6.        -- GetValue function
  7.         function()
  8.             return nUI_Options.round_map
  9.         end,
  10.        -- SetValue function
  11.         function()
  12.             addonNS.onMaskMap()
  13.         end
  14.     )
  15.     addonNS.Menu.ApplyFontObject(control)

And this is the font adjustment routine. You might need to do something similar to adjust the text.
Lua Code:
  1. addonNS.Menu.FontObject = "Number12FontOutline"
  2. addonNS.Menu.ApplyFontObject = function(control)
  3.     if not control then return end
  4.     control:AddInitializer(function(button, description, menu)
  5.         button.fontString:SetFontObject(addonNS.Menu.FontObject);
  6.     end)
  7. end

Hope that helps in some form.
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 70 - Resto Druid
Gamaliel - 70 - Disc Priest
Lienae - 70 - Resto Shaman
Velandryn - 70 - Prot Paladin (TR)
+ 5 at 60+
+ 2 at 40+

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

Last edited by Xrystal : 09-09-24 at 01:01 PM.
  Reply With Quote
09-09-24, 12:52 PM   #3
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 6,006
In regards to the checking of the checked state. In my usage, it wasn't needed as each click would set the variable, and I just checked the variable that was set.

As an example. This is submenu call for the hud options, but if the user chose to not display a hud, I disabled the options.
Lua Code:
  1. local hudMenu = addonNS.Menu.HudMenu(rootDescription)
  2.     hudMenu:SetEnabled(not nUI_Options.hud_nohud)

You can view what the end result of my menu code here:
https://drive.google.com/file/d/1zB8...ew?usp=sharing
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 70 - Resto Druid
Gamaliel - 70 - Disc Priest
Lienae - 70 - Resto Shaman
Velandryn - 70 - Prot Paladin (TR)
+ 5 at 60+
+ 2 at 40+

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

Last edited by Xrystal : 09-09-24 at 12:58 PM.
  Reply With Quote
09-10-24, 07:03 AM   #4
Zax
A Chromatic Dragonspawn
AddOn Author - Click to view addons
Join Date: Aug 2006
Posts: 164
Thanks for your code Xrystal.

I wanted to use the following example which works well for Radio Buttons:
Lua Code:
  1. local g_selectedIndex = 1;
  2. local function IsSelected(index) return index == g_selectedIndex; end
  3. local function SetSelected(index) g_selectedIndex = index; end
  4.  
  5. for index, thisDevice in ipairs(myDevicesTable) do
  6. local control = rootDescription:CreateRadio(thisDevice.name, IsSelected, SetSelected, index)
  7. end

But I had problems with the SetIsSelected() function so I wrote this and it seems to work:
Lua Code:
  1. local soundSettingsTbl = SndMgr.getDevicesNames()-- all devices indexes and names
  2.  
  3. local checkBoxesTbl = {}
  4. local function IsSelected(index) return checkBoxesTbl[index] == 1; end
  5. local function SetSelected(index) checkBoxesTbl[index] = abs(checkBoxesTbl[index] - 1); end
  6.  
  7. for index, thisDevice in ipairs(soundSettingsTbl.active) do -- list of "active" (checked) devices
  8.     checkBoxesTbl[index] = 1 -- initial state = active
  9.     local control = rootDescription:CreateCheckbox(thisDevice.name, IsSelected, SetSelected, index)
  10. end


__________________
Zax - Addons List, not all maintained.

Last edited by Zax : 09-10-24 at 08:30 AM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » New menu system with checkboxes?


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