diff --git a/src/dlangui/dml/parser.d b/src/dlangui/dml/parser.d index 372dc15b..19a1efa5 100644 --- a/src/dlangui/dml/parser.d +++ b/src/dlangui/dml/parser.d @@ -876,6 +876,12 @@ public Token[] tokenizeML(const(dstring[]) lines) { return tokenizeML(code); } +/// tokenize source into array of tokens (excluding EOF) +public Token[] tokenizeML(const(string[]) lines) { + string code = join(lines, "\n"); + return tokenizeML(code); +} + /// tokenize source into array of tokens (excluding EOF) public Token[] tokenizeML(string code) { Token[] res; diff --git a/src/dlangui/graphics/ftfonts.d b/src/dlangui/graphics/ftfonts.d index b78e1bd9..0434676a 100644 --- a/src/dlangui/graphics/ftfonts.d +++ b/src/dlangui/graphics/ftfonts.d @@ -571,29 +571,31 @@ class FreeTypeFontManager : FontManager { /// register freetype font by filename - optinally font properties can be passed if known (e.g. from libfontconfig). - bool registerFont(string filename, FontFamily family = FontFamily.SansSerif, string face = null, bool italic = false, int weight = 0) { + bool registerFont(string filename, FontFamily family = FontFamily.SansSerif, string face = null, bool italic = false, int weight = 0, bool dontLoadFile = false) { if (_library is null) return false; Log.d("FreeTypeFontManager.registerFont ", filename, " ", family, " ", face, " italic=", italic, " weight=", weight); if (!exists(filename) || !isFile(filename)) return false; - FreeTypeFontFile font = new FreeTypeFontFile(_library, filename); - if (!font.open(24)) { - Log.e("Failed to open font ", filename); - destroy(font); - return false; - } + if (!dontLoadFile) { + FreeTypeFontFile font = new FreeTypeFontFile(_library, filename); + if (!font.open(24)) { + Log.e("Failed to open font ", filename); + destroy(font); + return false; + } - if (face == null || weight == 0) { - // properties are not set by caller - // get properties from loaded font - face = font.face; - italic = font.italic; - weight = font.weight; - debug(FontResources)Log.d("Using properties from font file: face=", face, " weight=", weight, " italic=", italic); + if (face == null || weight == 0) { + // properties are not set by caller + // get properties from loaded font + face = font.face; + italic = font.italic; + weight = font.weight; + debug(FontResources)Log.d("Using properties from font file: face=", face, " weight=", weight, " italic=", italic); + } + destroy(font); } - destroy(font); FontDef def = FontDef(family, face, italic, weight); FontFileItem item = findFileItem(def); @@ -777,7 +779,7 @@ bool registerFontConfigFonts(FreeTypeFontManager fontMan) { else if (style16.indexOf("extralight") >= 0) face ~= " Extra Light"; - if (fontMan.registerFont(fn, fontFamily, face, italic, weight)) + if (fontMan.registerFont(fn, fontFamily, face, italic, weight, true)) facesFound++; /* LVFontDef def( diff --git a/src/dlangui/widgets/metadata.d b/src/dlangui/widgets/metadata.d index 00dfba33..5e748fc5 100644 --- a/src/dlangui/widgets/metadata.d +++ b/src/dlangui/widgets/metadata.d @@ -4,6 +4,20 @@ import dlangui.widgets.widget; interface WidgetMetadataDef { Widget create(); + /// short class name, e.g. "EditLine" + string className(); + /// module name, e.g. "dlangui.widgets.editors" + string moduleName(); + /// full class name, e.g. "dlangui.widgets.editors.EditLine" + string fullName(); +} + +struct WidgetSignalMetadata { + string name; + string typeString; + //TypeTuple + TypeInfo returnType; + TypeInfo paramsType; } private __gshared WidgetMetadataDef[string] _registeredWidgets; @@ -18,13 +32,43 @@ void registerWidgetMetadata(string name, WidgetMetadataDef metadata) { _registeredWidgets[name] = metadata; } +WidgetSignalMetadata[] getSignalList(alias T)() { + WidgetSignalMetadata[] res; + foreach(m; __traits(allMembers, T)) { + static if (__traits(compiles, (typeof(__traits(getMember, T, m))))){ + // skip non-public members + static if (__traits(getProtection, __traits(getMember, T, m)) == "public") { + static if (__traits(compiles, __traits(getMember, T, m).params_t ) && __traits(compiles, __traits(getMember, T, m).return_t)) { + alias typeof(__traits(getMember, T, m)) ti; + res ~= WidgetSignalMetadata(m, + __traits(getMember, T, m).return_t.stringof ~ __traits(getMember, T, m).params_t.stringof, + typeid(__traits(getMember, T, m).return_t), + typeid(__traits(getMember, T, m).params_t)); + } + } + } + } + return res; +} + string generateMetadataClass(alias t)() { + //pragma(msg, moduleName!t); import std.traits; + pragma(msg, getSignalList!t); immutable string metadataClassName = t.stringof ~ "Metadata"; return "class " ~ metadataClassName ~ " : WidgetMetadataDef { \n" ~ " override Widget create() {\n" ~ " return new " ~ moduleName!t ~ "." ~ t.stringof ~ "();\n" ~ " }\n" ~ + " override string className() {\n" ~ + " return \"" ~ t.stringof ~ "\";\n" ~ + " }\n" ~ + " override string moduleName() {\n" ~ + " return \"" ~ moduleName!t ~ "\";\n" ~ + " }\n" ~ + " override string fullName() {\n" ~ + " return \"" ~ moduleName!t ~ "." ~ t.stringof ~ "\";\n" ~ + " }\n" ~ "}\n"; }