1 module widgets.longlists;
2 
3 import dlangui;
4 
5 class LongListsExample : HorizontalLayout
6 {
7     this(string ID)
8     {
9         super(ID);
10         layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT);
11 
12         ListWidget list = new ListWidget("list1", Orientation.Vertical);
13         list.layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT);
14 
15         StringListAdapter stringList = new StringListAdapter();
16         WidgetListAdapter listAdapter = new WidgetListAdapter();
17         listAdapter.add((new TextWidget()).text("This is a list of widgets"d).styleId("LIST_ITEM"));
18         stringList.add("This is a list of strings from StringListAdapter"d);
19         stringList.add("If you type with your keyboard,"d);
20         stringList.add("then you can find the"d);
21         stringList.add("item in the list"d);
22         stringList.add("neat!"d);
23         for (int i = 1; i < 1000; i++) {
24             dstring label = "List item "d ~ to!dstring(i);
25             listAdapter.add((new TextWidget()).text("Widget list - "d ~ label).styleId("LIST_ITEM"));
26             stringList.add("Simple string - "d ~ label);
27         }
28         list.ownAdapter = listAdapter;
29         listAdapter.resetItemState(0, State.Enabled);
30         listAdapter.resetItemState(5, State.Enabled);
31         listAdapter.resetItemState(7, State.Enabled);
32         listAdapter.resetItemState(12, State.Enabled);
33         assert(list.itemEnabled(5) == false);
34         assert(list.itemEnabled(6) == true);
35         list.layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT);
36         list.selectItem(0);
37 
38         addChild(list);
39 
40         ListWidget list2 = new StringListWidget("list2");
41         list2.ownAdapter = stringList;
42         list2.layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT);
43         list2.selectItem(0);
44         addChild(list2);
45 
46         VerticalLayout itemedit = new VerticalLayout();
47         itemedit.addChild(new TextWidget(null, "New item text:"d));
48         EditLine itemtext = new EditLine(null, "Text for new item"d);
49         itemedit.addChild(itemtext);
50         Button btn = new Button(null, "Add item"d);
51         itemedit.addChild(btn);
52         addChild(itemedit);
53         btn.click = delegate(Widget src)
54         {
55             stringList.add(itemtext.text);
56             listAdapter.add((new TextWidget()).text(itemtext.text).styleId("LIST_ITEM"));
57             return true;
58         };
59     }
60 }