mirror of https://github.com/buggins/dlangui.git
get rid of unnecessary resource dirs, language and theme setting when default values are used
This commit is contained in:
parent
5b1c0de0ae
commit
0ddf2fa508
19
README.md
19
README.md
|
@ -106,7 +106,7 @@ Styles and themes are a bit similar to ones in Android API.
|
|||
which allows to modify some of attributes, while getting base style attributes if they are not changed in widget. This trick can minimize memory usage for widget attributes when
|
||||
standard values are used.
|
||||
* Current default theme is similar to one in MS Visual Studio 2013
|
||||
|
||||
* Resources can be either embedded into executable or loaded from external resource directory in runtime
|
||||
|
||||
Win32 builds
|
||||
------------
|
||||
|
@ -219,19 +219,6 @@ Hello World
|
|||
|
||||
/// entry point for dlangui based application
|
||||
extern (C) int UIAppMain(string[] args) {
|
||||
// resource directory search paths
|
||||
string[] resourceDirs = [
|
||||
appendPath(exePath, "../res/"), // for Visual D and DUB builds
|
||||
appendPath(exePath, "../../res/") // for Mono-D builds
|
||||
];
|
||||
|
||||
// setup resource directories - will use only existing directories
|
||||
Platform.instance.resourceDirs = resourceDirs;
|
||||
// select translation file - for english language
|
||||
Platform.instance.uiLanguage = "en";
|
||||
// load theme from file "theme_default.xml"
|
||||
Platform.instance.uiTheme = "theme_default";
|
||||
|
||||
// create window
|
||||
Window window = Platform.instance.createWindow("My Window", null);
|
||||
// create some widget to show in window
|
||||
|
@ -253,10 +240,6 @@ Sample dub.json:
|
|||
"targetPath": "bin",
|
||||
"targetType": "executable",
|
||||
|
||||
"copyFiles": [
|
||||
"res"
|
||||
],
|
||||
|
||||
"dependencies": {
|
||||
"dlangui:dlanguilib": "~master"
|
||||
}
|
||||
|
|
|
@ -9,27 +9,6 @@ mixin APP_ENTRY_POINT;
|
|||
|
||||
/// entry point for dlangui based application
|
||||
extern (C) int UIAppMain(string[] args) {
|
||||
// resource directory search paths
|
||||
string[] resourceDirs = [
|
||||
appendPath(exePath, "../../../res/"), // for Visual D and DUB builds
|
||||
appendPath(exePath, "../../../res/mdpi/"), // for Visual D and DUB builds
|
||||
appendPath(exePath, "../../../../res/"),// for Mono-D builds
|
||||
appendPath(exePath, "../../../../res/mdpi/"),// for Mono-D builds
|
||||
appendPath(exePath, "res/"), // when res dir is located at the same directory as executable
|
||||
appendPath(exePath, "../res/"), // when res dir is located at project directory
|
||||
appendPath(exePath, "../../res/"), // when res dir is located at the same directory as executable
|
||||
appendPath(exePath, "res/mdpi/"), // when res dir is located at the same directory as executable
|
||||
appendPath(exePath, "../res/mdpi/"), // when res dir is located at project directory
|
||||
appendPath(exePath, "../../res/mdpi/") // when res dir is located at the same directory as executable
|
||||
];
|
||||
|
||||
// setup resource directories - will use only existing directories
|
||||
Platform.instance.resourceDirs = resourceDirs;
|
||||
// select translation file - for english language
|
||||
Platform.instance.uiLanguage = "en";
|
||||
// load theme from file "theme_default.xml"
|
||||
Platform.instance.uiTheme = "theme_default";
|
||||
|
||||
// create window
|
||||
Window window = Platform.instance.createWindow("My Window", null);
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
"targetType": "executable",
|
||||
"targetName": "tetris",
|
||||
|
||||
"copyFiles": ["res"],
|
||||
"stringImportPaths": ["views", "views/res", "views/res/i18n", "views/res/mdpi"],
|
||||
|
||||
"dependencies": {
|
||||
"dlangui:dlanguilib": "*"
|
||||
|
|
|
@ -11,11 +11,75 @@ Supports nine-patch PNG images in .9.png files (like in Android).
|
|||
|
||||
Supports state drawables using XML files similar to ones in Android.
|
||||
|
||||
|
||||
|
||||
When your application uses custom resources, you can embed resources into executable and/or specify external resource directory(s).
|
||||
|
||||
To embed resources, put them into views/res directory, and create file views/resources.list with list of all files to embed.
|
||||
|
||||
Use following code to embed resources:
|
||||
|
||||
----
|
||||
/// entry point for dlangui based application
|
||||
extern (C) int UIAppMain(string[] args) {
|
||||
|
||||
// embed non-standard resources listed in views/resources.list into executable
|
||||
embeddedResourceList.addResources(embedResourcesFromList!("resources.list")());
|
||||
|
||||
...
|
||||
----
|
||||
|
||||
Resource list resources.list file may look similar to following:
|
||||
|
||||
----
|
||||
res/i18n/en.ini
|
||||
res/i18n/ru.ini
|
||||
res/mdpi/cr3_logo.png
|
||||
res/mdpi/document-open.png
|
||||
res/mdpi/document-properties.png
|
||||
res/mdpi/document-save.png
|
||||
res/mdpi/edit-copy.png
|
||||
res/mdpi/edit-paste.png
|
||||
res/mdpi/edit-undo.png
|
||||
res/mdpi/tx_fabric.jpg
|
||||
res/theme_custom1.xml
|
||||
----
|
||||
|
||||
As well you can specify list of external directories to get resources from.
|
||||
|
||||
----
|
||||
|
||||
/// entry point for dlangui based application
|
||||
extern (C) int UIAppMain(string[] args) {
|
||||
// resource directory search paths
|
||||
string[] resourceDirs = [
|
||||
appendPath(exePath, "../../../res/"), // for Visual D and DUB builds
|
||||
appendPath(exePath, "../../../res/mdpi/"), // for Visual D and DUB builds
|
||||
appendPath(exePath, "../../../../res/"),// for Mono-D builds
|
||||
appendPath(exePath, "../../../../res/mdpi/"),// for Mono-D builds
|
||||
appendPath(exePath, "res/"), // when res dir is located at the same directory as executable
|
||||
appendPath(exePath, "../res/"), // when res dir is located at project directory
|
||||
appendPath(exePath, "../../res/"), // when res dir is located at the same directory as executable
|
||||
appendPath(exePath, "res/mdpi/"), // when res dir is located at the same directory as executable
|
||||
appendPath(exePath, "../res/mdpi/"), // when res dir is located at project directory
|
||||
appendPath(exePath, "../../res/mdpi/") // when res dir is located at the same directory as executable
|
||||
];
|
||||
// setup resource directories - will use only existing directories
|
||||
Platform.instance.resourceDirs = resourceDirs;
|
||||
|
||||
----
|
||||
|
||||
When same file exists in both embedded and external resources, one from external resource directory will be used - it's useful for developing
|
||||
and testing of resources.
|
||||
|
||||
|
||||
Synopsis:
|
||||
|
||||
----
|
||||
import dlangui.graphics.resources;
|
||||
|
||||
// embed non-standard resources listed in views/resources.list into executable
|
||||
embeddedResourceList.addResources(embedResourcesFromList!("resources.list")());
|
||||
----
|
||||
|
||||
Copyright: Vadim Lopatin, 2014
|
||||
|
@ -56,7 +120,8 @@ struct EmbeddedResourceList {
|
|||
}
|
||||
/// find by exact file name
|
||||
EmbeddedResource * find(string name) {
|
||||
for(int i = 0; i < list.length; i++)
|
||||
// search backwards to allow overriding standard resources (which are added first)
|
||||
for (int i = cast(int)list.length - 1; i >= 0; i--)
|
||||
if (name.equal(list[i].name))
|
||||
return &list[i];
|
||||
return null;
|
||||
|
@ -68,7 +133,8 @@ struct EmbeddedResourceList {
|
|||
string png9name = name ~ ".9.png";
|
||||
string jpgname = name ~ ".jpg";
|
||||
string jpegname = name ~ ".jpeg";
|
||||
for(int i = 0; i < list.length; i++) {
|
||||
// search backwards to allow overriding standard resources (which are added first)
|
||||
for (int i = cast(int)list.length - 1; i >= 0; i--) {
|
||||
string s = list[i].name;
|
||||
if (s.equal(xmlname) || s.equal(pngname) || s.equal(png9name)
|
||||
|| s.equal(jpgname) || s.equal(jpegname))
|
||||
|
|
|
@ -806,6 +806,14 @@ class Platform {
|
|||
return this;
|
||||
}
|
||||
|
||||
/// to set uiLanguage and themeId to default (en, theme_default) if not set yet
|
||||
protected void setDefaultLanguageAndThemeIfNecessary() {
|
||||
if (!_uiLanguage)
|
||||
uiLanguage = "en";
|
||||
if (!_themeId)
|
||||
themeId = "theme_default";
|
||||
}
|
||||
|
||||
protected string[] _resourceDirs;
|
||||
/// returns list of resource directories
|
||||
@property string[] resourceDirs() { return _resourceDirs; }
|
||||
|
|
|
@ -791,6 +791,7 @@ class SDLPlatform : Platform {
|
|||
}
|
||||
|
||||
override Window createWindow(dstring windowCaption, Window parent, uint flags = WindowFlag.Resizable) {
|
||||
setDefaultLanguageAndThemeIfNecessary();
|
||||
SDLWindow res = new SDLWindow(this, windowCaption, parent, flags);
|
||||
_windowMap[res.windowId] = res;
|
||||
return res;
|
||||
|
|
|
@ -716,6 +716,7 @@ class Win32Platform : Platform {
|
|||
return null;
|
||||
}
|
||||
override Window createWindow(dstring windowCaption, Window parent, uint flags = WindowFlag.Resizable) {
|
||||
setDefaultLanguageAndThemeIfNecessary();
|
||||
return new Win32Window(this, windowCaption, parent, flags);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue