|
273 | 273 | return headerInitializer; |
274 | 274 | end |
275 | 275 |
|
276 | | - local heightCalculator = UIParent:CreateFontString(nil, "ARTWORK", "GameFontNormal"); |
277 | | - heightCalculator:SetWidth(635); |
| 276 | + local calculateHeight; |
| 277 | + do |
| 278 | + local heightCalculator = UIParent:CreateFontString(nil, "ARTWORK", "GameFontNormal"); |
| 279 | + local deferrer = CreateFrame("Frame"); |
| 280 | + deferrer:Hide(); |
| 281 | + deferrer.callbacks = {}; |
| 282 | + deferrer:SetScript("OnUpdate", function() |
| 283 | + for _, callback in pairs(deferrer.callbacks) do |
| 284 | + securecallfunction(callback); |
| 285 | + end |
| 286 | + deferrer.callbacks = {}; |
| 287 | + end); |
| 288 | + function deferrer:Defer(callback) |
| 289 | + table.insert(self.callbacks, callback); |
| 290 | + self:Show(); |
| 291 | + end |
| 292 | + calculateHeight = function(data, deferred) |
| 293 | + local text, indent = data.name, data.indent; |
| 294 | + heightCalculator:SetWidth(635 - (indent * 15)); |
| 295 | + heightCalculator:SetText(text); |
| 296 | + |
| 297 | + data.extent = heightCalculator:GetStringHeight(); |
| 298 | + if not deferred then |
| 299 | + deferrer:Defer(function() calculateHeight(data, true); end); |
| 300 | + end |
| 301 | + end |
| 302 | + end |
278 | 303 |
|
279 | 304 | --- @param text string |
| 305 | + --- @param indent number? # default 0 |
280 | 306 | --- @return SettingsListElementInitializer |
281 | | - function Config:MakeText(text) |
282 | | - heightCalculator:SetText(text); |
283 | | - |
| 307 | + function Config:MakeText(text, indent) |
284 | 308 | local data = { |
285 | 309 | name = text, |
286 | | - extent = heightCalculator:GetStringHeight(), |
| 310 | + indent = indent or 0, |
287 | 311 | }; |
| 312 | + calculateHeight(data); |
288 | 313 | --- @type SettingsListElementInitializer |
289 | 314 | local textInitializer = Settings.CreateElementInitializer("TransmogUpgradeMaster_SettingsTextTemplate", data); |
290 | 315 |
|
|
473 | 498 |
|
474 | 499 | return initializer:GetExtent(); |
475 | 500 | end |
| 501 | + |
| 502 | + frame:EvaluateVisibility(self.data.expanded); |
476 | 503 | end |
477 | 504 |
|
478 | 505 | self.layout:AddInitializer(expandInitializer); |
|
518 | 545 | function Config:MakeDonationPrompt() |
519 | 546 | self:MakeText("Addon development takes a large amount of time and effort. If you enjoy using Transmog Upgrade Master, please consider supporting its development by donating. Your support helps ensure the continued improvement and maintenance of the addon. Thank you for your generosity!"); |
520 | 547 |
|
521 | | - local function onClick(buttonIndex) |
| 548 | + local function onClick(_, buttonIndex) |
522 | 549 | if buttonIndex == 1 then |
523 | 550 | self:CopyText("https://www.paypal.com/cgi-bin/webscr?hosted_button_id=C8HP9WVKPCL8C&item_name=Transmog+Upgrade+Master&cmd=_s-xclick"); |
524 | 551 | else |
|
696 | 723 | self.Text:SetText(data.name); |
697 | 724 | self.Text:SetHeight(data.extent); |
698 | 725 | self:SetHeight(data.extent); |
| 726 | + local indent = data.indent or 0; |
| 727 | + self.Text:SetPoint('TOPLEFT', (7 + (indent * 15)), 0); |
| 728 | + end |
| 729 | + end |
| 730 | + |
| 731 | + TransmogUpgradeMaster_SettingsHeaderMixin = CreateFromMixins(DefaultTooltipMixin); |
| 732 | + do |
| 733 | + --- @class TUM_Config_HeaderMixin |
| 734 | + local mixin = TransmogUpgradeMaster_SettingsHeaderMixin; |
| 735 | + |
| 736 | + function mixin:Init(initializer) |
| 737 | + local data = initializer:GetData(); |
| 738 | + self.Title:SetTextToFit(data.name); |
| 739 | + local indent = data.indent or 0; |
| 740 | + self.Title:SetPoint('TOPLEFT', (7 + (indent * 15)), -16); |
| 741 | + |
| 742 | + self:SetCustomTooltipAnchoring(self.Title, "ANCHOR_RIGHT"); |
| 743 | + |
| 744 | + self:SetTooltipFunc(function() Settings.InitTooltip(initializer:GetName(), initializer:GetTooltip()) end); |
699 | 745 | end |
700 | 746 | end |
701 | 747 | end |
0 commit comments