1 module evael.graphics.gui.controls.TabControl;
2 
3 import evael.graphics.gui.controls.Container;
4 import evael.graphics.gui.controls.Button;
5 
6 import evael.utils.Math;
7 
8 import evael.utils.Size;
9 import evael.utils.Color;
10 
11 class TabControl : Container
12 {
13 	private TabPage[] m_tabs;
14 
15 	private TabPage m_currentTab;
16 
17 	private float m_currentTabPosition;
18 
19 	public this(in float x, in float y, in int width = 0, in int height = 0)
20 	{
21 		this(vec2(x, y), Size!int(width, height));
22 	}
23 
24 	public this(in vec2 position, in Size!int size)
25 	{
26 		super(position, size);
27 
28 		this.m_currentTabPosition = 0.0f;
29 	}
30 
31 	public override void draw(in float deltaTime)
32 	{
33 		//super.drawWithoutChildren(deltaTime);
34 
35 		foreach(control; this.m_controls)
36 		{
37 			control.draw(deltaTime);
38 		}
39 	}
40 
41 	public void addTab(TabPage tab)
42 	{
43 		if(this.m_currentTab is null)
44 		{
45 			this.m_currentTab = tab;
46 		}
47 		else tab.hide();
48 
49 		// We update tabpage size
50 		tab.size = Size!int(this.m_size.width, this.m_size.height - 30);
51 
52 		auto button = new Button(tab.displayName, this.m_currentTabPosition, this.m_size.height - 30);
53 		// button.borderColor = Color.DarkGrey;
54 
55 		button.onClickEvent = (sender) 
56 		{ 
57 			// We hide last page
58 			if(this.m_currentTab != tab)
59 			{
60 				this.m_currentTab.hide(); 
61 				tab.show();
62 				this.m_currentTab = tab;
63 
64 				// button.borderColor = Color.Black;
65 			}
66 		};
67 
68 		this.addChild(tab);
69 		this.addChild(button);
70 
71 //		this.m_currentTabPosition += this.m_font.getTextWidth(tab.name) + 20;
72 
73 		this.m_tabs ~= tab;
74 	}
75 }
76 
77 class TabPage : Container
78 {
79 	private wstring m_displayName;
80 
81 	public this(in wstring name)
82 	{
83 		super(vec2(0, 0), Size!int(0, 0));
84 
85 		this.m_displayName = name;
86 	}
87 
88 	public override void draw(in float deltaTime)
89 	{
90 		super.draw(deltaTime);
91 	}
92 
93 	@property
94 	public wstring displayName() const nothrow
95 	{
96 		return this.m_displayName;
97 	}
98 }