-
Posted by goranaws on Mon, 31 Jan 2011 02:14:59
I'm trying to make a checkbutton that will completely hide a Micro Menu Button. The idea is that the button will be hidden without leaving a blank space where the button is usually placed. I have succeeded in making the checkbutton appear in game, but it does not function as intended. Pretty sure I've messed it up completely. The code below is what I have so far...
function MenuBar:ToggleCharacter(enable) CharacterMicroButton:SetParent(MainMenuBar) end local showCharacter = p:NewCheckButton(L.AlwaysShowCharacter) showCharacter:SetScript('OnClick', function(self) self:GetParent(CharacterMicroButton).owner:RemoveButton(self:GetChecked()) end) showCharacter:SetScript('OnShow', function(self) self:SetChecked(self:GetParent(CharacterMicroButton).owner.sets.ToggleCharacter) end) end
-
Posted by jnwhiteh on Mon, 31 Jan 2011 08:57:43
Hrm. You'd also have to move and reanchor the other buttons, so I'm not entirely sure what you're trying to do with this specific code. Are the checkbuttons always visible? Do you have code to reposition and reanchor the bar to fill in the spaces?
-
Posted by goranaws on Tue, 01 Feb 2011 18:21:45
I'll post the full LUA file... if that will help. Keep in mind the checkbutton it is supposed change the original parent of the CharacterMicroButton to a Parent frame that is already set to be hidden by the addon this one is dependent on.
-
Posted by goranaws on Tue, 01 Feb 2011 18:30:29
local L = LibStub('AceLocale-3.0') CreateFrame("Frame", "MenuBar", MainMenuBar); CharacterMicroButton:SetParent(MenuBar); SpellbookMicroButton:SetParent(MenuBar); QuestLogMicroButton:SetParent(MenuBar); GuildMicroButton:SetParent(MenuBar); TalentMicroButton:SetParent(MenuBar); AchievementMicroButton:SetParent(MenuBar); PVPMicroButton:SetParent(MenuBar); LFDMicroButton:SetParent(MenuBar); MainMenuMicroButton:SetParent(MenuBar); HelpMicroButton:SetParent(MenuBar); local menuButtons do local loadButtons = function(...) menuButtons = {} for i = 1, select('#', ...) do local b = select(i, ...) local name = b:GetName() if name and name:match('(%w+)MicroButton$') then table.insert(menuButtons, b) end end end loadButtons(_G['MenuBar']:GetChildren()) end --[[ Menu Bar ]]-- local MenuBar = Dominos:CreateClass('Frame', Dominos.Frame) Dominos.MenuBar = MenuBar function MenuBar:New() local f = self.super.New(self, 'menu') f:LoadButtons() f:Layout() return f end function MenuBar:GetDefaults() return { point = 'BOTTOMRIGHT', x = -244, y = 0, } end function MenuBar:NumButtons() return #menuButtons end function MenuBar:AddButton(i) local b = menuButtons[i] if b then b:SetParent(self.header) b:Show() self.buttons[i] = b end end function MenuBar:RemoveButton(i) local b = self.buttons[i] if b then b:SetParent(nil) b:Hide() self.buttons[i] = nil end end --override, because the menu bar has weird button sizes local WIDTH_OFFSET = 2 local HEIGHT_OFFSET = 20 function MenuBar:Layout() if #self.buttons > 0 then local cols = min(self:NumColumns(), #self.buttons) local rows = ceil(#self.buttons / cols) local pW, pH = self:GetPadding() local spacing = self:GetSpacing() local b = self.buttons[1] local w = b:GetWidth() + spacing - WIDTH_OFFSET local h = b:GetHeight() + spacing - HEIGHT_OFFSET for i,b in pairs(self.buttons) do local col = (i-1) % cols local row = ceil(i / cols) - 1 b:ClearAllPoints() b:SetPoint('TOPLEFT', w*col + pW, -(h*row + pH) + HEIGHT_OFFSET) end self:SetWidth(max(w*cols - spacing + pW*2 + WIDTH_OFFSET, 8)) self:SetHeight(max(h*ceil(#self.buttons/cols) - spacing + pH*2, 8)) else self:SetWidth(30); self:SetHeight(30) end end local function AddLayoutPanel(menu) local p = menu:NewPanel(LibStub('AceLocale-3.0'):GetLocale('Dominos-Config').Layout) p:NewOpacitySlider() p:NewFadeSlider() p:NewScaleSlider() p:NewPaddingSlider() p:NewSpacingSlider() p:NewColumnsSlider() function MenuBar:ToggleCharacter(enable) CharacterMicroButton:SetParent(MainMenuBarArtFrame) end local showCharacter = p:NewCheckButton(L.AlwaysShowCharacter) showCharacter:SetScript('OnClick', function(self) self:GetParent(CharacterMicroButton).owner:RemoveButton(self:GetChecked()) end) showCharacter:SetScript('OnShow', function(self) self:SetChecked(self:GetParent(CharacterMicroButton).owner.sets.ToggleCharacter) end) end end function MenuBar:CreateMenu() local menu = Dominos:NewMenu(self.id) AddLayoutPanel(menu) self.menu = menu end
-
Posted by jnwhiteh on Wed, 16 Feb 2011 11:11:29
I don't really know Dominos at all, so I'm not sure how to help you with this without needing to go through a whole bunch of research. If you can come up with a minimally reproducable test case that doesn't rely on other libraries (Ace) or addons (Dominos) I may be able to help. Just make a checkbutton and have it do what you want it to do.