diff options
| author | Jonas Kümmerlin <jonas@kuemmerlin.eu> | 2018-12-27 22:54:55 +0100 |
|---|---|---|
| committer | Jonas Kümmerlin <jonas@kuemmerlin.eu> | 2018-12-27 23:01:28 +0100 |
| commit | a5f3ea9ac12fccbc9faf3f152d4dfbe7f263268e (patch) | |
| tree | 7e66ed4d7cb7e4b4ae56d8b562ff08121bf43026 /alf/alflabel.cpp | |
| parent | b0b0e97aa5a06b22768bb9c9ea5e8caf383d78a4 (diff) | |
make label, edit and button text line up perfectly
Diffstat (limited to 'alf/alflabel.cpp')
| -rw-r--r-- | alf/alflabel.cpp | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/alf/alflabel.cpp b/alf/alflabel.cpp index e9ae550..7402ecd 100644 --- a/alf/alflabel.cpp +++ b/alf/alflabel.cpp @@ -2,6 +2,17 @@ /* LABEL */ +static +int ALF__LabelTopPadding(HWND hwnd, ALFAPP app) +{ + // some pixels on top to align with the edit control + // see also: alfedit.cpp + return app->compatFn->GetSystemMetricsForDpi( + SM_CYEDGE, ALF_CentipointsToPixels(GetParent(hwnd), 7200)) + + 1 /* internal padding in edit control */ + + 1 /* external padding around edit control */; +} + static LRESULT CALLBACK ALF__LabelSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData) { @@ -41,12 +52,22 @@ ALF__LabelSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_ if (pSize->cx == 0) pSize->cx = r.right - r.left; if (pSize->cy == 0) - pSize->cy = r.bottom - r.top; + pSize->cy = r.bottom - r.top + ALF__LabelTopPadding(hwnd, app); if (font) SelectFont(hdcLabel, oldFont); ReleaseDC(hwnd, hdcLabel); + } else if (uMsg == ALF_WM_APPLYSIZE) { + RECT *p = (RECT *)lParam; + + int topPadding = ALF__LabelTopPadding(hwnd, app); + + return (LRESULT)DeferWindowPos((HDWP)wParam, + hwnd, NULL, + p->left, p->top + topPadding, + p->right - p->left, p->bottom - p->top - topPadding, + SWP_NOZORDER|SWP_NOACTIVATE); } return app->compatFn->DefSubclassProc(hwnd, uMsg, wParam, lParam); @@ -74,8 +95,7 @@ ALF_AddLabel(HWND win, WORD id, UINT x, UINT y, const WCHAR *text) p.y = y; p.width = 0; p.height = 0; - p.flags = ALF_QUERYSIZE | ALF_MESSAGEFONT; - p.margins[0] = 300; // TODO: pixel perfect margins from system metrics + p.flags = ALF_QUERYSIZE | ALF_APPLYSIZE | ALF_MESSAGEFONT; ALF_AddWidgetEx(win, &p); |
