From 64b6b40ace30693f0e12d56799abc40c997df07c Mon Sep 17 00:00:00 2001 From: Jonas Kümmerlin Date: Thu, 27 Dec 2018 20:17:02 +0100 Subject: tiny changes in edit and button sizing --- alf/alf.cpp | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/alf/alf.cpp b/alf/alf.cpp index 717f2df..f4117e7 100644 --- a/alf/alf.cpp +++ b/alf/alf.cpp @@ -842,8 +842,7 @@ ALF_AddLabel(HWND win, WORD id, UINT x, UINT y, const WCHAR *text) p.width = 0; p.height = 0; p.flags = ALF_QUERYSIZE | ALF_MESSAGEFONT; - p.margins[0] = 225; - p.margins[2] = 375; + p.margins[0] = 300; // TODO: pixel perfect margins from system metrics ALF_AddWidgetEx(win, &p); @@ -860,22 +859,30 @@ ALF__EditSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_P ALFAPP app = (ALFAPP)dwRefData; if (uMsg == ALF_WM_QUERYSIZE) { + HDC hDc = GetDC(hwnd); HFONT font = (HFONT)SendMessage(hwnd, WM_GETFONT, 0, 0); + if (font) { - LOGFONT lf; - ZeroMemory(&lf, sizeof(lf)); - if (GetObject(font, sizeof(lf), &lf)) { + HFONT oldfont = SelectFont(hDc, font); + + TEXTMETRIC tm; + ZeroMemory(&tm, sizeof(tm)); + + if (GetTextMetrics(hDc, &tm)) { SIZE *ps = (SIZE*)lParam; if (!ps->cx) { ps->cx = ALF_CentipointsToPixels(GetParent(hwnd), 12000); } if (!ps->cy) { - ps->cy = ALF_CentipointsToPixels(GetParent(hwnd), 525) - + MulDiv(16, -lf.lfHeight, 11); + ps->cy = tm.tmHeight + 6; // FIXME! use system metrics } } + + SelectFont(hDc, oldfont); } + + ReleaseDC(hwnd, hDc); return 0; } @@ -898,6 +905,7 @@ ALF_AddEdit(HWND win, WORD id, UINT x, UINT y, const WCHAR *text) ALFAPP app = ALF_ApplicationFromWindow(win); app->compatFn->SetWindowSubclass(hwndEdit, ALF__EditSubclassProc, 0, (DWORD_PTR)app); + SetWindowPos(hwndEdit, NULL, 0, 0, 0, 0, SWP_NOZORDER | SWP_NOSIZE | SWP_NOMOVE | SWP_FRAMECHANGED); ALFAddWidgetParams p; ZeroMemory(&p, sizeof(p)); @@ -907,6 +915,8 @@ ALF_AddEdit(HWND win, WORD id, UINT x, UINT y, const WCHAR *text) p.width = 0; p.height = 0; p.flags = ALF_QUERYSIZE | ALF_MESSAGEFONT; + p.margins[0] = 75; // TODO: pixel-perfect margin from system metrics + p.margins[2] = 75; ALF_AddWidgetEx(win, &p); @@ -945,21 +955,18 @@ ALF__ButtonSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT HeapFree(GetProcessHeap(), 0, textbuf); + // TODO: calculate from system metrics int padding = ALF_CentipointsToPixels(GetParent(hwnd), 525); - int minheight = ALF_CentipointsToPixels(GetParent(hwnd), 1725); SIZE *pSize = (SIZE*)(void*)lParam; if (pSize->cx < r.right - r.left + padding) { pSize->cx = r.right - r.left + padding; } - if (pSize->cx < minheight) { - pSize->cx = minheight; - } if (pSize->cy < r.bottom - r.top + padding) { pSize->cy = r.bottom - r.top + padding; } - if (pSize->cy < minheight) { - pSize->cy = minheight; + if (pSize->cx < pSize->cy) { + pSize->cx = pSize->cy; } if (font) -- cgit v1.2.3