1 module app; 2 3 import std.file; 4 import std.path; 5 import std.stdio; 6 import std.algorithm; 7 import std.range; 8 import std.datetime; 9 import dlangui; 10 import std.variant; 11 import std.experimental.logger; 12 13 mixin APP_ENTRY_POINT; 14 15 import std.datetime; 16 import treemapwidget; 17 import filenode; 18 19 auto doFileExample(string[] args, ref TextWidget text) { 20 auto path = args.length == 2 ? args[1] : "."; 21 StopWatch sw; 22 sw.start(); 23 auto fileNode = calcFileNode(DirEntry(path.asAbsolutePath.asNormalizedPath.to!string)); 24 sw.stop(); 25 alias FileTreeMap = TreeMapWidget!FileNode; 26 auto w = new FileTreeMap("filemap", fileNode, 4); 27 w.addTreeMapFocusedListener((FileTreeMap.Maybe maybeNode) { 28 maybeNode.visit!( 29 (FileNode node) { 30 log("focused on ", node); 31 text.text = node.getName().to!dstring ~ " (" ~ node.weight.humanize.to!dstring ~ "Byte)"; 32 }, 33 (typeof(null)) { 34 log("focused on nothing"); 35 text.text = "null"; 36 } 37 )(); 38 }); 39 return w; 40 } 41 42 import dlangui.dml.parser; 43 44 extern (C) int UIAppMain(string[] args) { 45 auto window = Platform.instance.createWindow(to!dstring("treemap"), null); 46 47 auto vl = parseML!VerticalLayout(q{VerticalLayout{layoutWidth: fill; layoutHeight: fill;}}); 48 49 auto text = new TextWidget("label", "no selection".to!dstring); 50 text.fontSize(32); 51 52 auto w = doFileExample(args, text); 53 w.backgroundColor(0x000000).layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT).padding(Rect(10, 10, 10, 10)); 54 55 vl.addChild(w); 56 vl.addChild(text); 57 58 window.mainWidget = vl; 59 window.show(); 60 return Platform.instance.enterMessageLoop(); 61 } 62