Merge pull request #191 from theyamo/tabs-fixes

Tabs fixes
This commit is contained in:
Vadim Lopatin 2016-03-11 09:11:58 +03:00
commit d8f10f01bf
2 changed files with 18 additions and 1 deletions

View File

@ -144,7 +144,7 @@ class Log {
if (logLevel >= level && logFile !is null && logFile.isOpen) { if (logLevel >= level && logFile !is null && logFile.isOpen) {
SysTime ts = Clock.currTime(); SysTime ts = Clock.currTime();
logFile.writef("%04d-%02d-%02d %02d:%02d:%02d.%03d %s ", ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second, ts.fracSecs.split!("msecs").msecs, logLevelName(level)); logFile.writef("%04d-%02d-%02d %02d:%02d:%02d.%03d %s ", ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second, ts.fracSecs.split!("msecs").msecs, logLevelName(level));
logFile.writeln(args); logFile.writefln(args);
logFile.flush(); logFile.flush();
} }
} }

View File

@ -557,6 +557,10 @@ class TabControl : WidgetGroupDefaultDrawing {
} }
void selectTab(int index, bool updateAccess) { void selectTab(int index, bool updateAccess) {
if (index < 0 || index + 1 >= _children.count) {
Log.e("Tried to access tab out of bounds (index = %d, count = %d)",index,_children.count-1);
return;
}
if (_children.get(index + 1).compareId(_selectedTabId)) if (_children.get(index + 1).compareId(_selectedTabId))
return; // already selected return; // already selected
string previousSelectedTab = _selectedTabId; string previousSelectedTab = _selectedTabId;
@ -642,6 +646,7 @@ class TabHost : FrameLayout, TabHandler {
assert(widget.id !is null, "ID for tab host page is mandatory"); assert(widget.id !is null, "ID for tab host page is mandatory");
assert(_children.indexOf(id) == -1, "duplicate ID for tab host page"); assert(_children.indexOf(id) == -1, "duplicate ID for tab host page");
_tabControl.addTab(widget.id, label, iconId, enableCloseButton); _tabControl.addTab(widget.id, label, iconId, enableCloseButton);
tabInitialization(widget);
//widget.focusGroup = true; // doesn't allow move focus outside of tab content //widget.focusGroup = true; // doesn't allow move focus outside of tab content
addChild(widget); addChild(widget);
return this; return this;
@ -652,9 +657,21 @@ class TabHost : FrameLayout, TabHandler {
assert(widget.id !is null, "ID for tab host page is mandatory"); assert(widget.id !is null, "ID for tab host page is mandatory");
assert(_children.indexOf(id) == -1, "duplicate ID for tab host page"); assert(_children.indexOf(id) == -1, "duplicate ID for tab host page");
_tabControl.addTab(widget.id, labelResourceId, iconId, enableCloseButton); _tabControl.addTab(widget.id, labelResourceId, iconId, enableCloseButton);
tabInitialization(widget);
addChild(widget); addChild(widget);
return this; return this;
} }
// handles initial tab selection & hides subsequently added tabs so
// they don't appear in the same frame
private void tabInitialization(Widget widget) {
if(_tabControl.selectedTabId is null) {
selectTab(_tabControl.tab(0).id,false);
} else {
widget.visibility = Visibility.Invisible;
}
}
/// select tab /// select tab
void selectTab(string ID, bool updateAccess) { void selectTab(string ID, bool updateAccess) {
int index = _tabControl.tabIndex(ID); int index = _tabControl.tabIndex(ID);