some reordering and more options

This commit is contained in:
Hendrik Leppkes
2007-12-09 11:45:03 +00:00
parent 675a871ada
commit 587c066fe5
4 changed files with 190 additions and 99 deletions
+160 -12
View File
@@ -6,9 +6,130 @@ Bartender4.ActionBar = ActionBar
local math_floor = math.floor
--[[
Bar Prototype Functions
]]
--[[===================================================================================
ActionBar Options
===================================================================================]]--
local module
-- option utilty functions
local getBar, optGetter, optSetter, optionMap, callFunc
do
-- maps option keys to function names
optionMap = {
padding = "Padding",
buttons = "Buttons",
rows = "Rows",
}
-- retrieves a valid bar object from the modules actionbars table
function getBar(id)
if not module then
module = Bartender4:GetModule("ActionBars")
end
local bar = module.actionbars[tonumber(id)]
assert(bar, "Invalid bar id in options table.")
return bar
end
-- calls a function on the bar
function callFunc(bar, type, option, ...)
local func = type .. (optionMap[option] or option)
assert(bar[func], "Invalid get/set function."..func)
return bar[func](bar, ...)
end
-- universal function to get a option
function optGetter(info)
local bar = getBar(info[2])
local option = info[#info]
return callFunc(bar, "Get", option)
end
-- universal function to set a option
function optSetter(info, ...)
local bar = getBar(info[2])
local option = info[#info]
return callFunc(bar, "Set", option, ...)
end
end
local baroptions
-- returns the option table used for all action bars
-- creates it, if the first time called
-- the Universal Bar option table is merged into this, alot of stuff gets inherited.
function ActionBar:GetOptionsTable()
if not baroptions then
baroptions = Bartender4:Merge({
general = {
-- type = inherited
-- name = inherited
-- cmdInline = inherited
order = 1,
args = {
style = {
-- type = inherited
-- name = inherited
-- inline = inherited
args = {
padding = {
type = "range",
name = "Padding",
desc = "Configure the padding of the buttons.",
min = -10, max = 20, step = 1,
set = optSetter,
get = optGetter,
},
},
},
layout = {
type = "group",
name = "Layout",
inline = true,
order = 10,
set = optSetter,
get = optGetter,
args = {
buttons = {
name = "Buttons",
desc = "Number of buttons.",
type = "range",
min = 1, max = 12, step = 1,
},
rows = {
name = "Rows",
desc = "Number of rows.",
type = "range",
min = 1, max = 12, step = 1,
},
},
}
},
},
swap = {
type = "group",
name = "Page Swapping",
cmdInline = true,
order = 2,
args = {},
},
align = {
-- type = inherited
-- name = inherited
-- cmdInline = inherited
order = 3,
args = {},
}
}, Bar.GetOptionTable(self))
end
return baroptions
end
--[[===================================================================================
ActionBar Prototype
===================================================================================]]--
local initialPosition
do
@@ -26,7 +147,7 @@ function ActionBar:ApplyConfig(config)
config = self.config
if not config.Position then initialPosition(self) end
self:UpdateButtons(config.Buttons)
self:UpdateButtons()
end
-- Update the number of buttons in our bar, creating new ones if necessary
@@ -60,19 +181,13 @@ function ActionBar:UpdateButtons(numbuttons)
self:UpdateButtonLayout()
end
ActionBar.SetButtons = ActionBar.UpdateButtons
function ActionBar:GetButtons()
return self.config.Buttons
end
-- align the buttons and correct the size of the bar overlay frame
function ActionBar:UpdateButtonLayout()
local numbuttons = self.config.Buttons
local numbuttons = self:GetButtons()
local buttons = self.buttons
local pad = self:GetPadding()
local Rows = self.config.Rows
local Rows = self:GetRows()
local ButtonPerRow = math_floor(numbuttons / Rows + 0.5) -- just a precaution
Rows = math_floor(numbuttons / ButtonPerRow + 0.5)
@@ -92,10 +207,16 @@ function ActionBar:UpdateButtonLayout()
end
end
--[[===================================================================================
ActionBar Config Interface
===================================================================================]]--
-- get the current padding
function ActionBar:GetPadding()
return self.config.Padding
end
-- set the padding and refresh layout
function ActionBar:SetPadding(pad)
if pad then
self.config.Padding = pad
@@ -103,10 +224,37 @@ function ActionBar:SetPadding(pad)
self:UpdateButtonLayout()
end
-- get the current number of buttons
function ActionBar:GetButtons()
return self.config.Buttons
end
-- set the number of buttons and refresh layout
ActionBar.SetButtons = ActionBar.UpdateButtons
-- get the current number of rows
function ActionBar:GetRows()
return self.config.Rows
end
-- set the number of rows and refresh layout
function ActionBar:SetRows(rows)
if rows then
self.config.Rows = rows
end
self:UpdateButtonLayout()
end
--[[===================================================================================
Utility function
===================================================================================]]--
-- get a iterator over all buttons
function ActionBar:GetAll()
return pairs(self.buttons)
end
-- execute a member function on all buttons
function ActionBar:ForAll(method, ...)
for _, button in self:GetAll() do
local func = button[method]