From d28cd7fb71a6fe56a04d4e21f2b95907a1ec105c Mon Sep 17 00:00:00 2001 From: Jonas Kümmerlin Date: Wed, 29 Apr 2020 14:59:38 +0200 Subject: layout: make minimum size actually work as a minimum --- alf/alflayout.cpp | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) (limited to 'alf/alflayout.cpp') diff --git a/alf/alflayout.cpp b/alf/alflayout.cpp index 6c5326d..1cdd328 100644 --- a/alf/alflayout.cpp +++ b/alf/alflayout.cpp @@ -196,15 +196,12 @@ ALF_Layout_CalcEditSize(HWND hwndWindow, ALFLayout *layout, HWND hwndEdit, SIZE ZeroMemory(&tm, sizeof(tm)); if (GetTextMetrics(hDc, &tm)) { - if (!ps->cx) { - ps->cx = ALF_CentipointsToPixels(12000, layout->dpi); - } - - if (!ps->cy) { - ps->cy = tm.tmHeight + 2*ALF_Compat_GetSystemMetricsForDpi( + int cy = tm.tmHeight + 2*ALF_Compat_GetSystemMetricsForDpi( SM_CYEDGE, (UINT)layout->dpi) + 4 /* padding internal to the edit control */; - } + + if (ps->cy < cy) + ps->cy = cy; } SelectFont(hDc, oldfont); @@ -229,20 +226,20 @@ ALF_Layout_CalcCheckboxSize(HWND hwndWindow, ALFLayout *layout, HWND hwndCheckbo DrawText(hDC, textbuf, -1, &r, DT_CALCRECT); ALF_Free(textbuf); - if (!ps->cx) { - // lol - int cw = 0; - GetCharWidth(hDC, '0', '0', &cw); + // lol + int cx = 0; + GetCharWidth(hDC, '0', '0', &cx); - ps->cx = checkwidth + r.right - r.left + cw; - } + cx += checkwidth + r.right - r.left; - if (!ps->cy) { - int height = r.bottom - r.top; - if (checkwidth > height) - height = checkwidth; - ps->cy = height; - } + int cy = r.bottom - r.top; + if (checkwidth > cy) + cy = checkwidth; + + if (ps->cx < cx) + ps->cx = cx; + if (ps->cy < cy) + ps->cy = cy; SelectFont(hDC, oldfont); ReleaseDC(hwndCheckbox, hDC); @@ -823,7 +820,12 @@ ALF_Layout_HandleMessage(ALFLayout *layout, HWND hwnd, UINT msg, WPARAM wparam, *pRet = 0; if (msg == ALF_WM_QUERYSIZE) { - ALF_Layout_GetMinSize(layout, hwnd, (SIZE*)lparam); + SIZE s = { 0, 0 }; + ALF_Layout_GetMinSize(layout, hwnd, &s); + if (((SIZE*)lparam)->cx < s.cx) + ((SIZE*)lparam)->cx = s.cx; + if (((SIZE*)lparam)->cy < s.cy) + ((SIZE*)lparam)->cy = s.cy; return TRUE; } -- cgit v1.2.3