rearrange example widgets using tabs

This commit is contained in:
Vadim Lopatin 2014-04-01 19:16:06 +04:00
parent bf97ece83f
commit 0b7f59bd95
5 changed files with 33 additions and 18 deletions

View File

@ -2,6 +2,7 @@ module winmain;
import dlangui.all;
import std.stdio;
import std.conv;
version (linux) {
pragma(lib, "png");
@ -97,22 +98,19 @@ extern (C) int UIAppMain(string[] args) {
layout.childById("BTN2").onClickListener(delegate (Widget w) { Log.d("onClick ", w.id); return true; });
layout.childById("BTN3").onClickListener(delegate (Widget w) { Log.d("onClick ", w.id); return true; });
ListWidget list = new ListWidget("mylist", Orientation.Horizontal);
WidgetListAdapter listAdapter = new WidgetListAdapter();
listAdapter.widgets.add((new TextWidget()).text("List item 1"));
listAdapter.widgets.add((new TextWidget()).text("List item 2"));
listAdapter.widgets.add((new TextWidget()).text("List item 3"));
listAdapter.widgets.add((new TextWidget()).text("List item 4"));
listAdapter.widgets.add((new TextWidget()).text("List item 5"));
listAdapter.widgets.add((new TextWidget()).text("List item 6"));
list.ownAdapter = listAdapter;
list.layoutWidth(FILL_PARENT);
layout.addChild(list);
layout.layoutHeight(FILL_PARENT).layoutWidth(FILL_PARENT);
tabs.addTab(layout, "Tab 1"d);
tabs.addTab((new TextWidget()).id("tab2").textColor(0x00802000).text("Tab 2 contents bla bla bla"), "Tab 2"d);
ListWidget list = new ListWidget("tab2", Orientation.Vertical);
WidgetListAdapter listAdapter = new WidgetListAdapter();
for (int i = 0; i < 1000; i++)
listAdapter.widgets.add((new TextWidget()).text("List item "d ~ to!dstring(i)));
list.ownAdapter = listAdapter;
list.layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT);
tabs.addTab(list, "Lists"d);
tabs.addTab((new TextWidget()).id("tab3").textColor(0x00802000).text("Tab 3 contents"), "Tab 3"d);
tabs.addTab((new TextWidget()).id("tab4").textColor(0x00802000).text("Tab 4 contents some long string"), "Tab 4"d);
tabs.addTab((new TextWidget()).id("tab5").textColor(0x00802000).text("Tab 5 contents"), "Tab 5"d);

View File

@ -19,6 +19,10 @@ void setLogLevel(LogLevel level) {
logLevel = level;
}
long currentTimeMillis() {
return std.datetime.Clock.currStdTime / 10000;
}
void setStdoutLogger() {
logFile = stdout;
}

View File

@ -73,10 +73,18 @@ class Window {
checkUpdateNeeded(needDraw, needLayout, animationActive);
}
if (needLayout) {
long measureStart = currentTimeMillis;
_mainWidget.measure(_dx, _dy);
long measureEnd = currentTimeMillis;
Log.d("measure took ", measureEnd - measureStart, " ms");
_mainWidget.layout(Rect(0, 0, _dx, _dy));
long layoutEnd = currentTimeMillis;
Log.d("layout took ", layoutEnd - measureEnd, " ms");
}
long drawStart = currentTimeMillis;
_mainWidget.onDraw(buf);
long drawEnd = currentTimeMillis;
Log.d("draw took ", drawEnd - drawStart, " ms");
lastDrawTs = ts;
if (animationActive)
scheduleAnimation();

View File

@ -306,6 +306,7 @@ class Win32Window : Window {
void onPaint() {
Log.d("onPaint()");
long paintStart = currentTimeMillis;
version (USE_OPENGL) {
if (useOpengl && _hGLRC) {
paintUsingOpenGL();
@ -315,6 +316,8 @@ class Win32Window : Window {
} else {
paintUsingGDI();
}
long paintEnd = currentTimeMillis;
Log.d("WM_PAINT handling took ", paintEnd - paintStart, " ms");
}
protected ButtonDetails _lbutton;

View File

@ -383,17 +383,19 @@ class ListWidget : WidgetGroup, OnScrollHandler {
// todo: scrollOffset
// draw items
for (int i = 0; i < itemCount; i++) {
Widget w = itemWidget(i);
if (w is null || w.visibility != Visibility.Visible)
continue;
Rect itemrc = _itemRects[i];
itemrc.left += rc.left - scrollOffset.x;
itemrc.right += rc.left - scrollOffset.x;
itemrc.top += rc.top - scrollOffset.y;
itemrc.bottom += rc.top - scrollOffset.y;
w.measure(itemrc.width, itemrc.height);
w.layout(itemrc);
w.onDraw(buf);
if (itemrc.intersects(rc)) {
Widget w = itemWidget(i);
if (w is null || w.visibility != Visibility.Visible)
continue;
w.measure(itemrc.width, itemrc.height);
w.layout(itemrc);
w.onDraw(buf);
}
}
}