forked from EllesmereGaming/EllesmereUI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEllesmereUI_Widgets.lua
More file actions
5601 lines (5097 loc) · 242 KB
/
EllesmereUI_Widgets.lua
File metadata and controls
5601 lines (5097 loc) · 242 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-------------------------------------------------------------------------------
-- EllesmereUI_Widgets.lua
-- Shared Widget Helpers + Widget Factory
-- Split from EllesmereUI.lua -- see EllesmereUI.lua for constants & utilities
-- DEFERRED: body runs on first EllesmereUI:EnsureLoaded() call, not at load.
-------------------------------------------------------------------------------
local EllesmereUI = _G.EllesmereUI
EllesmereUI._deferredInits[#EllesmereUI._deferredInits + 1] = function()
local PP = EllesmereUI.PanelPP
-- Utility functions (used heavily)
local SolidTex = EllesmereUI.SolidTex
local MakeFont = EllesmereUI.MakeFont
local MakeBorder = EllesmereUI.MakeBorder
local DisablePixelSnap = EllesmereUI.DisablePixelSnap
local RowBg = EllesmereUI.RowBg
local lerp = EllesmereUI.lerp
local MakeDropdownArrow = EllesmereUI.MakeDropdownArrow
local RegisterWidgetRefresh = EllesmereUI.RegisterWidgetRefresh
local RegAccent = EllesmereUI.RegAccent
-- Visual constants (used in hot paths)
local EXPRESSWAY = EllesmereUI.EXPRESSWAY
local ELLESMERE_GREEN = EllesmereUI.ELLESMERE_GREEN
local CONTENT_PAD = EllesmereUI.CONTENT_PAD
local DARK_BG = EllesmereUI.DARK_BG
local BORDER_COLOR = EllesmereUI.BORDER_COLOR
local TEXT_WHITE = EllesmereUI.TEXT_WHITE
local TEXT_DIM = EllesmereUI.TEXT_DIM
local TEXT_SECTION = EllesmereUI.TEXT_SECTION
local MEDIA_PATH = EllesmereUI.MEDIA_PATH
local CS = EllesmereUI.CS
-- Numeric constants (used frequently in widget builders)
local TEXT_WHITE_R = EllesmereUI.TEXT_WHITE_R
local TEXT_WHITE_G = EllesmereUI.TEXT_WHITE_G
local TEXT_WHITE_B = EllesmereUI.TEXT_WHITE_B
local TEXT_DIM_R = EllesmereUI.TEXT_DIM_R
local TEXT_DIM_G = EllesmereUI.TEXT_DIM_G
local TEXT_DIM_B = EllesmereUI.TEXT_DIM_B
local TEXT_DIM_A = EllesmereUI.TEXT_DIM_A
local BORDER_R = EllesmereUI.BORDER_R
local BORDER_G = EllesmereUI.BORDER_G
local BORDER_B = EllesmereUI.BORDER_B
local ROW_BG_ODD = EllesmereUI.ROW_BG_ODD
local ROW_BG_EVEN = EllesmereUI.ROW_BG_EVEN
-- Slider constants (packed into table to reduce upvalue count)
local SL = {
TRACK_R = EllesmereUI.SL_TRACK_R, TRACK_G = EllesmereUI.SL_TRACK_G,
TRACK_B = EllesmereUI.SL_TRACK_B, TRACK_A = EllesmereUI.SL_TRACK_A,
FILL_A = EllesmereUI.SL_FILL_A,
INPUT_R = EllesmereUI.SL_INPUT_R, INPUT_G = EllesmereUI.SL_INPUT_G,
INPUT_B = EllesmereUI.SL_INPUT_B, INPUT_A = EllesmereUI.SL_INPUT_A,
INPUT_BRD_A = EllesmereUI.SL_INPUT_BRD_A,
MW_INPUT_BOOST = EllesmereUI.MW_INPUT_ALPHA_BOOST,
MW_TRACK_BOOST = EllesmereUI.MW_TRACK_ALPHA_BOOST,
}
-- Toggle constants (packed into table to reduce upvalue count)
local TG = {
OFF_R = EllesmereUI.TG_OFF_R, OFF_G = EllesmereUI.TG_OFF_G,
OFF_B = EllesmereUI.TG_OFF_B, OFF_A = EllesmereUI.TG_OFF_A,
ON_A = EllesmereUI.TG_ON_A,
KNOB_OFF_R = EllesmereUI.TG_KNOB_OFF_R, KNOB_OFF_G = EllesmereUI.TG_KNOB_OFF_G,
KNOB_OFF_B = EllesmereUI.TG_KNOB_OFF_B, KNOB_OFF_A = EllesmereUI.TG_KNOB_OFF_A,
KNOB_ON_R = EllesmereUI.TG_KNOB_ON_R, KNOB_ON_G = EllesmereUI.TG_KNOB_ON_G,
KNOB_ON_B = EllesmereUI.TG_KNOB_ON_B, KNOB_ON_A = EllesmereUI.TG_KNOB_ON_A,
}
-- Checkbox constants (packed into table to reduce upvalue count)
local CB = {
BOX_R = EllesmereUI.CB_BOX_R, BOX_G = EllesmereUI.CB_BOX_G, BOX_B = EllesmereUI.CB_BOX_B,
BRD_A = EllesmereUI.CB_BRD_A, ACT_BRD_A = EllesmereUI.CB_ACT_BRD_A,
}
-------------------------------------------------------------------------------
-- Physical-pixel sizing for toggle / checkbox widgets
--
-- The panel runs at baseScale * userScale. At userScale ~= 1.0 the
-- coordinate system no longer maps 1:1 to physical pixels, so sub-pixel
-- drift causes uneven padding on inner elements (knob, checkmark).
--
-- Fix: convert hardcoded physical-pixel counts into panel coordinates
-- using PP.SnapForES(pixelCount * onePixel, es) where onePixel is the
-- size of 1 physical pixel in panel coords. This guarantees every
-- dimension lands on an exact physical pixel boundary regardless of
-- scroll position, because relative offsets between parent and child
-- cancel out any sub-pixel scroll drift.
-------------------------------------------------------------------------------
local function GetPanelEffectiveScale()
local mf = EllesmereUI._mainFrame
if mf then return mf:GetEffectiveScale() end
-- Fallback before mainFrame exists
local physW = (GetPhysicalScreenSize())
local baseScale = GetScreenWidth() / physW
local userScale = (EllesmereUIDB and EllesmereUIDB.panelScale) or 1.0
return baseScale * userScale
end
local function PixelsToPanel(px, es)
-- Convert a physical pixel count to panel coordinate units,
-- snapped so it maps to exactly that many physical pixels.
local RealPP = EllesmereUI.PP
local onePixel = RealPP.perfect / es
return px * onePixel
end
-------------------------------------------------------------------------------
-- BuildToggleControl(parent, frameLevel, getValue, setValue, opts)
--
-- Creates a toggle switch (track + knob) with animated on/off transition.
-- Returns: toggle (Button), applyVisual (fn), snapToState (fn)
--
-- opts (optional table):
-- .sizeRatio -- multiplier on track/knob sizes (default 1.0)
-- .noAnim -- if true, snap instead of animate (used by cog popup)
-- .offColors -- {trackR,trackG,trackB,trackA, knobR,knobG,knobB,knobA}
-- .onColors -- {trackA, knobR,knobG,knobB,knobA} (track RGB = accent)
-------------------------------------------------------------------------------
local function BuildToggleControl(parent, frameLevel, getValue, setValue, opts)
opts = opts or {}
local RealPP = EllesmereUI.PP
local TOGGLE_W, TOGGLE_H = 40, 20
local KNOB_PAD = 2
if opts.sizeRatio and opts.sizeRatio ~= 1 then
local r = opts.sizeRatio
TOGGLE_W = math.floor(TOGGLE_W * r + 0.5)
TOGGLE_H = math.floor(TOGGLE_H * r + 0.5)
end
local offTR = opts.offColors and opts.offColors[1] or TG.OFF_R
local offTG = opts.offColors and opts.offColors[2] or TG.OFF_G
local offTB = opts.offColors and opts.offColors[3] or TG.OFF_B
local offTA = opts.offColors and opts.offColors[4] or TG.OFF_A
local offKR = opts.offColors and opts.offColors[5] or TG.KNOB_OFF_R
local offKG = opts.offColors and opts.offColors[6] or TG.KNOB_OFF_G
local offKB = opts.offColors and opts.offColors[7] or TG.KNOB_OFF_B
local offKA = opts.offColors and opts.offColors[8] or TG.KNOB_OFF_A
local onTA = opts.onColors and opts.onColors[1] or TG.ON_A
local onKR = opts.onColors and opts.onColors[2] or TG.KNOB_ON_R
local onKG = opts.onColors and opts.onColors[3] or TG.KNOB_ON_G
local onKB = opts.onColors and opts.onColors[4] or TG.KNOB_ON_B
local onKA = opts.onColors and opts.onColors[5] or TG.KNOB_ON_A
local toggle = CreateFrame("Button", nil, parent)
RealPP.Size(toggle, TOGGLE_W, TOGGLE_H)
toggle:SetFrameLevel(frameLevel)
local tBg = SolidTex(toggle, "BACKGROUND", offTR, offTG, offTB, offTA)
DisablePixelSnap(tBg)
tBg:SetAllPoints()
-- Use PanelPP for knob offsets: SetPoint coordinates are relative to
-- the toggle frame which lives inside the panel (panel coordinate space).
local PanelPP = EllesmereUI.PanelPP or RealPP
local snappedPad = PanelPP.Scale(KNOB_PAD)
local knob = toggle:CreateTexture(nil, "ARTWORK")
DisablePixelSnap(knob)
knob:SetColorTexture(offKR, offKG, offKB, offKA)
-- Two-point vertical anchoring: knob top/bottom are always exactly
-- snappedPad from the track edges. No independent size calculation.
-- Horizontal: set width explicitly from the snapped track height
-- minus the two pads so the knob is square.
local snappedTrackH = PanelPP.Scale(TOGGLE_H)
local snappedTrackW = PanelPP.Scale(TOGGLE_W)
local knobSz = snappedTrackH - snappedPad * 2
-- OFF = left edge, ON = right edge. Raw offsets, no PP.Scale.
-- POS_ON is computed at SetKnobPos time using the toggle's actual
-- rendered width, so it matches the real right edge regardless of
-- any scale mismatch between RealPP/PanelPP and the frame's coords.
local POS_OFF = snappedPad
local POS_ON = 0 -- computed dynamically in SetKnobPos
-- Position knob with raw SetPoint (bypass PP snapping).
-- TOPLEFT + BOTTOMLEFT with explicit width gives equal vertical gap.
local function SetKnobPos(xOff)
knob:ClearAllPoints()
knob:SetPoint("TOPLEFT", toggle, "TOPLEFT", xOff, -snappedPad)
knob:SetPoint("BOTTOMLEFT", toggle, "BOTTOMLEFT", xOff, snappedPad)
knob:SetWidth(knobSz)
end
local function GetPosOn()
local w = toggle:GetWidth()
if w and w > 0 then
return w - snappedPad - knobSz
end
return snappedTrackW - snappedPad - knobSz
end
local animProgress = getValue() and 1 or 0
local animTarget = animProgress
local ANIM_DUR = 0.075
local function ApplyVisual(p)
local posOn = GetPosOn()
local xOff = lerp(POS_OFF, posOn, p)
-- Only round mid-animation; at endpoints use the pre-snapped values
-- directly so rounding at the toggle's effective scale can't shift
-- the knob away from its intended position.
if p > 0 and p < 1 then
local es = toggle:GetEffectiveScale()
if es and es > 0 then
xOff = math.floor(xOff * es + 0.5) / es
end
end
SetKnobPos(xOff)
tBg:SetColorTexture(
lerp(offTR, ELLESMERE_GREEN.r, p),
lerp(offTG, ELLESMERE_GREEN.g, p),
lerp(offTB, ELLESMERE_GREEN.b, p),
lerp(offTA, onTA, p))
knob:SetColorTexture(
lerp(offKR, onKR, p),
lerp(offKG, onKG, p),
lerp(offKB, onKB, p),
lerp(offKA, onKA, p))
DisablePixelSnap(knob)
end
ApplyVisual(animProgress)
if opts.noAnim then
toggle:SetScript("OnClick", function()
local v = not getValue()
setValue(v)
animProgress = v and 1 or 0
animTarget = animProgress
ApplyVisual(animProgress)
end)
else
local function AnimOnUpdate(self, elapsed)
local dir = (animTarget == 1) and 1 or -1
animProgress = animProgress + dir * (elapsed / ANIM_DUR)
if (dir == 1 and animProgress >= 1) or (dir == -1 and animProgress <= 0) then
animProgress = animTarget
self:SetScript("OnUpdate", nil)
end
ApplyVisual(animProgress)
end
toggle:SetScript("OnClick", function()
local v = not getValue()
setValue(v)
animTarget = v and 1 or 0
toggle:SetScript("OnUpdate", AnimOnUpdate)
end)
end
local function SnapToState()
local v = getValue() and 1 or 0
animProgress = v; animTarget = v
ApplyVisual(v)
toggle:SetScript("OnUpdate", nil)
end
return toggle, ApplyVisual, SnapToState
end
-------------------------------------------------------------------------------
-- BuildCheckboxControl(parent, frameLevel)
--
-- Creates a checkbox (box + border + checkmark texture).
-- Returns: box (Frame), check (Texture), boxBorder, applyVisual (fn)
-- applyVisual(isOn, isHovering) updates colors/visibility.
-------------------------------------------------------------------------------
local function BuildCheckboxControl(parent, frameLevel)
local RealPP = EllesmereUI.PP
local BOX_SZ = 18
local BOX_PAD = 2
local box = CreateFrame("Frame", nil, parent)
RealPP.Size(box, BOX_SZ, BOX_SZ)
box:SetFrameLevel(frameLevel)
local boxBg = SolidTex(box, "BACKGROUND", CB.BOX_R, CB.BOX_G, CB.BOX_B, 1)
DisablePixelSnap(boxBg)
boxBg:SetAllPoints()
local boxBorder = MakeBorder(box, BORDER_R, BORDER_G, BORDER_B, CB.BRD_A, PP)
local check = SolidTex(box, "ARTWORK", ELLESMERE_GREEN.r, ELLESMERE_GREEN.g, ELLESMERE_GREEN.b, 1)
DisablePixelSnap(check)
RealPP.SetInside(check, box, BOX_PAD, BOX_PAD)
local function ApplyVisual(isOn, isHovering)
check:SetColorTexture(ELLESMERE_GREEN.r, ELLESMERE_GREEN.g, ELLESMERE_GREEN.b, 1)
if isOn then
check:Show()
boxBg:SetColorTexture(CB.BOX_R, CB.BOX_G, CB.BOX_B, 1)
boxBorder:SetColor(ELLESMERE_GREEN.r, ELLESMERE_GREEN.g, ELLESMERE_GREEN.b, CB.ACT_BRD_A)
else
check:Hide()
local a = isHovering and 1 or 0.8
boxBg:SetColorTexture(CB.BOX_R, CB.BOX_G, CB.BOX_B, 1 * a)
boxBorder:SetColor(BORDER_R, BORDER_G, BORDER_B, CB.BRD_A * a)
end
end
return box, check, boxBorder, ApplyVisual
end
-- Button constants
local BTN_BG_R = EllesmereUI.BTN_BG_R
local BTN_BG_G = EllesmereUI.BTN_BG_G
local BTN_BG_B = EllesmereUI.BTN_BG_B
local BTN_BG_A = EllesmereUI.BTN_BG_A
local BTN_BG_HA = EllesmereUI.BTN_BG_HA
local BTN_BRD_A = EllesmereUI.BTN_BRD_A
local BTN_BRD_HA = EllesmereUI.BTN_BRD_HA
local BTN_TXT_A = EllesmereUI.BTN_TXT_A
local BTN_TXT_HA = EllesmereUI.BTN_TXT_HA
-- Dropdown constants
local DD_BG_R = EllesmereUI.DD_BG_R
local DD_BG_G = EllesmereUI.DD_BG_G
local DD_BG_B = EllesmereUI.DD_BG_B
local DD_BG_A = EllesmereUI.DD_BG_A
local DD_BG_HA = EllesmereUI.DD_BG_HA
local DD_BRD_A = EllesmereUI.DD_BRD_A
local DD_BRD_HA = EllesmereUI.DD_BRD_HA
local DD_TXT_A = EllesmereUI.DD_TXT_A
local DD_TXT_HA = EllesmereUI.DD_TXT_HA
local DD_ITEM_HL_A = EllesmereUI.DD_ITEM_HL_A
local DD_ITEM_SEL_A = EllesmereUI.DD_ITEM_SEL_A
-- Layout constants
local DUAL_ITEM_W = EllesmereUI.DUAL_ITEM_W
local DUAL_GAP = EllesmereUI.DUAL_GAP
local TRIPLE_ITEM_W = EllesmereUI.TRIPLE_ITEM_W
local TRIPLE_GAP = EllesmereUI.TRIPLE_GAP
-------------------------------------------------------------------------------
-- Shared Widget Helpers (reduce duplication across widget factories)
-------------------------------------------------------------------------------
-- Style a button frame with bg/border/label + hover scripts.
-- colours = { bg_r,bg_g,bg_b,bg_a, bg_hr,bg_hg,bg_hb,bg_ha,
-- brd_r,brd_g,brd_b,brd_a, brd_hr,brd_hg,brd_hb,brd_ha,
-- txt_r,txt_g,txt_b,txt_a, txt_hr,txt_hg,txt_hb,txt_ha }
local function MakeStyledButton(btn, text, fontSize, colours, onClick)
local c = colours
local bg = SolidTex(btn, "BACKGROUND", c[1], c[2], c[3], c[4])
bg:SetAllPoints()
local brd = MakeBorder(btn, c[9], c[10], c[11], c[12], PP)
local lbl = MakeFont(btn, fontSize, nil, c[17], c[18], c[19])
lbl:SetAlpha(c[20])
lbl:SetPoint("CENTER")
lbl:SetText(text)
btn:SetScript("OnEnter", function()
lbl:SetTextColor(c[21], c[22], c[23], c[24])
brd:SetColor(c[13], c[14], c[15], c[16])
bg:SetColorTexture(c[5], c[6], c[7], c[8])
end)
btn:SetScript("OnLeave", function()
lbl:SetTextColor(c[17], c[18], c[19], c[20])
brd:SetColor(c[9], c[10], c[11], c[12])
bg:SetColorTexture(c[1], c[2], c[3], c[4])
end)
btn:SetScript("OnClick", function() if onClick then onClick() end end)
return bg, brd, lbl
end
-- Pre-built colour arrays for the two button styles
local WB_COLOURS = { -- Button hover style
BTN_BG_R, BTN_BG_G, BTN_BG_B, BTN_BG_A, BTN_BG_R, BTN_BG_G, BTN_BG_B, BTN_BG_HA,
1, 1, 1, BTN_BRD_A, 1, 1, 1, BTN_BRD_HA,
1, 1, 1, BTN_TXT_A, 1, 1, 1, BTN_TXT_HA,
}
local RB_COLOURS = {
BTN_BG_R, BTN_BG_G, BTN_BG_B, BTN_BG_A, BTN_BG_R, BTN_BG_G, BTN_BG_B, BTN_BG_HA,
1, 1, 1, BTN_BRD_A, 1, 1, 1, BTN_BRD_HA,
1, 1, 1, BTN_TXT_A, 1, 1, 1, BTN_TXT_HA,
}
-- Extract display text from a dropdown value (supports both string and {text, note} table)
-- Forward declarations (defined after the Widget Factory section)
local ShowWidgetTooltip, HideWidgetTooltip
-- Search metadata: tag a row frame so the inline search can find it
local function TagOptionRow(frame, parent, labelText)
frame._isOptionRow = true
frame._labelText = labelText
frame._sectionHeader = parent._currentSection
end
-- Global disabled-widget tooltip: "This option requires ___ to be enabled"
-- Pass the human-readable requirement name (e.g. "Show Class Power", "a non-None slot")
local function DisabledTooltip(requirement)
if type(requirement) == "string" and requirement:find("^This option") then return requirement end
return "This option requires " .. requirement .. " to be enabled"
end
-- Add a disabled-tooltip overlay on a control frame (slider region, toggle, swatch, etc.)
-- Shows the disabled tooltip centered on the control when hovered while disabled.
local function AddControlDisabledTooltip(controlAnchor, cfg)
if not cfg.disabledTooltip or not cfg.disabled then return end
local parent = controlAnchor:GetParent()
local hit = CreateFrame("Frame", nil, parent)
hit:SetAllPoints(controlAnchor)
local baseLevel = controlAnchor.GetFrameLevel and controlAnchor:GetFrameLevel() or parent:GetFrameLevel()
hit:SetFrameLevel(baseLevel + 10)
hit:SetMouseClickEnabled(false)
hit:SetMouseMotionEnabled(false)
hit:SetScript("OnEnter", function()
if cfg.disabled() then
local tt = cfg.disabledTooltip
if type(tt) == "function" then tt = tt() end
local raw = cfg.rawTooltip
if type(raw) == "function" then raw = raw() end
ShowWidgetTooltip(controlAnchor, raw and tt or DisabledTooltip(tt))
end
end)
hit:SetScript("OnLeave", function() HideWidgetTooltip() end)
local function UpdateMouse()
local off = cfg.disabled()
hit:SetMouseClickEnabled(off and true or false)
hit:SetMouseMotionEnabled(off and true or false)
end
RegisterWidgetRefresh(UpdateMouse)
UpdateMouse()
end
local function DDText(v)
if type(v) == "table" then return v.text end
return v
end
-- Resolve the display label for a dropdown, handling subnav children.
-- If curKey matches a top-level key whose value has a subnav, returns 'ParentText: ChildText'.
-- If curKey matches a subnav child key, searches all values for the parent.
-- Otherwise falls back to DDText(values[curKey]) or tostring(curKey).
local function DDResolveLabel(values, order, curKey)
-- Direct top-level match (non-subnav)
local direct = values[curKey]
if direct and type(direct) ~= 'table' then return direct end
if direct and type(direct) == 'table' and not direct.subnav then return direct.text end
-- curKey might be a subnav child search all values for a parent with subnav
for _, parentKey in ipairs(order) do
local pv = values[parentKey]
if type(pv) == 'table' and pv.subnav then
local sv = pv.subnav.values
if sv and sv[curKey] then
return pv.text .. ' - ' .. sv[curKey]
end
end
end
return tostring(curKey)
end
local function DDFont(v)
if type(v) == "table" then return v.font end
return nil
end
local function IsDividerKey(key)
return type(key) == "string" and key:match("^%-%-%-") ~= nil
end
-- Build a dropdown popup menu, item buttons, and return { menu, menuItems, refresh }.
-- ddBtn = the dropdown button frame the menu hangs off
-- menuW = pixel width of the menu
-- order = ordered key array
-- values = { key = displayName } -- displayName may be string or { text=..., note=... }
-- getValue / setValue = accessors
-- ddLbl = the dropdown label FontString to update on selection
-- style = "wide" or "regular" (chooses WD_ vs RD_ menu colours)
local DD_MAX_HEIGHT = 200
local function BuildDropdownMenu(ddBtn, menuW, order, values, getValue, setValue, ddLbl, style, disabledValuesFn)
local isWide = (style == "wide")
-- Menu bg/border: same colours for both styles (DD_BTN with menu-specific alpha)
local _menuOpts = values._menuOpts
local _moIcon = _menuOpts and _menuOpts.icon
local _moIconAtlas = _menuOpts and _menuOpts.iconAtlas
local _moIconPressedAtlas = _menuOpts and _menuOpts.iconPressedAtlas
local _moIconOnClick = _menuOpts and _menuOpts.iconOnClick
local _moIconTooltip = _menuOpts and _menuOpts.iconTooltip
local _moBackground = _menuOpts and _menuOpts.background
local _moBgVertexColor = _menuOpts and _menuOpts.backgroundVertexColor
local _moItemH = _menuOpts and _menuOpts.itemHeight or 26
local _moOnItemHover = _menuOpts and _menuOpts.onItemHover
local _moOnItemLeave = _menuOpts and _menuOpts.onItemLeave
local mBgR, mBgG, mBgB, mBgA = DD_BG_R, DD_BG_G, DD_BG_B, DD_BG_HA
local mBrR, mBrG, mBrB, mBrA = 1, 1, 1, DD_BRD_A
local menu = CreateFrame("Frame", nil, UIParent)
menu:SetFrameStrata("FULLSCREEN_DIALOG")
menu:SetFrameLevel(200)
menu:SetClampedToScreen(true)
menu:SetClipsChildren(true)
menu:EnableMouse(true)
menu:SetSize(menuW, 10)
menu:SetPoint("TOPLEFT", ddBtn, "BOTTOMLEFT", 0, -2)
menu:Hide()
SolidTex(menu, "BACKGROUND", mBgR, mBgG, mBgB, mBgA):SetAllPoints()
MakeBorder(menu, mBrR, mBrG, mBrB, mBrA, PP)
-- Inner container: items are always parented here.
-- If scrolling is needed, this becomes the scroll child.
local innerContainer = CreateFrame("Frame", nil, menu)
innerContainer:SetWidth(menuW)
innerContainer:SetPoint("TOPLEFT", menu, "TOPLEFT", 0, 0)
local menuItems = {}
local mH = 4
for _, key in ipairs(order) do
-- Divider support: keys beginning with "---" insert a thin separator line
if IsDividerKey(key) then
local div = innerContainer:CreateTexture(nil, "ARTWORK")
div:SetHeight(1)
div:SetColorTexture(1, 1, 1, 0.10)
div:SetPoint("TOPLEFT", innerContainer, "TOPLEFT", 1, -mH - 4)
div:SetPoint("TOPRIGHT", innerContainer, "TOPRIGHT", -1, -mH - 4)
mH = mH + 9
else
local dn = values[key]
if dn then
-- SUBNAV PARENT: render with arrow, hover flyout
if type(dn) == 'table' and dn.subnav then
local sn = dn.subnav
local parentText = dn.text or tostring(key)
local item = CreateFrame('Button', nil, innerContainer)
item:SetHeight(26)
item:SetPoint('TOPLEFT', innerContainer, 'TOPLEFT', 1, -mH)
item:SetPoint('TOPRIGHT', innerContainer, 'TOPRIGHT', -1, -mH)
item:SetFrameLevel(menu:GetFrameLevel() + 2)
local iLbl = MakeFont(item, 13, nil, TEXT_DIM_R, TEXT_DIM_G, TEXT_DIM_B, TEXT_DIM_A)
iLbl:SetAlpha(1)
iLbl:SetPoint('LEFT', item, 'LEFT', isWide and 12 or 10, 0)
iLbl:SetText(parentText)
-- Arrow indicator (right side, texture)
local arrowTex = item:CreateTexture(nil, 'ARTWORK')
arrowTex:SetSize(10, 10)
arrowTex:SetPoint('RIGHT', item, 'RIGHT', -8, 0)
arrowTex:SetTexture(MEDIA_PATH .. 'icons/right-arrow.png')
arrowTex:SetAlpha(0.7)
local iHl = SolidTex(item, 'ARTWORK', 1, 1, 1, 1); iHl:SetAlpha(0)
iHl:SetAllPoints()
item._key = key
item._label = iLbl
item._highlight = iHl
item._isSubnavParent = true
item._subnavChildKeys = {}
if sn.order then for _, ck in ipairs(sn.order) do item._subnavChildKeys[ck] = true end end
menuItems[#menuItems + 1] = item
-- Build flyout sub-menu
local flyout = CreateFrame('Frame', nil, UIParent)
flyout:SetFrameStrata('FULLSCREEN_DIALOG')
flyout:SetFrameLevel(menu:GetFrameLevel() + 10)
flyout:SetClampedToScreen(true)
flyout:SetSize(menuW, 10)
flyout:Hide()
SolidTex(flyout, 'BACKGROUND', mBgR, mBgG, mBgB, mBgA):SetAllPoints()
MakeBorder(flyout, mBrR, mBrG, mBrB, mBrA, PP)
item._flyout = flyout
if not menu._flyouts then menu._flyouts = {} end
menu._flyouts[#menu._flyouts + 1] = flyout
local fH = 4
for _, childKey in ipairs(sn.order) do
local childText = sn.values[childKey]
if childText then
local ci = CreateFrame('Button', nil, flyout)
ci:SetHeight(sn.itemHeight or 26)
ci:SetPoint('TOPLEFT', flyout, 'TOPLEFT', 1, -fH)
ci:SetPoint('TOPRIGHT', flyout, 'TOPRIGHT', -1, -fH)
ci:SetFrameLevel(flyout:GetFrameLevel() + 2)
local cLbl = MakeFont(ci, 13, nil, TEXT_DIM_R, TEXT_DIM_G, TEXT_DIM_B, TEXT_DIM_A)
cLbl:SetAlpha(1)
cLbl:SetPoint('LEFT', ci, 'LEFT', 10, 0)
cLbl:SetText(childText)
cLbl:SetJustifyH('LEFT')
-- Optional icon from subnav.icon callback
if sn.icon then
local iconPath, l, r, t, b = sn.icon(childKey)
if iconPath then
local ico = ci:CreateTexture(nil, 'ARTWORK')
local icoSz = (sn.itemHeight or 26) - 8; ico:SetSize(icoSz, icoSz)
ico:SetPoint('RIGHT', ci, 'RIGHT', -6, 0)
ico:SetTexture(iconPath)
if l then ico:SetTexCoord(l, r, t, b) end
cLbl:SetPoint('RIGHT', ico, 'LEFT', -4, 0)
end
end
local cHl = SolidTex(ci, 'ARTWORK', 1, 1, 1, 1); cHl:SetAlpha(0)
cHl:SetAllPoints()
ci._key = childKey
ci._label = cLbl
ci._highlight = cHl
ci:SetScript('OnEnter', function()
cLbl:SetTextColor(1, 1, 1, 1)
cHl:SetAlpha(DD_ITEM_HL_A)
end)
ci:SetScript('OnLeave', function()
cLbl:SetTextColor(TEXT_DIM_R, TEXT_DIM_G, TEXT_DIM_B, TEXT_DIM_A)
local cur = getValue()
cHl:SetAlpha(ci._key == cur and DD_ITEM_SEL_A or 0)
end)
ci:SetScript('OnClick', function()
if sn.onSelect then sn.onSelect(childKey) end
ddLbl:SetText(parentText .. ': ' .. childText)
flyout:Hide()
menu:Hide()
C_Timer.After(0, function()
local rl = EllesmereUI._widgetRefreshList
if rl then for ri = 1, #rl do rl[ri]() end end
end)
end)
fH = fH + (sn.itemHeight or 26)
end
end
flyout:SetHeight(fH + 4)
-- Show/hide flyout on parent hover
local flyoutTimer
item:SetScript('OnEnter', function()
iLbl:SetTextColor(1, 1, 1, 1)
arrowTex:SetAlpha(1)
iHl:SetAlpha(DD_ITEM_HL_A)
if flyoutTimer then flyoutTimer:Cancel(); flyoutTimer = nil end
flyout:ClearAllPoints()
flyout:SetPoint('TOPLEFT', item, 'TOPRIGHT', 2, 0)
flyout:Show()
-- Match scale
flyout:SetScale(menu:GetScale())
end)
item:SetScript('OnLeave', function()
iLbl:SetTextColor(TEXT_DIM_R, TEXT_DIM_G, TEXT_DIM_B, TEXT_DIM_A)
arrowTex:SetAlpha(0.7)
local cur = getValue()
local isChild = item._subnavChildKeys[cur]
iHl:SetAlpha(isChild and DD_ITEM_SEL_A or 0)
-- Delay hide so user can move mouse to flyout
flyoutTimer = C_Timer.NewTimer(0.25, function()
if not flyout:IsMouseOver() and not item:IsMouseOver() then
flyout:Hide()
end
flyoutTimer = nil
end)
end)
-- Keep flyout alive while mouse is over it
flyout:SetScript('OnEnter', function()
if flyoutTimer then flyoutTimer:Cancel(); flyoutTimer = nil end
end)
flyout:SetScript('OnLeave', function()
flyoutTimer = C_Timer.NewTimer(0.15, function()
if not flyout:IsMouseOver() and not item:IsMouseOver() then
flyout:Hide()
end
flyoutTimer = nil
end)
end)
-- Hide flyout when main menu hides
menu:HookScript('OnHide', function() flyout:Hide() end)
item:SetScript('OnClick', function() end) -- no-op, subnav only
mH = mH + 26
else
-- Support annotated labels: dn can be a string or { text=..., note=..., font=... }
local mainText, noteText, itemFont
if type(dn) == "table" then
mainText = dn.text
noteText = dn.note
itemFont = dn.font
else
mainText = dn
end
local item = CreateFrame("Button", nil, innerContainer)
item:SetHeight(_moItemH)
item:SetPoint("TOPLEFT", innerContainer, "TOPLEFT", 1, -mH)
item:SetPoint("TOPRIGHT", innerContainer, "TOPRIGHT", -1, -mH)
item:SetFrameLevel(menu:GetFrameLevel() + 2)
-- Optional background texture from _menuOpts.background callback
if _moBackground then
local bgPath = _moBackground(key)
if bgPath then
local bgTex = item:CreateTexture(nil, "BACKGROUND", nil, 1)
bgTex:SetAllPoints()
bgTex:SetTexture(bgPath)
bgTex:SetAlpha(0.45)
if _moBgVertexColor then
local vr, vg, vb = _moBgVertexColor()
if vr then bgTex:SetVertexColor(vr, vg, vb, 1) end
end
end
end
local iLbl = MakeFont(item, 13, nil, TEXT_DIM_R, TEXT_DIM_G, TEXT_DIM_B, TEXT_DIM_A)
if itemFont then iLbl:SetFont(itemFont, 13, "") end
iLbl:SetAlpha(1)
iLbl:SetPoint("LEFT", item, "LEFT", isWide and 12 or 10, 0)
iLbl:SetJustifyH("LEFT")
iLbl:SetText(mainText)
-- Optional annotation (smaller font, 75% alpha, same color)
-- Optional icon. Three sources supported:
-- _menuOpts.icon(key) -> texture path (+ optional texcoord)
-- _menuOpts.iconAtlas(key) -> atlas name (Blizzard atlas)
-- _menuOpts.iconPressedAtlas(key)-> pressed-state atlas name
-- When _menuOpts.iconOnClick is also provided, the icon becomes
-- a clickable Button with its own frame level so clicks don't
-- propagate to the item's OnClick (used for sound previews).
local _haveAtlas = _moIconAtlas and _moIconAtlas(key) or nil
local _iconPath, _il, _ir, _it, _ib
if _moIcon and not _haveAtlas then
_iconPath, _il, _ir, _it, _ib = _moIcon(key)
end
if _haveAtlas or _iconPath then
local icoSz = _moItemH - 8
if _moIconOnClick then
local iconBtn = CreateFrame("Button", nil, item)
iconBtn:SetSize(icoSz, icoSz)
iconBtn:SetPoint("RIGHT", item, "RIGHT", -6, 0)
iconBtn:SetFrameLevel(item:GetFrameLevel() + 2)
if _haveAtlas then
iconBtn:SetNormalAtlas(_haveAtlas)
local pressedAtlas = _moIconPressedAtlas and _moIconPressedAtlas(key)
if pressedAtlas then
iconBtn:SetPushedAtlas(pressedAtlas)
end
iconBtn:SetHighlightAtlas(_haveAtlas)
-- Atlas icons like common-icon-sound have an intrinsic
-- colour (yellow). SetVertexColor alone just scales that
-- colour, so we desaturate first, then tint to #929292.
local _nr, _ng, _nb = 0.573, 0.573, 0.573
local nrmTex = iconBtn:GetNormalTexture()
if nrmTex then
if nrmTex.SetDesaturated then nrmTex:SetDesaturated(true) end
nrmTex:SetVertexColor(_nr, _ng, _nb, 1)
end
local psdTex = iconBtn:GetPushedTexture()
if psdTex then
if psdTex.SetDesaturated then psdTex:SetDesaturated(true) end
psdTex:SetVertexColor(_nr, _ng, _nb, 1)
end
local hlTex = iconBtn:GetHighlightTexture()
if hlTex then
if hlTex.SetDesaturated then hlTex:SetDesaturated(true) end
hlTex:SetVertexColor(_nr, _ng, _nb, 1)
hlTex:SetAlpha(0.4)
end
else
local ico = iconBtn:CreateTexture(nil, "ARTWORK")
ico:SetAllPoints()
ico:SetTexture(_iconPath)
if _il then ico:SetTexCoord(_il, _ir, _it, _ib) end
ico:SetVertexColor(0.8, 0.8, 0.8, 1)
iconBtn._ico = ico
end
iconBtn:SetScript("OnEnter", function()
if iconBtn._ico then iconBtn._ico:SetVertexColor(1, 1, 1, 1) end
if _moIconTooltip then
ShowWidgetTooltip(iconBtn, _moIconTooltip(key))
end
end)
iconBtn:SetScript("OnLeave", function()
if iconBtn._ico then iconBtn._ico:SetVertexColor(0.8, 0.8, 0.8, 1) end
if _moIconTooltip then HideWidgetTooltip() end
end)
iconBtn:SetScript("OnClick", function()
_moIconOnClick(key)
end)
iLbl:SetPoint("RIGHT", iconBtn, "LEFT", -4, 0)
else
local ico = item:CreateTexture(nil, "ARTWORK")
ico:SetSize(icoSz, icoSz)
ico:SetPoint("RIGHT", item, "RIGHT", -6, 0)
if _haveAtlas then
ico:SetAtlas(_haveAtlas)
else
ico:SetTexture(_iconPath)
if _il then ico:SetTexCoord(_il, _ir, _it, _ib) end
end
iLbl:SetPoint("RIGHT", ico, "LEFT", -4, 0)
end
end
local iNote
if noteText then
iNote = MakeFont(item, 11, nil, TEXT_DIM_R, TEXT_DIM_G, TEXT_DIM_B, TEXT_DIM_A)
iNote:SetAlpha(0.75)
iNote:SetPoint("LEFT", iLbl, "RIGHT", 4, 0)
iNote:SetText(noteText)
end
local iHl = SolidTex(item, "ARTWORK", 1, 1, 1, 1); iHl:SetAlpha(0)
iHl:SetAllPoints()
item._key, item._label, item._highlight, item._note = key, iLbl, iHl, iNote
-- Store the full display name for the dropdown button label
item._displayName = noteText and (mainText .. " " .. noteText) or mainText
menuItems[#menuItems + 1] = item
item:SetScript("OnEnter", function()
if disabledValuesFn then
local dv = disabledValuesFn(key)
if dv then
-- If the function returns a string, show it as a tooltip via the addon system
if type(dv) == "string" then ShowWidgetTooltip(item, dv) end
return
end
end
iLbl:SetTextColor(1, 1, 1, 1)
if iNote then iNote:SetTextColor(1, 1, 1, 1) end
iHl:SetAlpha(DD_ITEM_HL_A)
if _moOnItemHover then _moOnItemHover(key) end
end)
item:SetScript("OnLeave", function()
if disabledValuesFn and disabledValuesFn(key) then HideWidgetTooltip(); return end
iLbl:SetTextColor(TEXT_DIM_R, TEXT_DIM_G, TEXT_DIM_B, TEXT_DIM_A)
if iNote then iNote:SetTextColor(TEXT_DIM_R, TEXT_DIM_G, TEXT_DIM_B, TEXT_DIM_A) end
iHl:SetAlpha((item._key == getValue()) and DD_ITEM_SEL_A or 0)
if _moOnItemLeave then _moOnItemLeave(key) end
end)
item:SetScript("OnClick", function()
if disabledValuesFn and disabledValuesFn(key) then return end
setValue(key); ddLbl:SetText(mainText)
menu:Hide()
-- Deferred refresh: setValue may have mutually-excluded another
-- dropdown (e.g. left/right text). A zero-delay timer ensures
-- the other dropdown's label updates after the menu fully closes.
C_Timer.After(0, function()
local rl = EllesmereUI._widgetRefreshList
if rl then for ri = 1, #rl do rl[ri]() end end
end)
end)
mH = mH + _moItemH
end -- subnav if/else
end -- if dn
end -- divider else
end -- for order
local totalContentH = mH + 3
innerContainer:SetHeight(totalContentH)
---------------------------------------------------------------------------
-- Scrollable dropdown: if content exceeds DD_MAX_HEIGHT, wrap in a
-- ScrollFrame with a thin custom scrollbar + smooth scrolling.
---------------------------------------------------------------------------
if totalContentH > (_menuOpts and _menuOpts.maxHeight or DD_MAX_HEIGHT) then
menu:SetHeight(_menuOpts and _menuOpts.maxHeight or DD_MAX_HEIGHT)
local sf = CreateFrame("ScrollFrame", nil, menu)
sf:SetPoint("TOPLEFT", menu, "TOPLEFT", 0, 0)
sf:SetPoint("BOTTOMRIGHT", menu, "BOTTOMRIGHT", 0, 0)
sf:SetFrameLevel(menu:GetFrameLevel() + 1)
sf:EnableMouseWheel(true)
sf:SetScrollChild(innerContainer)
innerContainer:SetWidth(menuW)
-- Thin scrollbar track (4px, right side, matching main panel style)
local ddTrack = CreateFrame("Frame", nil, sf)
ddTrack:SetWidth(4)
ddTrack:SetPoint("TOPRIGHT", sf, "TOPRIGHT", -4, -4)
ddTrack:SetPoint("BOTTOMRIGHT", sf, "BOTTOMRIGHT", -4, 4)
ddTrack:SetFrameLevel(sf:GetFrameLevel() + 2)
SolidTex(ddTrack, "BACKGROUND", 1, 1, 1, 0.02):SetAllPoints()
local ddThumb = CreateFrame("Button", nil, ddTrack)
ddThumb:SetWidth(4)
ddThumb:SetFrameLevel(ddTrack:GetFrameLevel() + 1)
ddThumb:EnableMouse(true)
ddThumb:RegisterForDrag("LeftButton")
ddThumb:SetScript("OnDragStart", function() end)
ddThumb:SetScript("OnDragStop", function() end)
SolidTex(ddThumb, "ARTWORK", 1, 1, 1, 0.27):SetAllPoints()
-- Smooth scroll state (per-dropdown, isolated from main panel)
local ddScrollTarget = 0
local ddSmoothing = false
local SCROLL_STEP = 40
local SMOOTH_SPEED = 12
local ddSmoothFrame = CreateFrame("Frame")
ddSmoothFrame:Hide()
local function UpdateDDThumb()
local maxScroll = EllesmereUI.SafeScrollRange(sf)
if maxScroll <= 0 then ddTrack:Hide(); return end
ddTrack:Show()
local trackH = ddTrack:GetHeight()
local visH = sf:GetHeight()
local ratio = visH / (visH + maxScroll)
local thumbH = math.max(20, trackH * ratio)
ddThumb:SetHeight(thumbH)
local scrollRatio = (tonumber(sf:GetVerticalScroll()) or 0) / maxScroll
local maxTravel = trackH - thumbH
ddThumb:ClearAllPoints()
ddThumb:SetPoint("TOP", ddTrack, "TOP", 0, -(scrollRatio * maxTravel))
end
ddSmoothFrame:SetScript("OnUpdate", function(_, elapsed)
local cur = sf:GetVerticalScroll()
local maxScroll = EllesmereUI.SafeScrollRange(sf)
ddScrollTarget = math.max(0, math.min(maxScroll, ddScrollTarget))
local diff = ddScrollTarget - cur
if math.abs(diff) < 0.3 then
sf:SetVerticalScroll(ddScrollTarget)
UpdateDDThumb()
ddSmoothing = false
ddSmoothFrame:Hide()
return
end
local newScroll = cur + diff * math.min(1, SMOOTH_SPEED * elapsed)
newScroll = math.max(0, math.min(maxScroll, newScroll))
sf:SetVerticalScroll(newScroll)
UpdateDDThumb()
end)
local function DDSmoothScrollTo(target)
local maxScroll = EllesmereUI.SafeScrollRange(sf)
ddScrollTarget = math.max(0, math.min(maxScroll, target))
if not ddSmoothing then
ddSmoothing = true
ddSmoothFrame:Show()
end
end
sf:SetScript("OnMouseWheel", function(self, delta)
local maxScroll = EllesmereUI.SafeScrollRange(self)
if maxScroll <= 0 then return end
local base = ddSmoothing and ddScrollTarget or self:GetVerticalScroll()
DDSmoothScrollTo(base - delta * SCROLL_STEP)
end)
sf:SetScript("OnScrollRangeChanged", UpdateDDThumb)
-- Thumb drag
local ddDragging = false
local ddDragStartY, ddDragStartScroll
ddThumb:SetScript("OnMouseDown", function(self, button)
if button ~= "LeftButton" then return end
ddDragging = true
ddSmoothing = false
ddSmoothFrame:Hide()
local _, cursorY = GetCursorPosition()
ddDragStartY = cursorY / self:GetEffectiveScale()
ddDragStartScroll = sf:GetVerticalScroll()
self:SetScript("OnUpdate", function(self2)
if not IsMouseButtonDown("LeftButton") then
ddDragging = false
self2:SetScript("OnUpdate", nil)
return
end
local _, cy = GetCursorPosition()
cy = cy / self2:GetEffectiveScale()
local deltaY = ddDragStartY - cy
local trackH = ddTrack:GetHeight()
local maxTravel = trackH - self2:GetHeight()
if maxTravel <= 0 then return end
local maxScroll = EllesmereUI.SafeScrollRange(sf)
local newScroll = math.max(0, math.min(maxScroll,
ddDragStartScroll + (deltaY / maxTravel) * maxScroll))
ddScrollTarget = newScroll
sf:SetVerticalScroll(newScroll)
UpdateDDThumb()
end)
end)
ddThumb:SetScript("OnMouseUp", function(self, button)
if button ~= "LeftButton" then return end
ddDragging = false
self:SetScript("OnUpdate", nil)
end)
-- Stop smooth animation when menu hides
menu:HookScript("OnHide", function()
ddSmoothing = false
ddSmoothFrame:Hide()
ddScrollTarget = 0
sf:SetVerticalScroll(0)
end)
-- Initial thumb update when menu shows
menu:HookScript("OnShow", function()
ddScrollTarget = 0
sf:SetVerticalScroll(0)
UpdateDDThumb()
end)