PageRenderTime 32ms CodeModel.GetById 22ms app.highlight 7ms RepoModel.GetById 2ms app.codeStats 0ms

/ghost/ui/layout.h

http://ghostcb.googlecode.com/
C++ Header | 99 lines | 43 code | 28 blank | 28 comment | 0 complexity | a4af0aa98deba70bf63ae76533be88a1 MD5 | raw file
 1#ifndef LAYOUT_H
 2#define LAYOUT_H
 3
 4#include "common.h"
 5
 6class CWidget;
 7
 8/*
 9	Layouts make it possible to place widgets in different
10	styles (vertical, horizontal).
11
12	You need to create a layout and add widgets into it.
13
14	Methods setSize and setPosition have limitations so
15	given values should be reasonable.
16*/
17
18// TODO: fix recursiveResize, it doesn't work properly with some setups
19//       for example: 1.fixed size, 2.non-fixed size, 3.fixed size, etc...
20//       however, we don't use such layouts currently so this isn't
21//       an issue at the moment
22
23// Layout
24class CLayout
25{
26public:
27	CLayout(CWidget *parent = 0);
28
29	~CLayout();
30
31	// Add widget to layout
32	void addWidget(CWidget *widget);
33
34	// Remove widget from layout
35	void removeWidget(CWidget *widget);
36
37	// Get widget
38	CWidget *widgetAt(uint index);
39
40	// Show layout
41	void show();
42	
43	// Hide layout
44	void hide();
45
46	// Update layout
47	void update(int c);
48
49	// Get widgets count
50	int count();
51
52	// Set size
53	void setSize(uint width, uint height);
54
55	// Set position
56	void setPosition(uint x, uint y);
57
58	// Get index of widget. Returns -1, if not found.
59	int indexOf(CWidget *w);
60
61	// Find first widget with custom id. Returns -1, if not found.
62	int indexOf(int id);
63
64	// Get widget at i.
65	CWidget *at(uint i);
66
67protected:
68	virtual void recursiveResize(uint from, uint to, uint width, uint height, uint x, uint y);
69
70	CWidget *_parent;
71
72	CSize _size;
73	CPoint _pos;
74
75	vector<CWidget *> _widgets;
76
77};
78
79// Vertical layout
80class CVBoxLayout : public CLayout
81{
82public:
83	CVBoxLayout(CWidget *parent = 0);
84
85protected:
86	void recursiveResize(uint from, uint to, uint width, uint height, uint x, uint y); //fixme?
87};
88
89// Horizontal layout
90class CHBoxLayout : public CLayout
91{
92public:
93	CHBoxLayout(CWidget *parent = 0);
94
95protected:
96	void recursiveResize(uint from, uint to, uint width, uint height, uint x, uint y); //fixme
97};
98
99#endif