PageRenderTime 54ms CodeModel.GetById 46ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/gui/radiogroup.d

http://github.com/wilkie/djehuty
D | 77 lines | 61 code | 13 blank | 3 comment | 11 complexity | 18b3e26918c947267f75626d892589e3 MD5 | raw file
 1module gui.radiogroup;
 2
 3import gui.widget;
 4import gui.togglefield;
 5
 6import core.string;
 7import core.event;
 8
 9// Description: This control provides a method of grouping together toggle fields to form a collection of mutually exclusive 'radio' fields.
10class RadioGroup : Widget
11{
12public:
13	this() {
14		super(0,0,0,0);
15	}
16
17	override void onAdd()
18	{
19		for (uint i = 0; i<_count; i++)
20		{
21			_window.push(_toggleFields[i]);
22		}
23	}
24
25	override bool onSignal(Dispatcher dsp, uint signal) {
26		if (signal == ToggleField.Signal.Selected) {
27			for (uint i = 0; i<_count; i++) {
28				if (_toggleFields[i] !is dsp) {
29					_toggleFields[i].unselect();
30				}
31			}
32		}
33		return false;
34	}
35
36	// Description: This function will add a toggle field control to the group.
37	override void push(Dispatcher dsp) {
38		if (cast(ToggleField)dsp !is null) {
39		}
40		else {
41			// error
42		}
43	}
44
45private:
46	ToggleField _toggleFields[] = null;
47
48	uint _capacity = 10;
49	uint _count = 0;
50
51	void addControl(ToggleField inctrl)
52	{
53		if (_toggleFields is null)
54		{
55			_toggleFields = new ToggleField[_capacity];
56			_count = 0;
57		}
58
59		if (_capacity == _count)
60		{
61			ToggleField[] _tmp = _toggleFields;
62			_capacity *= 2;
63			_toggleFields = new ToggleField[_capacity];
64			_toggleFields[0.._count] = _tmp[0.._count];
65		}
66
67		_toggleFields[_count] = inctrl;
68		_count++;
69
70		inctrl._is_grouped = true;
71
72		if (_window !is null)
73		{
74			_window.push(inctrl);
75		}
76	}
77}