mirror of https://github.com/buggins/dlangui.git
DML support improvement
This commit is contained in:
parent
5b954d7481
commit
9b7f4deaf4
|
@ -53,8 +53,8 @@
|
|||
<cccmd>$(CC) -c</cccmd>
|
||||
<ccTransOpt>1</ccTransOpt>
|
||||
<program>$(DMDInstallDir)windows\bin\dmd.exe</program>
|
||||
<imppath>3rdparty ../DerelictGL3/source ../DerelictUtil/source ../DerelictFT/source ../de_image/source/interfaces ../de_image/source/png $(SolutionDir)/../dlib $(SolutionDir)/../gl3n $(SolutionDir)/../DSFML/src</imppath>
|
||||
<fileImppath>$(SolutionDir)/views $(SolutionDir)/views/res $(SolutionDir)/views/res/i18n $(SolutionDir)/views/res/mdpi $(SolutionDir)/views/res/hdpi</fileImppath>
|
||||
<imppath>$(SolutionDir)/../dlangui/3rdparty $(SolutionDir)/../DerelictGL3/source $(SolutionDir)/../DerelictUtil/source $(SolutionDir)/../DerelictFT/source $(SolutionDir)/../de_image/source/interfaces $(SolutionDir)/../de_image/source/png $(SolutionDir)/../dlib</imppath>
|
||||
<fileImppath>$(SolutionDir)/../dlangui/views $(SolutionDir)/../dlangui/views/res $(SolutionDir)/../dlangui/views/res/i18n $(SolutionDir)/../dlangui/views/res/mdpi $(SolutionDir)/../dlangui/views/res/hdpi</fileImppath>
|
||||
<outdir>$(ConfigurationName)</outdir>
|
||||
<objdir>$(OutDir)</objdir>
|
||||
<objname />
|
||||
|
@ -72,7 +72,7 @@
|
|||
<debuglevel>0</debuglevel>
|
||||
<debugids>DebugFocus FontResources</debugids>
|
||||
<versionlevel>0</versionlevel>
|
||||
<versionids>EmbedStandardResources Unicode USE_FREETYPE USE_OPENGL</versionids>
|
||||
<versionids>EmbedStandardResources Unicode USE_FREETYPE</versionids>
|
||||
<dump_source>0</dump_source>
|
||||
<mapverbosity>0</mapverbosity>
|
||||
<createImplib>1</createImplib>
|
||||
|
@ -154,8 +154,8 @@
|
|||
<cccmd>$(CC) -c</cccmd>
|
||||
<ccTransOpt>1</ccTransOpt>
|
||||
<program>$(DMDInstallDir)windows\bin\dmd.exe</program>
|
||||
<imppath>3rdparty ../DerelictGL3/source ../DerelictUtil/source ../DerelictFT/source ../de_image/source/interfaces ../de_image/source/png $(SolutionDir)/../dlib</imppath>
|
||||
<fileImppath>$(SolutionDir)/views $(SolutionDir)/views/res $(SolutionDir)/views/res/i18n $(SolutionDir)/views/res/mdpi</fileImppath>
|
||||
<imppath>$(SolutionDir)/../dlangui/3rdparty $(SolutionDir)/../DerelictGL3/source $(SolutionDir)/../DerelictUtil/source $(SolutionDir)/../DerelictFT/source $(SolutionDir)/../de_image/source/interfaces $(SolutionDir)/../de_image/source/png $(SolutionDir)/../dlib</imppath>
|
||||
<fileImppath>$(SolutionDir)/../dlangui/views $(SolutionDir)/../dlangui/views/res $(SolutionDir)/../dlangui/views/res/i18n $(SolutionDir)/../dlangui/views/res/mdpi $(SolutionDir)/../dlangui/views/res/hdpi</fileImppath>
|
||||
<outdir>$(ConfigurationName)</outdir>
|
||||
<objdir>$(OutDir)</objdir>
|
||||
<objname />
|
||||
|
|
|
@ -342,6 +342,40 @@ class Tokenizer {
|
|||
return _token;
|
||||
}
|
||||
|
||||
protected ref const(Token) parseHex(int prefixLen) {
|
||||
dchar ch = 0;
|
||||
for (int i = 0; i < prefixLen; i++)
|
||||
ch = skipChar();
|
||||
|
||||
uint n = decodeHexDigit(ch);
|
||||
if (n == uint.max)
|
||||
return parseError();
|
||||
|
||||
for(;;) {
|
||||
ch = skipChar();
|
||||
uint digit = decodeHexDigit(ch);
|
||||
if (digit == uint.max)
|
||||
break;
|
||||
n = (n << 4) + digit;
|
||||
}
|
||||
string suffix;
|
||||
if (ch == '%') {
|
||||
suffix ~= ch;
|
||||
ch = skipChar();
|
||||
} else {
|
||||
while (ch >= 'a' && ch <= 'z') {
|
||||
suffix ~= ch;
|
||||
ch = skipChar();
|
||||
}
|
||||
}
|
||||
if (isAlphaNum(ch) || ch == '.')
|
||||
return parseError();
|
||||
_token.type = TokenType.integer;
|
||||
_token.intvalue = n;
|
||||
_token.text = suffix;
|
||||
return _token;
|
||||
}
|
||||
|
||||
protected ref const(Token) parseNumber() {
|
||||
dchar ch = peekChar();
|
||||
uint n = ch - '0';
|
||||
|
@ -429,6 +463,10 @@ class Tokenizer {
|
|||
return parseString();
|
||||
if (isAlpha(ch))
|
||||
return parseIdent();
|
||||
if (ch == '0' && peekNextChar == 'x')
|
||||
return parseHex(2);
|
||||
if (ch == '#')
|
||||
return parseHex(1);
|
||||
if (isNum(ch))
|
||||
return parseNumber();
|
||||
if (ch == '.' && isNum(peekNextChar()))
|
||||
|
@ -821,7 +859,7 @@ class MLParser {
|
|||
|
||||
/// Parse DlangUI ML code
|
||||
public Widget parseML(T = Widget)(string code, string filename = "", Widget context = null) {
|
||||
MLParser parser = new MLParser(code, filename);
|
||||
MLParser parser = new MLParser(code, filename, context);
|
||||
scope(exit) destroy(parser);
|
||||
Widget w = parser.parse();
|
||||
T res = cast(T) w;
|
||||
|
|
|
@ -164,7 +164,7 @@ bool isFullyTransparentColor(uint color) pure nothrow {
|
|||
}
|
||||
|
||||
/// decodes hex digit (0..9, a..f, A..F), returns uint.max if invalid
|
||||
uint decodeHexDigit(char ch) {
|
||||
uint decodeHexDigit(T)(T ch) {
|
||||
if (ch >= '0' && ch <= '9')
|
||||
return ch - '0';
|
||||
else if (ch >= 'a' && ch <= 'f')
|
||||
|
|
|
@ -151,6 +151,17 @@ class ComboBoxBase : HorizontalLayout, OnClickHandler {
|
|||
init();
|
||||
}
|
||||
|
||||
void setAdapter(ListAdapter adapter, bool ownAdapter = true) {
|
||||
if (_adapter) {
|
||||
if (_ownAdapter)
|
||||
destroy(_adapter);
|
||||
removeAllChildren();
|
||||
}
|
||||
_adapter = adapter;
|
||||
_ownAdapter = ownAdapter;
|
||||
init();
|
||||
}
|
||||
|
||||
protected void init() {
|
||||
_body = createSelectedItemWidget();
|
||||
_body.onClickListener = this;
|
||||
|
@ -173,27 +184,46 @@ class ComboBoxBase : HorizontalLayout, OnClickHandler {
|
|||
/** ComboBox with list of strings. */
|
||||
class ComboBox : ComboBoxBase {
|
||||
|
||||
protected StringListAdapter _adapter;
|
||||
|
||||
/// empty parameter list constructor - for usage by factory
|
||||
this() {
|
||||
this(null);
|
||||
}
|
||||
/// create with ID parameter
|
||||
this(string ID) {
|
||||
super(ID, (_adapter = new StringListAdapter()), true);
|
||||
super(ID, new StringListAdapter(), true);
|
||||
}
|
||||
|
||||
this(string ID, string[] items) {
|
||||
super(ID, (_adapter = new StringListAdapter(items)), true);
|
||||
super(ID, new StringListAdapter(items), true);
|
||||
}
|
||||
|
||||
this(string ID, dstring[] items) {
|
||||
super(ID, (_adapter = new StringListAdapter(items)), true);
|
||||
super(ID, new StringListAdapter(items), true);
|
||||
}
|
||||
|
||||
this(string ID, StringListValue[] items) {
|
||||
super(ID, (_adapter = new StringListAdapter(items)), true);
|
||||
super(ID, new StringListAdapter(items), true);
|
||||
}
|
||||
|
||||
@property void items(string[] itemResourceIds) {
|
||||
setAdapter(new StringListAdapter(itemResourceIds));
|
||||
}
|
||||
|
||||
@property void items(dstring[] items) {
|
||||
setAdapter(new StringListAdapter(items));
|
||||
}
|
||||
|
||||
@property void items(StringListValue[] items) {
|
||||
setAdapter(new StringListAdapter(items));
|
||||
}
|
||||
|
||||
/// returns list of items
|
||||
@property ref const(UIStringCollection) items() {
|
||||
return (cast(StringListAdapter)_adapter).items;
|
||||
}
|
||||
|
||||
@property StringListAdapter adapter() {
|
||||
return cast(StringListAdapter)_adapter;
|
||||
}
|
||||
|
||||
@property override dstring text() {
|
||||
|
@ -201,7 +231,7 @@ class ComboBox : ComboBoxBase {
|
|||
}
|
||||
|
||||
@property override Widget text(dstring txt) {
|
||||
int idx = _adapter.items.indexOf(txt);
|
||||
int idx = adapter.items.indexOf(txt);
|
||||
if (idx >= 0) {
|
||||
selectedItemIndex = idx;
|
||||
} else {
|
||||
|
@ -213,7 +243,7 @@ class ComboBox : ComboBoxBase {
|
|||
}
|
||||
|
||||
@property override Widget text(UIString txt) {
|
||||
int idx = _adapter.items.indexOf(txt);
|
||||
int idx = adapter.items.indexOf(txt);
|
||||
if (idx >= 0) {
|
||||
selectedItemIndex = idx;
|
||||
} else {
|
||||
|
@ -225,7 +255,7 @@ class ComboBox : ComboBoxBase {
|
|||
}
|
||||
|
||||
override @property ComboBoxBase selectedItemIndex(int index) {
|
||||
_body.text = _adapter.items[index];
|
||||
_body.text = adapter.items[index];
|
||||
return super.selectedItemIndex(index);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue