Hi Ladies and Gentleman, its me again.
Today I have a question about ace options. I have the following code:
Lua Code:
position = {
type = "group",
inline = true,
order = 3,
name = LOCALE["POSITION"],
desc = LOCALE["POSITION_DESC"],
args = {
anchor = {
type = "select",
order = 1,
name = LOCALE["ANCHOR"],
desc = LOCALE["ANCHOR_MINI_MAP"],
values = CORE.Values.Anchors,
get = function()
return LybrialMiniMap.db.profile.position.anchor;
end,
set = function(_, value)
LybrialMiniMap.db.profile.position.anchor = value;
LybrialMiniMap:OnUpdatePosition();
end,
},
offset = {
type = "group",
inline = true,
order = 2,
name = LOCALE["OFFSET"],
desc = LOCALE["OFFSET_DESC"],
args = {
x = {
type = "range",
order = 1,
name = LOCALE["OFFSET_X"],
desc = LOCALE["OFFSET_X_DESC"],
min = Minimap:GetMinOffsetX(LybrialMiniMap.db.profile.position.anchor),
max = Minimap:GetMaxOffsetX(LybrialMiniMap.db.profile.position.anchor),
step = 1,
get = function()
return LybrialMiniMap.db.profile.position.offset.x;
end,
set = function(_, value)
LybrialMiniMap.db.profile.position.offset.x = value;
LybrialMiniMap:OnUpdatePosition();
end
},
y = {
type = "range",
order = 2,
name = LOCALE["OFFSET_Y"],
desc = LOCALE["OFFSET_Y_DESC"],
min = Minimap:GetMinOffsetY(LybrialMiniMap.db.profile.position.anchor),
max = Minimap:GetMaxOffsetY(LybrialMiniMap.db.profile.position.anchor),
step = 1,
get = function()
return -LybrialMiniMap.db.profile.position.offset.y;
end,
set = function(_, value)
LybrialMiniMap.db.profile.position.offset.y = -value;
LybrialMiniMap:OnUpdatePosition();
end
},
},
},
},
},
As you can see I have options for changing the position of my minimap. You can choose
the anchor ("TOP", "BOTTOM", "LEFT", etc.) and the x and y offset. However, for the min
and max values of the offsets I calculate the min and max x and y offset of the minimap
in relation to the anchor. Example:
Lua Code:
--- Get the min x offset of the frame in relation to the UIParent or custom parent frame (if provided) at the given anchor.
--- @param frame table The actual frame to get the min x offset for.
--- @param anchor string The actual anchor to get the min x offset for.
--- @param parent table The parent frame (optional) defaults to UIParent.
local function GetMinOffsetX(frame, anchor, parent)
if (frame) then
if (anchor == "LEFT" or anchor == "TOPLEFT" or anchor == "BOTTOMLEFT") then
return 0;
elseif (anchor == "RIGHT" or anchor == "TOPRIGHT" or anchor == "BOTTOMRIGHT") then
if (parent) then
return -(math.floor(parent:GetWidth()) - math.floor(frame:GetWidth()));
else
return -(math.floor(SCREEN.info.width) - math.floor(frame:GetWidth()));
end
else
if (parent) then
return -(math.floor(parent:GetWidth() / 2) - math.floor(frame:GetWidth() / 2));
else
return -(math.floor(SCREEN.info.width / 2) - math.floor(frame:GetWidth() / 2));
end
end
end
end
That means ofcourse that whenever the "anchor" option changes the offset min and max values
in the options need to get updated. How can I make the options refresh for the offsets after the anchor changed?