Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
blob: 977ff4dc603215955fd088ccdfab4a2583499063 (plain)
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
/*
   ui/container.cc
   This file is part of the Osirion project and is distributed under
   the terms of the GNU General Public License version 2
*/


#include "ui/container.h"
#include "ui/paint.h"

namespace ui
{

// TODO Container::direction
Container::Container(Widget *parent) : Window(parent)
{
	set_label("container");
	set_border(false);
	
	set_border(true);
	set_background(true);
	
	container_childsize.assign(256, 48);
	container_margin = 24;
}

Container::~Container()
{
}

void Container::resize()
{
	float w = container_childsize.width() * 1.5f;
	float h = children().size() * (container_childsize.height() + margin()) + container_childsize.height();
	set_size(w, h);

	const float x = container_childsize.width() * 0.25f;
	float y = container_childsize.height() * 0.5f;

	// reposition all children within the container
	for (Children::iterator it = children().begin(); it != children().end(); it++) {
		Widget *w = (*it);
		w->set_size(container_childsize);
		w->set_location(x, y);
		y += container_childsize.height() + container_margin;
	}
}

void Container::set_childsize(const float w, const float h)
{
	container_childsize.assign(w, h);
}

void Container::set_margin(const float margin)
{
	container_margin = margin;
}

void Container::draw_border()
{
	if(focus()) {
		paint::color(palette()->foreground());
	} else {
		paint::color(palette()->border());
	}
	paint::border(global_location(), size());
}

}