fork/m-overlay

git clone https://git.julia.blue/fork/m-overlay

BkacjiosStylize the Tabs on a TabPanel.be5d99b

settings-overhaul
2.0 KiB89 linesraw
1local PANEL = class.create("Tab", "Button")
2
3PANEL:ACCESSOR("Active", "m_bActive", false)
4PANEL:ACCESSOR("Panel", "m_pPanel")
5PANEL:ACCESSOR("ActiveColor", "m_cActiveColor")
6
7function PANEL:Tab()
8	self:super()
9	self:SetDrawButton(false)
10	self:TextMargin(28, 0, 0, 0)
11	self:SetTextAlignment("left")
12end
13
14function PANEL:OnClick()
15	if self.m_pPanel then
16		self.m_pPanel:GetParent():SetActivePanel(self.m_pPanel)
17	end
18end
19
20function PANEL:SetImage(file)
21	if not file then return end
22	self.m_pImage = graphics.newImage(file)
23end
24
25function PANEL:Paint(w, h)
26	gui.skinHook("Paint", "Tab", self, w, h)
27
28	self:super("Paint", w, h)
29
30	if not self.m_pImage then return end
31	graphics.setColor(color_white)
32	graphics.easyDraw(self.m_pImage, 4, 4, 0, 16, 16)
33end
34
35function PANEL:PaintOverlay(w, h)
36	gui.skinHook("PaintOverlay", "Button", self, w, h)
37end
38
39local PANEL = class.create("TabbedPanel", "Panel")
40
41function PANEL:TabbedPanel()
42	self:super()
43	self:SetDrawPanel(false)
44	self:DockPadding(0,0,0,0)
45
46	self.m_pTabBar = self:Add("Panel")
47	self.m_pTabBar:Dock(DOCK_TOP)
48	self.m_pTabBar:DockPadding(0, 0, 0, 0)
49	self.m_pTabBar:DockMargin(0, 0, 0, 0)
50	self.m_pTabBar:SetBorderColor(color_clear)
51	self.m_pTabBar:SetBackgroundColor(color_clear)
52
53	self.m_pActivePanel = nil
54end
55
56function PANEL:SetActivePanel(panel)
57	if self.m_pActivePanel then
58		self.m_pActivePanel:SetVisible(false)
59		self.m_pActivePanel:GetTab():SetActive(false)
60	end
61	panel:SetVisible(true)
62	panel:GetTab():SetActive(true)
63	self.m_pActivePanel = panel
64end
65
66function PANEL:AddTab(name, icon, active)
67	local panel = self:Add("Panel")
68	panel:Dock(DOCK_FILL)
69	panel:DockMargin(0, 0, 0, 0)
70	panel:SetVisible(false)
71
72	local tab = self.m_pTabBar:Add("Tab")
73	tab:SetBorderColor(color_clear)
74	tab:SetBackgroundColor(color_clear)
75	tab:DockMargin(0, 0, 0, 0)
76	tab:Dock(DOCK_LEFT)
77	tab:SetText(name)
78	tab:SetPanel(panel)
79	tab:SetImage(icon)
80	tab:SetWidth(82)
81
82	ACCESSOR(panel, "Tab", "m_pTab", tab)
83
84	if active then
85		self:SetActivePanel(panel)
86	end
87
88	return panel
89end