-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexampleaddon_view.lua
More file actions
131 lines (108 loc) · 5.12 KB
/
exampleaddon_view.lua
File metadata and controls
131 lines (108 loc) · 5.12 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
ADDON:ImportObject(OBJECT.TextStyle)
ADDON:ImportObject(OBJECT.Window)
ADDON:ImportObject(OBJECT.Button)
ADDON:ImportObject(OBJECT.CheckButton)
ADDON:ImportObject(OBJECT.Textbox)
ADDON:ImportObject(OBJECT.NinePartDrawable)
ADDON:ImportObject(OBJECT.ImageDrawable)
WINDOW = {
WIDTH = 680,
HEIGHT = 250,
MIN_WIDTH = 680,
MIN_HEIGHT = 250,
MAX_WIDTH = 1000,
MAX_HEIGHT = 1000,
RESIZE_BORDER_SIZE = { LEFT = 10, TOP = 0, RIGHT = 10, BOTTOM = 10 },
MARGIN = 20,
CLOSE_BUTTON_OFFSET = 3,
UIBOUND_NAME = "ui_bound_exampleaddon",
}
---Sets up the view of the example addon window.
---@return Window
function SetViewOfExampleAddon()
-- Create a window.
local window = UIParent:CreateWidget("window", "exampleaddon", "UIParent")
local background = window:CreateDrawable(TEXTURE_PATH.DEFAULT, "main_bg", "background")
local decoration = window:CreateDrawable(TEXTURE_PATH.DEFAULT, "main_bg_deco", "background")
-- Create a title bar.
local titleBar = window:CreateChildWidget("window", "titleBar", 0, true)
titleBar.titleStyle:SetAlign(ALIGN_CENTER)
titleBar.titleStyle:SetSnap(true)
titleBar.titleStyle:SetFont(FONT_PATH.SUB, FONT_SIZE.XLARGE)
titleBar.titleStyle:SetColorByKey("title")
titleBar:SetTitleText(locale.addon.title)
titleBar:EnableDrag(true)
titleBar:SetHeight(45)
-- Create a close button for the title bar.
local closeButton = titleBar:CreateChildWidget("button", "closeButton", 0, true)
closeButton:SetStyle("btn_close_default")
-- Create a body textbox.
local bodyTextbox = window:CreateChildWidget("textbox", "bodyTextbox", 0, true)
bodyTextbox.style:SetFontSize(FONT_SIZE.LARGE)
bodyTextbox.style:SetAlign(ALIGN_TOP_LEFT)
bodyTextbox.style:SetColorByKey("default")
bodyTextbox.style:SetSnap(true)
bodyTextbox:SetLineSpace(7)
bodyTextbox:SetText(locale.addon.body)
-- Create a example check button.
local checkButton = window:CreateChildWidget("checkbutton", "checkButton", 0, true)
local checkButtonBackground = checkButton:CreateDrawable(TEXTURE_PATH.CHECK_BTN, "btn_df", "background")
local checkButtonCheckedBackground = checkButton:CreateDrawable(TEXTURE_PATH.CHECK_BTN, "btn_chk_df", "background")
checkButton:SetCheckedBackground(checkButtonCheckedBackground)
-- Create a textbox for the check button.
local textbox = checkButton:CreateChildWidget("textbox", "textbox", 0, true)
textbox.style:SetColorByKey("default")
textbox:SetAutoResize(true)
textbox:SetAutoWordwrap(false)
textbox:SetText(locale.addon.enableModal)
-- Create a reset button.
local resetUIButton = window:CreateChildWidget("button", "resetUIButton", 0, true)
resetUIButton:SetStyle("text_default")
resetUIButton:SetNormalColor(.8, .4, .4, 1)
resetUIButton:SetTextColor(1, 1, 1, 1)
resetUIButton:SetHighlightColor(.8, .5, .5, 1)
resetUIButton:SetHighlightTextColor(1, 1, 1, 1)
resetUIButton:SetPushedColor(.8, .3, .3, 1)
resetUIButton:SetPushedTextColor(1, 1, 1, 1)
resetUIButton:SetText(locale.addon.resetUI)
-- Create a save button.
local saveUIButton = window:CreateChildWidget("button", "saveUIButton", 0, true)
saveUIButton:SetStyle("text_default")
saveUIButton:SetText(locale.addon.saveUI)
-- Create a settings button.
local settingsButton = window:CreateChildWidget("button", "settingsButton", 0, true)
settingsButton:SetStyle("button_common_option")
function window:SetDefaultUIBound()
self:RemoveAllAnchors()
self:AddAnchor("CENTER", "UIParent", 0, 0)
self:SetExtent(WINDOW.WIDTH, WINDOW.HEIGHT)
end
-- Set up widget anchors.
local savedUIBound = UIParent:GetUIBound(WINDOW.UIBOUND_NAME)
if not savedUIBound then
window:SetDefaultUIBound()
else
window:AddAnchor("TOPLEFT", "UIParent", savedUIBound.bound.x, savedUIBound.bound.y)
window:SetExtent(savedUIBound.bound.width, savedUIBound.bound.height)
end
background:AddAnchor("TOPLEFT", window, -5, -5)
background:AddAnchor("BOTTOMRIGHT", window, 5, 5)
decoration:AddAnchor("TOPLEFT", window, 0, -5)
decoration:AddAnchor("TOPRIGHT", window, 0, -5)
titleBar:AddAnchor("TOPLEFT", window, 0, 0)
titleBar:AddAnchor("TOPRIGHT", window, 0, 0)
closeButton:AddAnchor("TOPRIGHT", titleBar, WINDOW.CLOSE_BUTTON_OFFSET, -WINDOW.CLOSE_BUTTON_OFFSET)
bodyTextbox:AddAnchor("TOPLEFT", titleBar, "BOTTOMLEFT", WINDOW.MARGIN, 0)
bodyTextbox:AddAnchor("TOPRIGHT", titleBar, "BOTTOMRIGHT", -WINDOW.MARGIN, 0)
checkButton:AddAnchor("BOTTOMLEFT", window, WINDOW.MARGIN, -WINDOW.MARGIN)
checkButton:SetExtent(16, 16)
checkButtonBackground:AddAnchor("CENTER", checkButton, 0, 0)
checkButtonCheckedBackground:AddAnchor("CENTER", checkButton, 0, 0)
textbox:AddAnchor("LEFT", checkButton, "RIGHT", WINDOW.MARGIN / 2, 0)
settingsButton:AddAnchor("BOTTOMRIGHT", window, -WINDOW.MARGIN, -WINDOW.MARGIN)
settingsButton:SetExtent(34, 34)
saveUIButton:AddAnchor("RIGHT", settingsButton, "LEFT", -WINDOW.MARGIN / 2, 0)
resetUIButton:AddAnchor("RIGHT", saveUIButton, "LEFT", -WINDOW.MARGIN / 2, 0)
bodyTextbox:AddAnchor("BOTTOMRIGHT", settingsButton, "TOPRIGHT", 0, -WINDOW.MARGIN)
return window
end