From 0f0ac6a527d7ed2998ac1312188e3c803398bbad Mon Sep 17 00:00:00 2001 From: Timo Taipalus Date: Wed, 9 Mar 2016 14:16:22 +0200 Subject: [PATCH 1/3] selectTab - checks for illegal index value Don't send illegal index value to object list and cause exception, just output error to console instead --- src/dlangui/widgets/tabs.d | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/dlangui/widgets/tabs.d b/src/dlangui/widgets/tabs.d index d1c0f109..e5599fb0 100644 --- a/src/dlangui/widgets/tabs.d +++ b/src/dlangui/widgets/tabs.d @@ -557,6 +557,10 @@ class TabControl : WidgetGroupDefaultDrawing { } 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)) return; // already selected string previousSelectedTab = _selectedTabId; From e89b684274cf9ad158b9bf1f051479af57fb6a56 Mon Sep 17 00:00:00 2001 From: Timo Taipalus Date: Wed, 9 Mar 2016 14:31:15 +0200 Subject: [PATCH 2/3] logger: using writefln to allow formatted strings --- src/dlangui/core/logger.d | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dlangui/core/logger.d b/src/dlangui/core/logger.d index 7fc22700..877e1ed3 100644 --- a/src/dlangui/core/logger.d +++ b/src/dlangui/core/logger.d @@ -144,7 +144,7 @@ class Log { if (logLevel >= level && logFile !is null && logFile.isOpen) { 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.writeln(args); + logFile.writefln(args); logFile.flush(); } } From 1be3c329d789d32394939acbecc9aa2e41063647 Mon Sep 17 00:00:00 2001 From: Timo Taipalus Date: Wed, 9 Mar 2016 14:43:46 +0200 Subject: [PATCH 3/3] fixes to tab initialization automatically select the first added tab as the default and hide the widgets from subsequently added tabs. --- src/dlangui/widgets/tabs.d | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/dlangui/widgets/tabs.d b/src/dlangui/widgets/tabs.d index e5599fb0..9173edb5 100644 --- a/src/dlangui/widgets/tabs.d +++ b/src/dlangui/widgets/tabs.d @@ -646,6 +646,7 @@ class TabHost : FrameLayout, TabHandler { assert(widget.id !is null, "ID for tab host page is mandatory"); assert(_children.indexOf(id) == -1, "duplicate ID for tab host page"); _tabControl.addTab(widget.id, label, iconId, enableCloseButton); + tabInitialization(widget); //widget.focusGroup = true; // doesn't allow move focus outside of tab content addChild(widget); return this; @@ -656,9 +657,21 @@ class TabHost : FrameLayout, TabHandler { assert(widget.id !is null, "ID for tab host page is mandatory"); assert(_children.indexOf(id) == -1, "duplicate ID for tab host page"); _tabControl.addTab(widget.id, labelResourceId, iconId, enableCloseButton); + tabInitialization(widget); addChild(widget); 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 void selectTab(string ID, bool updateAccess) { int index = _tabControl.tabIndex(ID);