1 /**
2 Grimoire
3 Copyright (c) 2017 Enalye
4 
5 This software is provided 'as-is', without any express or implied warranty.
6 In no event will the authors be held liable for any damages arising
7 from the use of this software.
8 
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute
11 it freely, subject to the following restrictions:
12 
13 	1. The origin of this software must not be misrepresented;
14 	   you must not claim that you wrote the original software.
15 	   If you use this software in a product, an acknowledgment
16 	   in the product documentation would be appreciated but
17 	   is not required.
18 
19 	2. Altered source versions must be plainly marked as such,
20 	   and must not be misrepresented as being the original software.
21 
22 	3. This notice may not be removed or altered from any source distribution.
23 */
24 
25 module ui.listwindow;
26 
27 import core.all;
28 import common.all;
29 
30 import ui.modal;
31 import ui.button;
32 import ui.list.vlist;
33 import ui.inputfield;
34 
35 void setListWindow(string title, string[] list) {
36 	auto modal = new ListWindow(title, list);
37 	setModalWindow(modal);
38 }
39 
40 class ListWindow: ModalWindow {
41 	private {
42 		InStream _stream;
43 		string[] _elements;
44 		VList _list;
45 	}
46 
47 	@property {
48 		string selected() const {
49 			if(!_elements.length)
50 				return "";
51 			return _elements[_list.selected];
52 		}
53 	}
54 
55 	this(string title, string[] newElements) {
56 		super(title, Vec2f(250f, 200f));
57 		_elements = newElements;
58 		_list = new VList(layout.size);
59 		foreach(element; _elements) {
60 			auto btn = new TextButton(element);
61 			_list.addChild(btn);
62 		}
63 		layout.addChild(_list);
64 	}
65 }