diff --git a/dlanguilib.visualdproj b/dlanguilib.visualdproj
index 657bf967..9a0e3bae 100644
--- a/dlanguilib.visualdproj
+++ b/dlanguilib.visualdproj
@@ -275,6 +275,7 @@
+
diff --git a/examples/example1/winmain.d b/examples/example1/winmain.d
index e356e5f9..a5cdd6f1 100644
--- a/examples/example1/winmain.d
+++ b/examples/example1/winmain.d
@@ -1,20 +1,12 @@
module winmain;
-import dlangui.platforms.common.platform;
-import dlangui.graphics.images;
-import dlangui.widgets.widget;
-import dlangui.widgets.controls;
-import dlangui.core.logger;
-import dlangui.graphics.fonts;
+import dlangui.all;
import std.stdio;
-ImageCache imageCache;
-string resourceDir;
-
+/// workaround for link issue when WinMain is located in library
version(Windows) {
import win32.windows;
import dlangui.platforms.windows.winapp;
- /// workaround for link issue when WinMain is located in library
extern (Windows)
int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
@@ -24,38 +16,23 @@ version(Windows) {
}
}
-
+/// entry point for dlangui based application
extern (C) int UIAppMain(string[] args) {
-
- imageCache = new ImageCache();
- resourceDir = exePath() ~ "..\\res\\";
-
+ // setup resource dir
+ string resourceDir = exePath() ~ "..\\res\\";
string[] imageDirs = [
resourceDir
];
drawableCache.resourcePaths = imageDirs;
+
+ // create window
Window window = Platform.instance().createWindow("My Window", null);
Widget myWidget = (new Button()).textColor(0x40FF4000);
myWidget.text = "Some strange text string. 1234567890";
- myWidget.alignment = Align.Center;
window.mainWidget = myWidget;
window.show();
window.windowCaption = "New Window Caption";
-
-
- Log.d("Before getFont");
- FontRef font = FontManager.instance.getFont(32, 400, false, FontFamily.SansSerif, "Arial");
- Log.d("After getFont");
- assert(!font.isNull);
- int[] widths;
- dchar[] text = cast(dchar[])"Test string"d;
- Log.d("Calling measureText");
- int charsMeasured = font.measureText(text, widths, 1000);
- assert(charsMeasured > 0);
- int w = widths[charsMeasured - 1];
- Log.d("Measured string: ", charsMeasured, " chars, width=", w);
- Glyph * g = font.getCharGlyph('A');
- Log.d("Char A glyph: ", g.blackBoxX, "x", g.blackBoxY);
+ // run message loop
return Platform.instance().enterMessageLoop();
}
diff --git a/src/dlangui/platforms/common/platform.d b/src/dlangui/platforms/common/platform.d
index b20a9f82..9b8865d7 100644
--- a/src/dlangui/platforms/common/platform.d
+++ b/src/dlangui/platforms/common/platform.d
@@ -32,8 +32,9 @@ public class Window {
}
}
public void onDraw(DrawBuf buf) {
- if (_mainWidget !is null)
+ if (_mainWidget !is null) {
_mainWidget.onDraw(buf);
+ }
}
}
diff --git a/src/dlangui/platforms/windows/win32drawbuf.d b/src/dlangui/platforms/windows/win32drawbuf.d
index 2b8f64a7..512c908f 100644
--- a/src/dlangui/platforms/windows/win32drawbuf.d
+++ b/src/dlangui/platforms/windows/win32drawbuf.d
@@ -3,6 +3,7 @@ module dlangui.platforms.windows.win32drawbuf;
version (Windows) {
import win32.windows;
+import dlangui.core.logger;
import dlangui.graphics.drawbuf;
class Win32ColorDrawBuf : ColorDrawBufBase {
@@ -18,10 +19,15 @@ class Win32ColorDrawBuf : ColorDrawBufBase {
return _pixels + _dx * (_dy - 1 - y);
return null;
}
+ ~this() {
+ clear();
+ }
override void clear() {
if (_drawbmp !is null) {
DeleteObject( _drawbmp );
DeleteObject( _drawdc );
+ _drawbmp = null;
+ _drawdc = null;
_pixels = null;
_dx = 0;
_dy = 0;
@@ -62,7 +68,7 @@ class Win32ColorDrawBuf : ColorDrawBufBase {
_pixels[i] = color;
}
void drawTo(HDC dc, int x, int y) {
- BitBlt(dc, x, y, _dx, _dx, _drawdc, 0, 0, SRCCOPY);
+ BitBlt(dc, x, y, _dx, _dy, _drawdc, 0, 0, SRCCOPY);
}
}
diff --git a/src/dlangui/platforms/windows/winapp.d b/src/dlangui/platforms/windows/winapp.d
index 93de7c1d..32ab3b35 100644
--- a/src/dlangui/platforms/windows/winapp.d
+++ b/src/dlangui/platforms/windows/winapp.d
@@ -52,7 +52,7 @@ class Win32Window : Window {
//int dy = rect.bottom - rect.top;
if (_drawbuf is null)
_drawbuf = new Win32ColorDrawBuf(_dx, _dy);
- else
+ else
_drawbuf.resize(_dx, _dy);
return _drawbuf;
}
@@ -220,27 +220,29 @@ LRESULT WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
int dy = rect.bottom - rect.top;
//window.onResize(pos.cx, pos.cy);
window.onResize(dx, dy);
- UpdateWindow(hwnd);
+ InvalidateRect(hwnd, null, FALSE);
+ //UpdateWindow(hwnd);
}
return 0;
case WM_ERASEBKGND:
return 1;
case WM_PAINT:
{
- GetClientRect(hwnd, &rect);
- int dx = rect.right - rect.left;
- int dy = rect.bottom - rect.top;
- window.onResize(dx, dy);
+ //GetClientRect(hwnd, &rect);
+ //int dx = rect.right - rect.left;
+ //int dy = rect.bottom - rect.top;
+ //window.onResize(dx, dy);
+
hdc = BeginPaint(hwnd, &ps);
+ scope(exit) EndPaint(hwnd, &ps);
+
Win32ColorDrawBuf buf = window.getDrawBuf();
buf.fill(0x808080);
window.onDraw(buf);
buf.drawTo(hdc, 0, 0);
- //drawBuf2DC(hdc, 0, 0, buf);
- scope(exit) EndPaint(hwnd, &ps);
+
}
- //DrawTextA(hdc, "Hello, Windows!", -1, &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
- return 0;
+ return 0; // processed
case WM_DESTROY:
window.onDestroy();
diff --git a/src/dlangui/widgets/controls.d b/src/dlangui/widgets/controls.d
index 29c51f30..cbfcb09c 100644
--- a/src/dlangui/widgets/controls.d
+++ b/src/dlangui/widgets/controls.d
@@ -28,4 +28,4 @@ class Button : Widget {
applyAlign(rc, sz);
font.drawText(buf, rc.left, rc.top, text, textColor);
}
-}
\ No newline at end of file
+}
diff --git a/src/dlangui/widgets/styles.d b/src/dlangui/widgets/styles.d
index 36f3097a..3844d612 100644
--- a/src/dlangui/widgets/styles.d
+++ b/src/dlangui/widgets/styles.d
@@ -18,10 +18,10 @@ enum Align : ubyte {
Unspecified = ALIGN_UNSPECIFIED,
Left = 1,
Right = 2,
- HCenter = Left | Right,
+ HCenter = 1 | 2,
Top = 4,
Bottom = 8,
- VCenter = Top | Bottom,
+ VCenter = 4 | 8,
Center = VCenter | HCenter,
TopLeft = Left | Top,
}
@@ -95,6 +95,9 @@ class Style {
return (cast(Style)this)._backgroundDrawable;
}
+ //===================================================
+ // font properties
+
@property ref FontRef font() const {
if (!(cast(Style)this)._font.isNull)
return (cast(Style)this)._font;
@@ -147,6 +150,9 @@ class Style {
return parentStyle.fontSize;
}
+ //===================================================
+ // layout parameters: margins / padding
+
/// padding
@property ref const(Rect) padding() const {
if (_stateValue != 0)
@@ -169,6 +175,9 @@ class Style {
return parentStyle.textColor;
}
+ //===================================================
+ // background
+
/// background color
@property uint backgroundColor() const {
if (_backgroundColor != COLOR_UNSPECIFIED)
@@ -185,6 +194,9 @@ class Style {
return parentStyle.backgroundImageId;
}
+ //===================================================
+ // alignment
+
/// get full alignment (both vertical and horizontal)
@property ubyte alignment() const {
if (_align != Align.Unspecified)
@@ -193,9 +205,9 @@ class Style {
return parentStyle.alignment;
}
/// vertical alignment: Top / VCenter / Bottom
- @property ubyte valign() const { return _align & Align.VCenter; }
+ @property ubyte valign() const { return alignment & Align.VCenter; }
/// horizontal alignment: Left / HCenter / Right
- @property ubyte halign() const { return _align & Align.HCenter; }
+ @property ubyte halign() const { return alignment & Align.HCenter; }
/// set alignment
@property Style alignment(ubyte value) {
@@ -320,6 +332,7 @@ class Theme : Style {
Style modifyStyle(string id) {
Style style = new Style(null, null);
style._parentId = id;
+ style._align = Align.Unspecified; // inherit
return style;
}
@@ -346,5 +359,6 @@ private __gshared Theme _currentTheme;
static this() {
_currentTheme = new Theme("default");
- Style button = _currentTheme.createSubstyle("BUTTON").backgroundImageId("btn_default_normal").alignment(Align.Center);
+ Style button = _currentTheme.createSubstyle("BUTTON").backgroundImageId("btn_default_normal");
+ button.alignment(Align.Center);
}
diff --git a/src/dlangui/widgets/widget.d b/src/dlangui/widgets/widget.d
index 25330215..cb3b4d46 100644
--- a/src/dlangui/widgets/widget.d
+++ b/src/dlangui/widgets/widget.d
@@ -169,18 +169,20 @@ class Widget {
}
/// Applies alignment for content of size sz - set rectangle rc to aligned value of content inside of initial value of rc.
void applyAlign(ref Rect rc, Point sz) {
- if (valign == Align.Bottom) {
+ Align va = valign;
+ Align ha = halign;
+ if (va == Align.Bottom) {
rc.top = rc.bottom - sz.y;
- } else if (valign == Align.VCenter) {
+ } else if (va == Align.VCenter) {
int dy = (rc.height - sz.y) / 2;
rc.top += dy;
rc.bottom = rc.top + sz.y;
} else {
rc.bottom = rc.top + sz.y;
}
- if (halign == Align.Right) {
+ if (ha == Align.Right) {
rc.left = rc.right - sz.x;
- } else if (halign == Align.HCenter) {
+ } else if (ha == Align.HCenter) {
int dx = (rc.width - sz.x) / 2;
rc.left += dx;
rc.right = rc.left + sz.x;