-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathKKoreUI.txt
1761 lines (1460 loc) · 74.5 KB
/
KKoreUI.txt
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
KahLua Kore - User Interface (KKoreUI)
======================================
KKoreUI is a library of useful user interface management functions used
by all KahLua modules. While it was originally designed to be tightly
coupled with the rest of KahLua Kore (KKore), it provides functionality
that is useful and traditionally fairly difficult to work with using the
standard Blizzard code. Therefore, I have made it possible for this
portion of KKore to be packaged as a stand-alone library so that other
addon authors can more easily create their won user interfaces. The
parts that are most likely to interest other users is the tabbed dialog
code, the dropdown menu code and the popup menu code. That is the vast
majority of the KKoreUI code anyway, the rest of it is mostly just a
thin wrapper on top of normal Blizzard frame types.
KKoreUI functions are divided into three main groups:
1. Individual widgets (buttons, edit boxes etc).
2. Container widgets (dialogs and tabbed dialogs).
3. Utilities (string measurement etc).
1. Using KKoreUI in your code.
===============================
KKoreUI's heritage shows in its directory placement requirement. To use
this (or other KKore libraries such as KKoreHash) simply copy the KKore
folder into your addon directory and add the following line to your
addon's TOC file, right after all of the ## directives:
KKore\KKore.xml
Then edit that file (KKore\KKore.xml) and ensure that KKoreUI has been
uncommented. If you are using any other KKore libraries in your addon,
they should be uncommented too.
Once this has been done, somewhere at the top of your module code where
it initializes itself, you need to get a "handle" to KKoreUI. KKoreUI
has an embedded version of LibStub, so if you were using that for any
other reason, such as loading Ace3 libraries, you can remove the
LibStub.lua file from your addon and its TOC file. This is why you want
KKore to be loaded as early as possible in your TOC. To get a handle
for KKoreUI, simply add the following lines to your addon:
local KUI = LibStub:GetLibrary ("KKoreUI")
assert (KUI, "YourModuleName requires KKoreUI, which was not loaded")
That's it. Your addon is now ready to use KKoreUI.
2. Basic Usage
===============
Almost all KKoreUI functions take two and only two arguments: a configuration
table and the parent frame to which the widget is to be attached, which if
not specified defaults to UIParent. For example, to create a button, you
could use:
local button = KUI:CreateButton ({text = "Push me!"})
All options to KKoreUI widgets and functions are passed through the first
argument, which is a Lua table with a number of named elements that
control what KKoreUI does. There are some elements common to all or most
widgets, and some widgets have extra elements to control their behaviour.
The common elements all widgets share are:
cfg.name [string]
The name of the widget or container. Certain widget types must have a
name, others its optional. Where a name is mandatory it is discussed in
the widget type.
cfg.x, cfg.y [number or string]
Where to position this object relative to its parent. Internally KKoreUI
performs the following actions:
frame:SetPoint ("LEFT", parent, "LEFT", x, 0)
frame:SetPoint ("TOP, parent, "TOP, 0, y)
x can also be the string "CENTER" in which case the widget will be
centered horizontally withing the parent, and y can be the string
"MIDDLE" to be centered vertically. If either x or y are not specified
then that particular point ("LEFT" for x, "TOP" for y) are not set by
KKoreUI and you will need to place the returned frame yourself.
cfg.width, cfg.height [number]
Override the default widget width and height. Each widget type has a
default, and this allows you to set your own values.
cfg.enabled [boolean]
Most widgets support this element, and if set, sets the default state
of the element. If not specified it defaults to true. If you want the
widget to start out life disabled, set this to false.
cfg.label [table]
Many widgets allow you to set a lable for the widget. If the widget type
uses labels, this is how you set its value and properties. This element
is a table which can contain the following elements:
text
The actual text of the label. Must be specified if the label element
appears in the config table.
font
The name of the font to use for the label. Depending on the widget type
this has different default values if not specified.
color
The color for the lable. This is a table with 4 named values: r, g, b and
a for the red, green, blue and alpha channels respectively. if a is
omitted it defaults to 1. The values for r, g and b must be between
0 and 1.
width - width
height - height
pos
Where to position the label with regards to the UI element itself.
Not all widgets support all values but most do. The possible values
are "TOP" to place the label above the widget, "BOTTOM" to display
it below, "LEFT" to display it to the left, and "RIGHT" to display
it to the right.
justifyh, justifyv
How the text is justified in the label frame horizontally and
vertically. justifyh defaults to "LEFT" for most widgets, and
justifyv defaults to "MIDDLE".
cfg.parent [table]
If you need the widget to have a specific parent, set it here. Otherwise
the parent passed as the argument to the widget creation function is
used. If the parent frame passed to the creation function is a KKoreUI
container widget and it has a member called "content", then this is set
as the actual parent.
cfg.level [number]
Set the frame level to the value indicated. Not often used but its here
if you need it. The level must be no greater than 128 above the parent's
frame level.
cfg.template [string]
Set this to the name of a template to use for the widget instead of
whichever template is the default.
cfg.canmove [boolean]
Some widget types, and especially the container types, allow you to
mark the container as movable. Set this to true if you want the user
to be able to move the thing, false if not. If set to true, will cause
the OnStartMoving and OnStopMoving events to fire when moving starts
and stops.
cfg.canresize [boolean or string]
Some widget types and containers support resizing. If you want to allow
resizing, set this to boolean true if you want resizing in both the
vertical and horizontal planes. If you only want to allow vertical
resizing, set this to "HEIGHT", and if you only want to allow horizontal
resizing set this to "WIDTH". The string "BOTH" has the same meaning as
boolean true (resizing in both planes).
cfg.minheight, cfg.maxheight [number]
If cfg.canresize enables window resizing, then these two values give
the minimum and maximum height that the widget or container can be
resized to.
cfg.minwidth, cfg.maxwidth [number]
If cfg.canresize enables window resizing, then these two values give
the minimum and maximum width that the widget or container can be
resized to.
cfg.tooltip [table]
Some widgets support setting a tooltip that will be displayed when the
mouse enters them. For those widgets, you set the tooltip text and title
using this table. It can have the following three members:
title
The title for the tooltip, displayed at the top of the tooltip using
HIGHLIGHT_FONT_COLOR. By special dispensation, if this is the string
"$$" then it will be replaced by the title text of the enclosing
widget.
text
The substantive text for the tooltip, displayed using NORMAL_FONT_COLOR.
This can have embedded newlines.
func
Custom placement function. If this is set then the tooltip is anchored
to the widget by default, with its TOPLEFT set to just to the right
of the widget's TOPLEFT. You can change this placement and the frame
it is anchored to in the function. It is passed a single argument, the
widget frame pointer.
3. Utility Functions
=====================
These functions do not take the usual configuration table and parent
as their arguments. They are simply useful functions used throughout
the KKoreUI internals and useful outside too.
width, height = KUI:MeasureStrWidth (str, font)
Measures and returns the absolute width and height of the specified
string when using the specified font. If no font is specified then
this defaults to the last font used in a call to this or GetFontColor
below.
r, g, b, a = KUI.GetFontColor (font)
rgbtable = KUI.GetFontColor (font, true)
Returns the default colors for the given font, either as a set of
4 values, or as a table containing the members r, g, b and a with
those colors, if the second argument to the function was true. If
no font is specified, defaults to the last font pased to this function
or to MeasureStrWidth above.
w, h, t, b, l, r = KUI.GetFramePos (frame)
postable = KUI.GetFramePos (frame, true)
Returns the width, height, top, bottom, left and right position of the
given frame, or a table with these values names w, h, t, b, l and r
if the second argument is true,
frame = KUI.MakeFrame (type, name, parent, template)
A drop-in replacement for CreateFrame() that simply securely hooks
the SetFrameLevel() function and ensures that all children of a
frame have their levels adjusted if you change the frame level.
4. Return Values
=================
The return value from most of the widget creation functions is a frame
of the specified type, or a generic frame if it is a container. Thus all
of the functions available to frames of the given type are available to
call. There are also a few functions or values stored in this return
value which you can use. The two most important of these are :Catch()
and :Throw(), which are the mechanism used to receive and dispatch events
respectively.
ret:Catch (event, handler)
Catches the named event and calls the given handler. If no handler
is specified, returns the current handler for the event, if any.
The handler can either be a function or a string which names a
function. If you use a string the function must either be a member
of the return value (ret), or a global function. Event handlers can return
values to the caller. The first return value is a boolean which
indicates that the handler failed in some way. Return true for an
error, or nil or false if there was no error. Return any other values
after this first value.
Please refer to each widget type to see what events it throws
which you may want to catch. There are some standard events which are
thrown if you call certain functions. These events are described here.
All events take as their first argument the name of the event, followed
by any additional arguments specific to the event.
OnWidthSet (this, event, width)
Thrown when you call :SetWidth() on a widget and its width changes.
OnHeightSet (this, event, height)
Thrown when you call :SetHeight() on a widget and its height changes.
OnEnable (this, event, onoff)
Thrown when you enable or disable the widget, either by calling
:Enable() or :Disable() directly, or by calling :SetEnabled (),
which is discussed below. onoff is set to true if the widget is
being enabled or false if it is being disabled.
OnShow (this, event)
Thrown when the widget is shown by calling :Show (). This is not
quite the same thing as hooking the OnShow script.
OnHide (this, event)
Thrown when the widget is hidden by calling :Hide (). This is not
quite the same thing as hooking the OnHide script.
OnValueChanged (this, event, newval, user, ...)
For many widget types that store a value, this is thrown whenever
the value of the widget changes. Exactly how and when this is called
depends on the widget type and is discussed below. user is set to true
if this was the result of actual user interaction, false if it was
the result of a programatic change. This event may fire multiple times
for the same "action". For example, it may fire once with user set to
false (as it sets the value) and then again with user set to true if
the change was the result of the user clicking or changing the element.
ret:Throw (event, ...)
Used to throw an event for the widget. You can use this as a way of
controlling your widgets with custom events. Takes any number of
arguments all of which are pased unprocessed to any handlers.
ret:SetEnabled (onoff)
If the widget is to be enabled, pass the value of true, or pass the
value false to disable the widget. Throws "OnEnable" for the widget.
ret:SetShown (onoff)
Pass true to show the widget, false to hide it. Throws "OnShow" or
"OnHide".
5. Widgets
===========
This section discusses the basic KKoreUI widgets that are usually placed
within containers or your own frames. These are the basic "building
blocks" of a user interface. All of these widgets take the same two
parameters: the config table and the parent, which defaults to UIParent
if not specified. If the parent specified is a KKoreUI container object
and that container has a "content" member, then the actual low level
frame parent is set to that content frame, not to the outer containing
frame of the container widget. If the widget throws any extra events
they are displayed as throw:EVENTNAME (args).
In discussing each widget type below, the convention is to use
cfg.ELEMENTNAME to describe elements of the config table passed as the
first argument, and ret.VALUE or ret:FUNCTION to describe values or
functions found in the returned frame.
5.1 KUI:CreateStringLabel
-------------------------
Creates a simple frame with a text string inside it. Since this entire
widget type is a label, the various label members discussed in section 2
above are all part of the base configuration table, not in a label
element. This widget supports tooltips.
cfg.autosize [boolean]
Enabled by default. If set to false the string label remains the
exact height and width specified in cfg. Otherwise, it adjusts the
frame size and string width to accomodate the string.
cfg.border [boolean]
If set to true, surrounds the label with a thin (tooltip style) border.
ret:SetText (string)
Sets the label's string to the one specified.
ret:SetTextColor (r, g, b, a)
Sets the color of the label to the colors specified, all in the range
0 to 1.
ret.label [FontString]
Low level pointer to the actual label created by the call to
CreateFontString ().
Example:
local cfg = {
x = "CENTER", y = 0, width = 200, autosize = false, border = true,
text = "My string label", font = "GameFontHighlight",
color = { r = 1, g = 1, b = 0 }, justifyh = "CENTER",
}
local mystr = KUI:CreateStringLabel (cfg, myframe)
5.2 KUI:CreateEditBox
---------------------
Creates an input box into which the user can type text or numbers.
The default width and height are 200 and 24, respectively. Please note
that the width and height do not take the label into account. These
values control only the width and height of the edit box itself. This
widget supports tooltips.
cfg.len [number]
Sets the maximum number of characters the user can type in the edit box.
This defaults to 128.
cfg.numeric [boolean]
Set to true if the input to this field should be only numbers. Defaults
to false.
cfg.font [string]
Sets the name of the font for the text inside the edit box. Defaults
to "ChatFontNormal".
cfg.color [RGB table]
Sets the color of the text inside the edit box.
cfg.label [table]
Standard label as described in section 2 above. The label position
defaults to "LEFT".
cfg.initialvalue [string]
Sets the initial value of the edit box.
ret.label [FontString]
Low level access to the label, if any. This is the return value from
CreateFontString ().
ret.lrgb [RGB table]
The label colors.
ret.trgb [RGB table]
The actual text colors.
throw:OnEnterPressed (value)
Thrown when Enter is pressed. value is the value of the edit box at the
time that enter was pressed. This sets the "saved value" of the edit box,
If a user presses Escape while changing set, the edit box contents are
set back to the last "saved value". If the handler for this event returns
true, which signals an error, then the input focus remains in the edit box.
Otherwise, focus is cleared.
throw:OnEscapePressed ()
Thrown if the user presses Escape while entering text. When the edit box
value is restored to its last "saved value", this will also throw an
OnValueChanged () event.
throw:OnValueChanged (this, event, value, user)
Thrown whenever the value of the edit box changes. This will be thrown
when the value of the edit box is set with :SetText() or when the last
saved value is restored if a user presses Escape. It will also be thrown
when the user presses enter after entering or removing text. user is set
to true if this is the result of a user change, false if programatic.
Example:
local cfg = {
x = 0, y = -24, numeric = true, width = 32, len = 4,
label = { text = "Enter a number" },
}
local myeb = KUI:CreateEditBox (cfg, myframe)
5.3 KUI:CreateCheckBox
----------------------
Creates a checkbox that can have a boolean on/off state. When on, it has
a check mark in a little box. When off, the check mark is hidden.
Check box labels can only appear to the "LEFT" or "RIGHT" of the box.
If you need labels to appear above or below a check box for some reason
(it looks terrible visually) then set your own label manualy with
KUI:CreateStringLabel (). The default width and height are both 24.
Adjust the width for a label if you will be using one. This widget supports
tooltips.
cfg.autosize [boolean]
Usually labels do not form part of the width or height of the widget.
However, labels are so intrinsic to this widget type that they do.
Set this to true if the containing frame is to be sized when the
label of the box changes or is set, false if the size is to remain
exactly as specified. Defaults to false.
cfg.checked [boolean]
Set to true if the box should start out in the checked state, false if not.
ret:SetText (text)
Sets the checkbox label to the specified text, and resizes the whole
frame if cfg.autosize was true.
ret:GetChecked ()
Returns true or false if the button is or is not checked.
ret:SetChecked (onoff)
Sets the checked state to on (if onoff is true) or off (if it is false).
ret:ToggleChecked ()
Toggles the current checked state.
ret.text [FontString]
Low level pointer to the label, if any.
ret.rgb [RGB table]
The color of the lable, if any.
throw:OnClick (checked)
Throws when the button is clicked. checked is set to the current state
of the button after the click was processed (in other words after the
state was changed and the new current value set).
throw:OnValueChanged (onoff, user)
Thrown whenever the state of the button changes. onoff is set to false
if the button is unchecked, true if it is checked. user is true if this
was the result of a user action, false otherwise. May fire multiple
times
Example:
local cfg = {
x = 0, y = 0, checked = true, label = { text = "Option 1" },
}
local mycb = KUI:CreateCheckBox (cfg, myframe)
mycb:Catch ("OnValueChanged", function (this, event, onoff)
print ("Option 1 set to " .. tostring(onoff))
end)
5.4 KUI:CreateRadioButton
-------------------------
Radio buttons are a group of buttons which have a mutually exclusive
choice (i.e. only one button in a radio group can be selected or
checked at a time). For this reason, a mandatory element in the config
table is the "group" element that groups all radio buttons in a
group together. In order for radio buttons to work, all of the radio
buttons must share a common parent. That parent can contain any number
of radio button groups, but still, each group can only ever have one
of its buttons pressed at a time. The default width and height are
both 16. Adjust the width for a label if you will be using one.
This widget supports tooltips.
cfg.autosize [boolean]
Usually labels do not form part of the width or height of the widget.
However, labels are so intrinsic to this widget type that they do.
Set this to true if the containing frame is to be sized when the
label of the box changes or is set, false if the size is to remain
exactly as specified. Defaults to false.
cfg.group [string]
The name of the radio button group to which this radio button belongs.
cfg.groupparent [table]
Set this to an explicit parent that contains the radio button group.
If not set this defaults to the parent specified in the call. If
that parent is some type of container and does not itself contain
all of the radio buttons in the group, use this to set a top level
parent that will contain all of the radio buttons. If you set this
you may also need to set the getbutton element below.
cfg.checked [boolean]
Set to true if this radio button should be selected by default,
false otherwise.
cfg.value [anything]
Set the value for this particular radio button. Each button in the
group must have a unique value (not enforced).
cfg.func [function]
A convenience function that is called whenever the value of a radio
group changes. In order for this to have any meaning, all of the
buttons in a group should use the same function. This is essentially
just a convenient way of attaching an OnValueChanged event to each
radio button in a group. This function takes as its values a pointer
to the button that was pressed, whether the button is on or off, and
the button value:
local radiofunc (this, onoff, value)
...
end
cfg.getbutton [function]
Function that takes the radio button frame as its only argument.
This function must return a pointer to the parent that contains the
radio group. This really is very rarely used, and the best way to
understand why it is necessary is to look at the internals of
KKoreUI. Not for the weak of heart.
ret:SetChecked ()
Sets this specific radio button to the one and only one in the group
that is checked. This will cause OnValueChanged events to be fired
both for the button being checked and for the button that is
currently checked becoming unchecked. There is NO guarantee of the
order in which these two events fire.
ret:SetValue (value, nothrow)
Sets the value for the entire radio group to the value specified.
Essentially this just searches through all of the radio buttons in
the group until it finds one with a matching value, and if that was
not already set, set it to the current checked button. This will
also cause OnValueChanged events to fire for both the new button and
the previously selected one. Note that each button in the radio
group gets this function. Regardless of which button's function you
call it will set the value for the entire group. If nothrow is true,
do not throw an OnValueChanged event.
ret:GetValue ()
Searches the radio group for the currently selected button and
return its value.
throw:OnValueChanged (onoff, user, value)
Thrown when a buttons state changes. onoff is true if this is the
currently selected button, false otherwise. value is the value of
the button. user is whether this was a user initiated change or a
programatic one.
Example:
local cfg = {
x = 0, y = 0, group = "mygroup", value = 1, checked = true,
label = { text = "Exclusive option 1" },
}
local myrb1 = KUI:CreateRadioButton (cfg, myparent)
cfg.y = -16
cfg.value = 2
cfg.label.text = "Exclusive option 2"
cfg.checked = false
local myrb2 = KUI:CreateRadioButton (cfg, myparent)
cfg.y = -32
cfg.value = 3
cfg.label.text = "Exclusive option 3"
local myrb3 = KUI:CreateRadioButton (cfg, myparent)
print ("Current option: " .. tostring(myrb3:GetValue ()))
5.5 KUI:CreateSlider
--------------------
This widget type allows you to create either a vertical or horizontal
slider that lets you drag a thumbnail to increase and decrease the slider
value in defined increments between a given minimum and maximum value.
A horizontal slider has a default width of 200 and height of 16, and
a vetical slider has a default width of 16 and height of 200. This widget
supports tooltips.
cfg.orientation [string]
Either "HORIZONTAL" or "VERTICAL". Defaults to "HORIZONTAL".
cfg.minval [number]
Sets the minimum value for the slider. Defaults to 0.
cfg.maxval [number]
Sets the maximum value for the slider. Defaults to 100.
cfg.step [number]
Sets the increment that the slider can change by. Defaults to 1.
cfg.initialvalue [number]
Sets the initial value. Defaults to minval if not specified.
cfg.minmaxfont [string]
Name of the font to use to display the minimum and maximum values.
Defaults to "GameFontHighlightSmall".
cfg.minmaxcolor [RGB table]
Sets the color for the minimum and maximum values. Defaults to whatever
the color is for the font.
cfg.editfont [string]
Sets the font for the edit box that appears in the middle of the slider
where the user can manually type in a value. Defaults to
"GameFontHighlightSmall".
cfg.editcolor [RGB table]
Sets the color of the edit box text. Defaults to whatever the default
color for the font is.
cfg.label [table]
Only valid for HORIZONTAL sliders. Sets the title of the slider that
is always displayed above the slider (the pos element is ignored).
throw:OnValueChanged (value, user)
Thrown when the value changes by whatever mechanism.
ret.editbox [table]
Pointer to the raw edit box.
ret.mintxt [FontString]
Pointer to the raw font string for the minimum value.
ret.maxtxt [FontString]
Pointer to the raw font string for the maximum value.
ret.mrgb [RGB table]
Colors for the minumuma nd maximum strings.
ret.ergb [RGB table]
Colors for the edit box.
ret.label [FontString]
Pointer to the raw label font string.
ret.lrgb [RGB table]
Colors for the label.
ret:ChangeMinMax(newmin, newmax)
Example:
local cfg = {
x = 0, y = -60, initialvalue = 42,
label = { text = "My Slider", justifyh = "CENTER" },
}
local myslider = KUI:CreateSlider (cfg, parent)
5.6 KUI:CreateButton
--------------------
Creates a simple pushbutton based on the UIPanelButtonTemplate template.
This widget supports tooltips.
cfg.template [string]
Name of an alternate button template to use if you do not want to use
the default UIPanelButtonTemplate template. If you dont want to use
any template set this to the empty string ("").
cfg.hook [boolean]
When set to true, hook the OnClick function rather than setting it.
You would want to do with if you want to preserve the OnClick handler
from a template. If this is nil or false, set an onclick handler that
will :Throw() an OnClick event. If set to true, :Throw () the onclick
event only after the template's OnClick handler has run.
cfg.text [string]
Text to display on the button (if any).
throw:OnClick (button, down)
Thrown when the button is clicked. BUTTON is the name of the button that
was pressed, and DOWN is true if the button is being pressed, false or nil
if it is being released.
5.7 KUI:CreateDropDown
----------------------
Custom replacement for the notoriously confusing Blizzard dropdown menu code.
Visually a KUI dropdown looks almost identical to the Blizzard one, but the
internals are extremely different. This widget type must be given a name.
Drop down menus can be either a simple single level drop down, or any of the
items on the menu can be a submenu, with no restriction other than a practical
one of how deep you can stack submenus. Submenus will automatically close the
dropped down portion when the mouse leaves it for any length of time (which is
configurable). This widget has two distinct portions. The first is the
"static" portion that has the push button for displaying the drop down menu,
and the string which has the current value or title, and the second portion
is the actual menu that drops down below it when you press the drop down
button. In this discussion, the first is refered to as the static portion
and the second as the menu portion. This widget supports tooltips for the
static portion, as well as individual tooltips for each menu item.
Note that if a given menu has too many items to fit in the specified
or calculated minimum / maximum height and width of the menu, the code
will provide a small scrollbar on the left side of menu, which can be
clicked or scrolled using the mouse wheel.
cfg.name [string]
Name of the dropdown. Must be provided for all dropdowns, including
submenus.
cfg.items [table]
Menu items for the dropdown. See below for details. Must be provided.
If you need to create an empty dropdown that you will populate later,
set this to KUI.emptydropdown.
cfg.dwidth [number]
The width of the static user-interface portion of the dropdown.
Must be provided.
cfg.label [table]
Label for the dropdown menu.
cfg.justifyh [string]
Justification for the static text portion. Defaults to "LEFT".
cfg.border [string]
Sets the border style. Values are "THICK" (the default) for dialog
style borders, or "THIN" for tooltip style borders. This is the
border used for the menu portion.
cfg.mode [string]
Sets the "mode" for the dropdown. Can have one of three possible
values: "SINGLE" (the default if no mode is specified) for a dropdown
menu that allows you to select a single value from a list of
choices, "MULTI" which allows you to check multiple options, or
"COMPACT", which is the same as "SINGLE" but has no check marks
in order to save space. These values set the default for each item's
"keep" and "notcheckable" options See below for details.
cfg.arg [anything]
Argument that is set for each menu item as its "tlarg" element.
cfg.func [function (tbf, created)]
Function that is called with the item being clicked or created,
and a boolean indicating if the function is being called because
the item was just created. The tbf parameter is the full item
frame, with all of its values, as specified below.
cfg.itemheight [number]
Optional. If set, sets the default height for each item so that you
do not need to specify it for each and every item. An individual
item may still override this default by specifying a height.
cfg.timeout [number]
Sets how long the mouse cursor must be out of the bounds of the
static or menu portions before the dropdown is automatically closed.
Defaults to 3 seconds.
cfg.minheight, cfg.maxheight [number]
If the menu portion is to be resizable, sets the minimum and maximum
height of the menu, respectively. See section 2 for details.
cfg.minwidth, cfg.maxwidth [number]
If the menu portion is to be resizable, sets the minimum and maximum
width of the menu. See section 2 for details.
cfg.canresize [boolean or string]
Allow or disallow resizing. See section 2 above for details.
cfg.title [table]
Same type of table as a label. This is only used for MULTI mode
dropdowns where a clear choice about what to display in the static
text box cannot be made. With SINGLE or COMPACT mode dropdowns,
the static text is set to the currently selected item, but since
multiple items can be selected for a MULTI mode dropdown, this has
less meaning. Thus, this title. This sets the permanent value of the
static text box to this value. If this is not specified and the
first item in the item list is a title item that is used instead.
If the first item is not a title, a multi mode drop down will have no
value set by this code and you should set it yourself.
cfg.width [number]
Set the width of this dropdown menu. If this is not set, then the
default width of the dropdown is set to be just wide enough to contain
the widest text or frame item.
cfg.height [number]
Sets the height of this dropown menu. If this is not set, then the
height of the dropdown is set to be high enough to cover all of
the items, or 300, whichever is less. If the height required to show
all of the items is greater than this value, then the dropdown will
be scrollable.
ret:SetJustification (how)
How to justify the text in the static portion of the dropdown.
Defaults to "LEFT".
ret:UpdateItems (newitemtable)
Updates the menu portion to have the new items specified. This must be
the full list of items, there is no mechanism to randomly insert or
delete or modify items.
ret:GetValue ()
Returns the value of the currently selected item or nil if no item
is selected.
ret:SetValue (value, nothrow)
Sets the currently selected item to the first item that matches the
specified value. Ideally, each item in a dropdown will have a
unique value. If not, there is no guarantee which item with the same
value will actually become checked. If nothrow is true, do not thow an
OnValueChanged event.
ret:Close ()
Closes the dropdown menu and any submenus
ret:StopTimeoutCounter()
ret:StartTimeoutCounter ()
Two functions to be called whenever the mouse enters or leaves the bounds
of any portion of the dropdown.
ret.text [FontString]
Pointer to the raw font string that holds the displayed text
string of the current value or title.
ret.button [table]
Pointer to the raw button that when pressed, will cause the
menu to drop down.
ret.label [FontString]
Pointer to the low level font string for the label, if any.
ret.labelcolor [RGB table]
Color values for the label.
ret.toplevel [table]
Pointer to itself, as this is the top level of the dropdown.
ret.dropdown [table]
The pointer to the top level drop down menu. This and all subsequent
submenus all have the same values inside. The values of this table are:
.toplevel [table]
Pointer to the very top level. Same as the return value from
KUI:CreateDropDown().
.sframe [table]
Pointer to the scrolling frame that contains the items.
.cframe [table]
Pointer to the child frame which is set as the child of .sframe.
This is the actual low level parent of all of the items.
.scrollbar [table]
Pointer to the scrollbar object that is positioned to the left of all
of the items if it needs to scroll.
.iframes [table]
Table of each individual item frame.
.current [table]
Pointer to the currently selected item.
ret.trgb
The color for the static text title if the mode is MULTI.
throw:OnClick ()
Thrown when the dropdown button is clicked and the dropdown either hidden
or shown.
throw:OnItemChecked (item, checked)
Thrown when an item is checked on unchecked.
throw:OnValueChanged (value, user)
Thrown when a new item is selected in a SINGLE or COMPACT drop down
and the drop down value changes.
5.7.1 Menu Item Table
---------------------
For a dropdown, you define the choices by passing an item table through the
main config structure. This is a table of tables, each element of
which desribes a single item on the menu. This section describes the
various values that can be set for each item.
Each item must be either a text item or a custom frame, not both.
Thus you need provide only menu.frame or menu.text. It is an error
to provide both, or neither.
menu.name [string]
Individual item name, possibly used by the handler function.
menu.func [function (item, created)]
Function that is passed the item frame and whether or not the item has
just been created. This is called when the item is clicked and when
it is created. Optional.
menu.arg [anything]
Presumably useful to the function above.
menu.value [anything]
Unique value for the menu item.
menu.tooltip [table]
Tooltip for this item. See section 2 above for details.
menu.color [RGB table or function]
Color for the menu item text. Can be a table or a function that
returns a table.
menu.title [boolean or function]
Whether or not this item is a title. Title items cannot be clicked on
or checked. Can be a boolean or a function returning a boolean. Title
items are displayed in a different font ("GameFontNormalSmallLeft" by
default). They are always both nocheckable and nonclickable.
menu.enabled [boolean or function]
Whether or not this item is enabled. Can be a boolean or a function
that returns a boolean.
menu.checked [boolean or function]
Whether or not this item should be checked. Can be a boolean or a
function that returns a boolean.
menu.keep [boolean or function]
This can be a boolean or a function returning a boolean. If set to
true, keep the dropdown menu open even after the item is clicked.
If set to false, close the dropdown when the item is clicked. The
default value for this depends on the dropdown type. For SINGLE and
COMPACT mode dropdowns, this defaults to false. For MULTI mode
dropdowns it defaults to true. However, regardless of mode, if you
explicitly set this for an item, it will be obeyed.
menu.text [string or function]
Either a string or a function that returns a string. This element is
mutually exclusive with menu.frame (see below). If this is specified
then this is a normal menu item or the text for a submenu. Unless
other options below prevent it, a normal menu item is both clickable
and checkable. This is the most common type of menu item. By
special dispensation, if the string (or return value from the
function) is a single hyphen ("-"), then this becomes a menu
"spacer" item that is neither clickable not checkable, and draws a
thin horizontal line between two sections of a menu. The default
font for text items is "GameFontHighlightSmallLeft"
menu.notclickable [boolean or function]
A boolean or a function returning a boolean. If set to true, then this
item is not clickable (and by extension, not checkable). This is
rarely used with text menu items but is more commonly used with
custom frame menu items that are simply placing textures or other
content in the menu.
menu.notcheckable [boolean or function]
A boolean or a function returning a boolean. Setting this to true means
the item can not be checked. More accurately, it means it will not have
a checkmark ascociated with it. COMPACT mode menus force this to true.
SINGLE and MULTI mode menus set it to false by default.
menu.icon [string or function]
The name of an icon or a function return such a name. This is forced
to be a 16x16 sized icon. This icon will appear between the checkmark
(if any) and the left edge of the frame or text.
menu.iconcoord [table]
If menu.icon is set above, this can be a set of texture co-ordinates
for the icon. This uses the 4-call version of SetTexCoord (). The table
can have members called left (defaults to 0), right (defaults to 1),
top (defaults to 0) and bottom (defaults to 1).
menu.font [string or function]
Font to use for a title or text item.
menu.height [number]
Set this item to be this number of pixels high. If not set, inherits the
containing menu's itemheight value. If the menu does not have itemheight
set then this value must be provided.
menu.width [number]
Set this item to be this number of pixels wide. If not specified this
defaults to the width of the text string or frame.
menu.frame [table or function]
There may be times when you need a custom frame for a menu item to
represent something in the menu other than a simple checkbox choice.
For these situations, you can provide your own frame that is
placed in the menu by the KKoreUI code. This is rarely used for
dropdown menus, but more commonly used for popup menus. This element
must either be a frame or a function that returns a frame. It is the
responsibility of these custom frames to call the StartTimeoutCounter
and StopTimeoutCounter when the mouse leaves or enters the frame. In
order to make it easier to insert custom frames, if you set this
element to be boolean true, then this will call an internal KKoreUI
function that allows you to place one of a number of widgets on the
menu. If you use this facility, then you must set the menu.widget
element below to one of the supported widget names, and provide any
extra elements that widget may require as part of this menu item
table. If you set this to any other value then you need to manage the
frame yourself.
menu.widget [string]
If you are using a custom frame and you are using the internal KKoreUI
custom frame creation function (by setting menu.frame to true), then this
element tells KKoreUI which widget type to create for the custom frame.
For each of these widget types, you may need to set extra elements in
the menu item table to provide configuration options for the widget.
Where this is the case is is described along with the widget type.
Note that using this feature requires the full KKoreUI library. If
you have stripped out just the dropdown portion, you may not be able to
use this feature. However, this document assumes you are using the
full KKoreUI, so please note that these widget types use the widgets
described above, so the purpose of the extra values is not discussed here.
Refer to the individual widget types above for details. The KKoreUI
widget type is displayed in parentheses.
"radio" (KUI:CreateRadioButton)
This widget type creates a radio button. Extra item elements you need
to provide are:
menu.group - the radio button group name
"slider" (KUI:CreateSlider)
Create a slider widget. The additional elements are:
menu.orientation - slider orientation (defaults to "VERTICAL")
menu.editfont - edit box font
menu.editcolor - edit box text color
menu.minmaxfont - minimum and maximum value font
menu.minmaxcolor - minimum and maximum value color
menu.minval - minimum slider value
menu.maxval - maximum slider value
menu.step - slider step increment
menu.initialvalue - initial slider value
menu.label - the text for the label. Note that this is not the full