1 module awebview.gui.widgets.image; 2 3 __EOF__ 4 5 class Image(alias format = q{<img id="%[id%]"> alt="" src="%[src%]"}) : HTMLElement 6 { 7 private this(string id, bool doCreateObject, string uri) 8 { 9 super(id, false); 10 _uri = uri; 11 } 12 13 14 static Image fromURI(string id, string uri) 15 { 16 return new Image(id, uri); 17 } 18 19 20 static Image fromPath(string id, string path) 21 { 22 import std.uri : encodeComponent; 23 import std.array : replace; 24 import std.path : buildNormalizedPath; 25 26 if(path.isAbsolute){ 27 version(Windows) 28 path = "file:///" ~ encodeComponent(buildNormalizedPath(path).replace('\\', '/'); 29 else 30 path = "file://" ~ encodeComponent(buildNormalizedPath(path)); 31 32 return fromURI(id, path); 33 } 34 else 35 return fromPath(id, absolutePath(path)); 36 } 37 38 39 final 40 @property 41 string src() 42 { 43 if(this.activity) 44 _uri = this["src"].to!string; 45 46 return _uri; 47 } 48 49 50 final 51 @property 52 void src(string uri) 53 { 54 _uri = uri; 55 56 if(this.activity) 57 this["src"] = uri; 58 } 59 60 61 string html() 62 { 63 64 } 65 66 67 private: 68 string _uri; 69 }