|
218 | 218 |
|
219 | 219 | --- @param text string |
220 | 220 | --- @param tooltip string? |
| 221 | + --- @param indent number? # default 0 |
221 | 222 | --- @return SettingsListElementInitializer initializer |
222 | | - function ConfigBuilderMixin:MakeHeader(text, tooltip) |
223 | | - local initializer = Config:MakeHeader(text, tooltip); |
| 223 | + function ConfigBuilderMixin:MakeHeader(text, tooltip, indent) |
| 224 | + local initializer = Config:MakeHeader(text, tooltip, indent); |
224 | 225 | initializer:AddShownPredicate(self.isExpanded); |
225 | 226 |
|
226 | 227 | return initializer; |
@@ -358,28 +359,53 @@ end |
358 | 359 | do |
359 | 360 | --- @param text string |
360 | 361 | --- @param tooltip string? |
| 362 | + --- @param indent number? # default 0 |
361 | 363 | --- @return SettingsListElementInitializer |
362 | | - function Config:MakeHeader(text, tooltip) |
363 | | - local headerInitializer = CreateSettingsListSectionHeaderInitializer(text, tooltip); |
364 | | - self.layout:AddInitializer(headerInitializer); |
| 364 | + function Config:MakeHeader(text, tooltip, indent) |
| 365 | + local data = { name = text, tooltip = tooltip, indent = indent or 0 }; |
| 366 | + --- @type SettingsListElementInitializer |
| 367 | + local headerInitializer = Settings.CreateElementInitializer("MythicPlusTweaks_SettingsHeaderTemplate", data); |
365 | 368 |
|
366 | 369 | return headerInitializer; |
367 | 370 | end |
368 | 371 |
|
369 | | - local heightCalculator = UIParent:CreateFontString(nil, "ARTWORK", "GameFontNormal"); |
| 372 | + local calculateHeight; |
| 373 | + do |
| 374 | + local heightCalculator = UIParent:CreateFontString(nil, "ARTWORK", "GameFontNormal"); |
| 375 | + local deferrer = CreateFrame("Frame"); |
| 376 | + deferrer:Hide(); |
| 377 | + deferrer.callbacks = {}; |
| 378 | + deferrer:SetScript("OnUpdate", function() |
| 379 | + for _, callback in pairs(deferrer.callbacks) do |
| 380 | + securecallfunction(callback); |
| 381 | + end |
| 382 | + deferrer.callbacks = {}; |
| 383 | + end); |
| 384 | + function deferrer:Defer(callback) |
| 385 | + table.insert(self.callbacks, callback); |
| 386 | + self:Show(); |
| 387 | + end |
| 388 | + calculateHeight = function(data, deferred) |
| 389 | + local text, indent = data.name, data.indent; |
| 390 | + heightCalculator:SetWidth(635 - (indent * 15)); |
| 391 | + heightCalculator:SetText(text); |
| 392 | + |
| 393 | + data.extent = heightCalculator:GetStringHeight(); |
| 394 | + if not deferred then |
| 395 | + deferrer:Defer(function() calculateHeight(data, true); end); |
| 396 | + end |
| 397 | + end |
| 398 | + end |
370 | 399 |
|
371 | 400 | --- @param text string |
372 | 401 | --- @param indent number? # default 0 |
373 | 402 | --- @return SettingsListElementInitializer |
374 | 403 | function Config:MakeText(text, indent) |
375 | | - heightCalculator:SetWidth(635 - (indent or 0)); |
376 | | - heightCalculator:SetText(text); |
377 | | - |
378 | 404 | local data = { |
379 | 405 | name = text, |
380 | | - extent = heightCalculator:GetStringHeight(), |
381 | 406 | indent = indent or 0, |
382 | 407 | }; |
| 408 | + calculateHeight(data); |
383 | 409 | --- @type SettingsListElementInitializer |
384 | 410 | local textInitializer = Settings.CreateElementInitializer("MythicPlusTweaks_SettingsTextTemplate", data); |
385 | 411 |
|
|
785 | 811 | self.Text:SetPoint('TOPLEFT', (7 + (indent * 15)), 0); |
786 | 812 | end |
787 | 813 | end |
| 814 | + |
| 815 | + MythicPlusTweaks_SettingsHeaderMixin = CreateFromMixins(DefaultTooltipMixin); |
| 816 | + do |
| 817 | + --- @class MPT_Config_HeaderMixin |
| 818 | + local mixin = MythicPlusTweaks_SettingsHeaderMixin; |
| 819 | + |
| 820 | + function mixin:Init(initializer) |
| 821 | + local data = initializer:GetData(); |
| 822 | + self.Title:SetTextToFit(data.name); |
| 823 | + local indent = data.indent or 0; |
| 824 | + self.Title:SetPoint('TOPLEFT', (7 + (indent * 15)), -16); |
| 825 | + |
| 826 | + self:SetCustomTooltipAnchoring(self.Title, "ANCHOR_RIGHT"); |
| 827 | + |
| 828 | + self:SetTooltipFunc(function() Settings.InitTooltip(initializer:GetName(), initializer:GetTooltip()) end); |
| 829 | + end |
| 830 | + end |
788 | 831 | end |
0 commit comments