comparison Libs/DF/panel.lua @ 49:7d5934415ad0 r49-release

- framework update.
author Tercio
date Wed, 05 Jul 2017 15:20:21 -0300
parents 2bbf129690b0
children 36b4d9559b69
comparison
equal deleted inserted replaced
48:a671a2cf52ee 49:7d5934415ad0
515 515
516 ------------fill panel 516 ------------fill panel
517 517
518 local button_on_enter = function (self) 518 local button_on_enter = function (self)
519 self.MyObject._icon:SetBlendMode ("ADD") 519 self.MyObject._icon:SetBlendMode ("ADD")
520 if (self.MyObject.onenter_func) then
521 pcall (self.MyObject.onenter_func, self.MyObject)
522 end
520 end 523 end
521 local button_on_leave = function (self) 524 local button_on_leave = function (self)
522 self.MyObject._icon:SetBlendMode ("BLEND") 525 self.MyObject._icon:SetBlendMode ("BLEND")
526 if (self.MyObject.onleave_func) then
527 pcall (self.MyObject.onleave_func, self.MyObject)
528 end
523 end 529 end
524 530
525 local add_row = function (self, t, need_update) 531 local add_row = function (self, t, need_update)
526 local index = #self.rows+1 532 local index = #self.rows+1
527 533
534 thisrow.notext = t.notext 540 thisrow.notext = t.notext
535 thisrow.icon = t.icon 541 thisrow.icon = t.icon
536 thisrow.iconalign = t.iconalign 542 thisrow.iconalign = t.iconalign
537 543
538 thisrow.hidden = t.hidden or false 544 thisrow.hidden = t.hidden or false
545
546 thisrow.onenter = t.onenter
547 thisrow.onleave = t.onleave
539 548
540 local text = DF:NewLabel (thisrow, nil, self._name .. "$parentLabel" .. index, "text") 549 local text = DF:NewLabel (thisrow, nil, self._name .. "$parentLabel" .. index, "text")
541 text:SetPoint ("left", thisrow, "left", 2, 0) 550 text:SetPoint ("left", thisrow, "left", 2, 0)
542 text:SetText (t.name) 551 text:SetText (t.name)
543 552
616 entry:SetWidth (row.width - 25) 625 entry:SetWidth (row.width - 25)
617 else 626 else
618 entry:SetWidth (row.width) 627 entry:SetWidth (row.width)
619 end 628 end
620 entry.func = row.func 629 entry.func = row.func
630
631 entry.onenter_func = nil
632 entry.onleave_func = nil
633
634 if (row.onenter) then
635 entry.onenter_func = row.onenter
636 end
637 if (row.onleave) then
638 entry.onleave_func = row.onleave
639 end
621 end 640 end
622 elseif (type == "button") then 641 elseif (type == "button") then
623 for i = 1, #self.scrollframe.lines do 642 for i = 1, #self.scrollframe.lines do
624 local line = self.scrollframe.lines [i] 643 local line = self.scrollframe.lines [i]
625 local button = tremove (line.button_available) 644 local button = tremove (line.button_available)
650 end 669 end
651 670
652 if (row.name and not row.notext) then 671 if (row.name and not row.notext) then
653 button._text:SetPoint ("left", button._icon, "right", 2, 0) 672 button._text:SetPoint ("left", button._icon, "right", 2, 0)
654 button._text.text = row.name 673 button._text.text = row.name
655 end 674 end
675
676 button.onenter_func = nil
677 button.onleave_func = nil
678
679 if (row.onenter) then
680 button.onenter_func = row.onenter
681 end
682 if (row.onleave) then
683 button.onleave_func = row.onleave
684 end
656 685
657 end 686 end
658 elseif (type == "icon") then 687 elseif (type == "icon") then
659 for i = 1, #self.scrollframe.lines do 688 for i = 1, #self.scrollframe.lines do
660 local line = self.scrollframe.lines [i] 689 local line = self.scrollframe.lines [i]
665 end 694 end
666 tinsert (line.icon_inuse, icon) 695 tinsert (line.icon_inuse, icon)
667 icon:SetPoint ("left", line, "left", self._anchors [#self._anchors] + ( ((row.width or 22) - 22) / 2), 0) 696 icon:SetPoint ("left", line, "left", self._anchors [#self._anchors] + ( ((row.width or 22) - 22) / 2), 0)
668 icon.func = row.func 697 icon.func = row.func
669 end 698 end
699
700 elseif (type == "texture") then
701 for i = 1, #self.scrollframe.lines do
702 local line = self.scrollframe.lines [i]
703 local texture = tremove (line.texture_available)
704 if (not texture) then
705 self:CreateRowTexture (line)
706 texture = tremove (line.texture_available)
707 end
708 tinsert (line.texture_inuse, texture)
709 texture:SetPoint ("left", line, "left", self._anchors [#self._anchors] + ( ((row.width or 22) - 22) / 2), 0)
710 end
711
670 end 712 end
671 713
672 sindex = sindex + 1 714 sindex = sindex + 1
673 else 715 else
674 row:Hide() 716 row:Hide()
685 727
686 self.showing_amt = rows_shown 728 self.showing_amt = rows_shown
687 end 729 end
688 730
689 local update_rows = function (self, updated_rows) 731 local update_rows = function (self, updated_rows)
732
690 for i = 1, #updated_rows do 733 for i = 1, #updated_rows do
691 local t = updated_rows [i] 734 local t = updated_rows [i]
692 local raw = self._raw_rows [i] 735 local raw = self._raw_rows [i]
693 736
694 if (not raw) then 737 if (not raw) then
703 widget.name = t.name 746 widget.name = t.name
704 widget.textsize = t.textsize 747 widget.textsize = t.textsize
705 widget.textalign = t.textalign 748 widget.textalign = t.textalign
706 widget.hidden = t.hidden or false 749 widget.hidden = t.hidden or false
707 750
751 --
752 widget.onenter = t.onenter
753 widget.onleave = t.onleave
754 --
755
708 widget.text:SetText (t.name) 756 widget.text:SetText (t.name)
709 DF:SetFontSize (widget.text, raw.textsize or 10) 757 DF:SetFontSize (widget.text, raw.textsize or 10)
710 widget.text:SetJustifyH (raw.textalign or "left") 758 widget.text:SetJustifyH (raw.textalign or "left")
711 759
712 end 760 end
745 tinsert (row.icon_available, tremove (row.icon_inuse, i)) 793 tinsert (row.icon_available, tremove (row.icon_inuse, i))
746 end 794 end
747 for i = 1, #row.icon_available do 795 for i = 1, #row.icon_available do
748 row.icon_available[i]:Hide() 796 row.icon_available[i]:Hide()
749 end 797 end
798
799 for i = #row.texture_inuse, 1, -1 do
800 tinsert (row.texture_available, tremove (row.texture_inuse, i))
801 end
802 for i = 1, #row.texture_available do
803 row.texture_available[i]:Hide()
804 end
750 end 805 end
751 806
752 self.current_header = updated_rows 807 self.current_header = updated_rows
753 808
754 self:AlignRows() 809 self:AlignRows()
769 editbox:SetHook ("OnEnterPressed", function() 824 editbox:SetHook ("OnEnterPressed", function()
770 editbox.widget.focuslost = true 825 editbox.widget.focuslost = true
771 editbox:ClearFocus() 826 editbox:ClearFocus()
772 editbox.func (editbox.index, editbox.text) 827 editbox.func (editbox.index, editbox.text)
773 return true 828 return true
774 end) 829 end)
830
831 editbox:SetHook ("OnEnter", function()
832 if (editbox.onenter_func) then
833 pcall (editbox.onenter_func, editbox)
834 end
835 end)
836 editbox:SetHook ("OnLeave", function()
837 if (editbox.onleave_func) then
838 pcall (editbox.onleave_func, editbox)
839 end
840 end)
775 841
776 editbox:SetBackdrop ({bgFile = [[Interface\DialogFrame\UI-DialogBox-Background]], edgeFile = "Interface\\ChatFrame\\ChatFrameBackground", edgeSize = 1}) 842 editbox:SetBackdrop ({bgFile = [[Interface\DialogFrame\UI-DialogBox-Background]], edgeFile = "Interface\\ChatFrame\\ChatFrameBackground", edgeSize = 1})
777 editbox:SetBackdropColor (1, 1, 1, 0.1) 843 editbox:SetBackdropColor (1, 1, 1, 0.1)
778 editbox:SetBackdropBorderColor (1, 1, 1, 0.1) 844 editbox:SetBackdropBorderColor (1, 1, 1, 0.1)
779 editbox.editbox.current_bordercolor = {1, 1, 1, 0.1} 845 editbox.editbox.current_bordercolor = {1, 1, 1, 0.1}
782 end 848 end
783 849
784 local create_panel_button = function (self, row) 850 local create_panel_button = function (self, row)
785 row.button_total = row.button_total + 1 851 row.button_total = row.button_total + 1
786 local button = DF:NewButton (row, nil, "$parentButton" .. row.button_total, "button" .. row.button_total, 120, 20) 852 local button = DF:NewButton (row, nil, "$parentButton" .. row.button_total, "button" .. row.button_total, 120, 20)
787 --, nil, nil, nil, nil, nil, nil, DF:GetTemplate ("button", "OPTIONS_BUTTON_TEMPLATE")
788 --button:InstallCustomTexture()
789 853
790 --> create icon and the text 854 --> create icon and the text
791 local icon = DF:NewImage (button, nil, 20, 20) 855 local icon = DF:NewImage (button, nil, 20, 20)
792 local text = DF:NewLabel (button) 856 local text = DF:NewLabel (button)
793 857
822 iconbutton._icon = icon 886 iconbutton._icon = icon
823 887
824 icon:SetPoint ("center", iconbutton, "center", 0, 0) 888 icon:SetPoint ("center", iconbutton, "center", 0, 0)
825 889
826 tinsert (row.icon_available, iconbutton) 890 tinsert (row.icon_available, iconbutton)
891 end
892
893 local create_panel_texture = function (self, row)
894 row.texture_total = row.texture_total + 1
895 local texture = DF:NewImage (row, nil, 20, 20, "artwork", nil, "_icon" .. row.texture_total, "$parentIcon" .. row.texture_total)
896 tinsert (row.texture_available, texture)
827 end 897 end
828 898
829 local set_fill_function = function (self, func) 899 local set_fill_function = function (self, func)
830 self._fillfunc = func 900 self._fillfunc = func
831 end 901 end
870 panel.UpdateRows = update_rows 940 panel.UpdateRows = update_rows
871 panel.CreateRowText = create_panel_text 941 panel.CreateRowText = create_panel_text
872 panel.CreateRowEntry = create_panel_entry 942 panel.CreateRowEntry = create_panel_entry
873 panel.CreateRowButton = create_panel_button 943 panel.CreateRowButton = create_panel_button
874 panel.CreateRowIcon = create_panel_icon 944 panel.CreateRowIcon = create_panel_icon
945 panel.CreateRowTexture = create_panel_texture
875 panel.SetFillFunction = set_fill_function 946 panel.SetFillFunction = set_fill_function
876 panel.SetTotalFunction = set_total_function 947 panel.SetTotalFunction = set_total_function
877 panel.DropHeader = drop_header_function 948 panel.DropHeader = drop_header_function
878 949
879 panel._name = name 950 panel._name = name
904 if (index <= filled_lines) then 975 if (index <= filled_lines) then
905 976
906 local real_index = index + offset 977 local real_index = index + offset
907 local results = panel._fillfunc (real_index, panel) 978 local results = panel._fillfunc (real_index, panel)
908 979
909 if (results [1]) then 980 if (results and results [1]) then
910 row:Show() 981 row:Show()
911 982
912 local text, entry, button, icon = 1, 1, 1, 1 983 local text, entry, button, icon, texture = 1, 1, 1, 1, 1
913 984
914 for index, t in ipairs (panel.rows) do 985 for index, t in ipairs (panel.rows) do
915 if (not t.hidden) then 986 if (not t.hidden) then
916 if (t.type == "text") then 987 if (t.type == "text") then
917 local fontstring = row.text_inuse [text] 988 local fontstring = row.text_inuse [text]
918 text = text + 1 989 text = text + 1
919 fontstring:SetText (results [index]) 990 fontstring:SetText (results [index])
920 fontstring.index = real_index 991 fontstring.index = real_index
921 fontstring:Show() 992 fontstring:Show()
922
923 if (true) then
924 --print (t.hello)
925 end
926 993
927 elseif (t.type == "entry") then 994 elseif (t.type == "entry") then
928 local entrywidget = row.entry_inuse [entry] 995 local entrywidget = row.entry_inuse [entry]
929 entry = entry + 1 996 entry = entry + 1
930 entrywidget:SetText (results [index])
931 entrywidget.index = real_index 997 entrywidget.index = real_index
998
999 if (type (results [index]) == "table") then
1000 entrywidget:SetText (results [index].text)
1001 entrywidget.id = results [index].id
1002 entrywidget.data1 = results [index].data1
1003 entrywidget.data2 = results [index].data2
1004 else
1005 entrywidget:SetText (results [index])
1006 end
1007
1008 entrywidget:SetCursorPosition(0)
1009
932 entrywidget:Show() 1010 entrywidget:Show()
933 1011
934 elseif (t.type == "button") then 1012 elseif (t.type == "button") then
935 local buttonwidget = row.button_inuse [button] 1013 local buttonwidget = row.button_inuse [button]
936 button = button + 1 1014 button = button + 1
937 buttonwidget.index = real_index 1015 buttonwidget.index = real_index
938 1016
939
940
941 if (type (results [index]) == "table") then 1017 if (type (results [index]) == "table") then
942 if (results [index].text) then 1018 if (results [index].text) then
943 buttonwidget:SetText (results [index].text) 1019 buttonwidget:SetText (results [index].text)
944 end 1020 end
945 1021
958 t.func (real_index, index) 1034 t.func (real_index, index)
959 panel:Refresh() 1035 panel:Refresh()
960 end 1036 end
961 buttonwidget:SetClickFunction (func) 1037 buttonwidget:SetClickFunction (func)
962 end 1038 end
1039
1040 buttonwidget.id = results [index].id
1041 buttonwidget.data1 = results [index].data1
1042 buttonwidget.data2 = results [index].data2
1043
963 else 1044 else
964 local func = function() 1045 local func = function()
965 t.func (real_index, index) 1046 t.func (real_index, index)
966 panel:Refresh() 1047 panel:Refresh()
967 end 1048 end
985 else 1066 else
986 iconwidget._icon:SetTexture (results [index]) 1067 iconwidget._icon:SetTexture (results [index])
987 end 1068 end
988 1069
989 iconwidget:Show() 1070 iconwidget:Show()
1071
1072 elseif (t.type == "texture") then
1073 local texturewidget = row.texture_inuse [texture]
1074 texture = texture + 1
1075
1076 texturewidget.line = index
1077 texturewidget.index = real_index
1078
1079 if (type (results [index]) == "string") then
1080 local result = results [index]:gsub (".-%\\", "")
1081 texturewidget.texture = results [index]
1082 else
1083 texturewidget:SetTexture (results [index])
1084 end
1085
1086 texturewidget:Show()
990 end 1087 end
991 end 1088 end
992 end 1089 end
993 1090
994 else 1091 else
1008 local filled_lines = panel._totalfunc (panel) 1105 local filled_lines = panel._totalfunc (panel)
1009 local scroll_total_lines = #panel.scrollframe.lines 1106 local scroll_total_lines = #panel.scrollframe.lines
1010 local line_height = options.rowheight 1107 local line_height = options.rowheight
1011 refresh_fillbox (panel.scrollframe) 1108 refresh_fillbox (panel.scrollframe)
1012 FauxScrollFrame_Update (panel.scrollframe, filled_lines, scroll_total_lines, line_height) 1109 FauxScrollFrame_Update (panel.scrollframe, filled_lines, scroll_total_lines, line_height)
1110 panel.scrollframe:Show()
1013 end 1111 end
1014 1112
1015 local scrollframe = CreateFrame ("scrollframe", name .. "Scroll", panel.widget, "FauxScrollFrameTemplate") 1113 local scrollframe = CreateFrame ("scrollframe", name .. "Scroll", panel.widget, "FauxScrollFrameTemplate")
1016 scrollframe:SetScript ("OnVerticalScroll", function (self, offset) FauxScrollFrame_OnVerticalScroll (self, offset, 20, panel.Refresh) end) 1114 scrollframe:SetScript ("OnVerticalScroll", function (self, offset) FauxScrollFrame_OnVerticalScroll (self, offset, 20, panel.Refresh) end)
1017 scrollframe:SetPoint ("topleft", panel.widget, "topleft", 0, -21) 1115 scrollframe:SetPoint ("topleft", panel.widget, "topleft", 0, -21)
1057 row.button_total = 0 1155 row.button_total = 0
1058 1156
1059 row.icon_available = {} 1157 row.icon_available = {}
1060 row.icon_inuse = {} 1158 row.icon_inuse = {}
1061 row.icon_total = 0 1159 row.icon_total = 0
1160
1161 row.texture_available = {}
1162 row.texture_inuse = {}
1163 row.texture_total = 0
1062 end 1164 end
1063 end 1165 end
1064 panel:UpdateRowAmount() 1166 panel:UpdateRowAmount()
1065 1167
1066 panel.AlignRows (panel) 1168 panel.AlignRows (panel)
1524 end) 1626 end)
1525 end 1627 end
1526 1628
1527 local no_options = {} 1629 local no_options = {}
1528 function DF:CreateSimplePanel (parent, w, h, title, name, panel_options, db) 1630 function DF:CreateSimplePanel (parent, w, h, title, name, panel_options, db)
1529 1631
1530 if (db and name and not db [name]) then 1632 if (db and name and not db [name]) then
1531 db [name] = {scale = 1} 1633 db [name] = {scale = 1}
1532 end 1634 end
1533 1635
1534 if (not name) then 1636 if (not name) then
1538 if (not parent) then 1640 if (not parent) then
1539 parent = UIParent 1641 parent = UIParent
1540 end 1642 end
1541 1643
1542 panel_options = panel_options or no_options 1644 panel_options = panel_options or no_options
1543 1645
1544 local f = CreateFrame ("frame", name, UIParent) 1646 local f = CreateFrame ("frame", name, UIParent)
1545 f:SetSize (w or 400, h or 250) 1647 f:SetSize (w or 400, h or 250)
1546 f:SetPoint ("center", UIParent, "center", 0, 0) 1648 f:SetPoint ("center", UIParent, "center", 0, 0)
1547 f:SetFrameStrata ("FULLSCREEN") 1649 f:SetFrameStrata ("FULLSCREEN")
1548 f:EnableMouse() 1650 f:EnableMouse()