Skip to content

Commit

Permalink
Improved small toolbar button size issue in hidpi (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
funap committed Mar 4, 2023
1 parent 3a5c9cc commit f9cf0f1
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 25 deletions.
34 changes: 20 additions & 14 deletions src/Explorer/ExplorerDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,22 +413,25 @@ INT_PTR CALLBACK ExplorerDialog::run_dlgProc(UINT Message, WPARAM wParam, LPARAM
_ToolBar.reSizeTo(rc);
_Rebar.reSizeTo(rc);

auto toolBarHeight = _ToolBar.getHeight();
auto filterHeight = GetSystemMetrics(SM_CYSMSIZE);

/* set position of tree control */
getClientRect(rc);
rc.top += 26;
rc.top += toolBarHeight;
rc.bottom = splitterPos;
::SetWindowPos(_hTreeCtrl, NULL, rc.left, rc.top, rc.right, rc.bottom, SWP_NOZORDER | SWP_SHOWWINDOW);

/* set splitter */
getClientRect(rc);
rc.top = (splitterPos + 26);
rc.top = (splitterPos + toolBarHeight);
rc.bottom = 6;
::SetWindowPos(_hSplitterCtrl, NULL, rc.left, rc.top, rc.right, rc.bottom, SWP_NOZORDER | SWP_SHOWWINDOW);

/* set position of list control */
getClientRect(rc);
rc.top = (splitterPos + 32);
rc.bottom -= (splitterPos + 32 + 22);
rc.top = (splitterPos + toolBarHeight + 6);
rc.bottom -= (splitterPos + toolBarHeight + 6 + filterHeight);
::SetWindowPos(_hListCtrl, NULL, rc.left, rc.top, rc.right, rc.bottom, SWP_NOZORDER | SWP_SHOWWINDOW);

/* set position of filter controls */
Expand All @@ -438,16 +441,16 @@ INT_PTR CALLBACK ExplorerDialog::run_dlgProc(UINT Message, WPARAM wParam, LPARAM
/* set position of static text */
hWnd = ::GetDlgItem(_hSelf, IDC_STATIC_FILTER);
::GetWindowRect(hWnd, &rcWnd);
rc.top = rcBuff.bottom - 18;
rc.bottom = 12;
rc.top = rcBuff.bottom - filterHeight + 6;
rc.bottom = filterHeight;
rc.left += 2;
rc.right = rcWnd.right - rcWnd.left;
::SetWindowPos(hWnd, NULL, rc.left, rc.top, rc.right, rc.bottom, SWP_NOZORDER | SWP_SHOWWINDOW);
rcBuff.left = rc.right + 4;

/* set position of combo */
rc.top = rcBuff.bottom - 21;
rc.bottom = 20;
rc.top = rcBuff.bottom - filterHeight + 1;
rc.bottom = filterHeight;
rc.left = rcBuff.left;
rc.right = rcBuff.right - rcBuff.left;
::SetWindowPos(_hFilter, NULL, rc.left, rc.top, rc.right, rc.bottom, SWP_NOZORDER | SWP_SHOWWINDOW);
Expand All @@ -466,10 +469,13 @@ INT_PTR CALLBACK ExplorerDialog::run_dlgProc(UINT Message, WPARAM wParam, LPARAM
_ToolBar.reSizeTo(rc);
_Rebar.reSizeTo(rc);

auto toolBarHeight = _ToolBar.getHeight();
auto filterHeight = GetSystemMetrics(SM_CYSMSIZE);

/* set position of tree control */
getClientRect(rc);
rc.top += 26;
rc.bottom -= 26 + 22;
rc.top += toolBarHeight;
rc.bottom -= toolBarHeight + filterHeight;
rc.right = splitterPos;
::SetWindowPos(_hTreeCtrl, NULL, rc.left, rc.top, rc.right, rc.bottom, SWP_NOZORDER | SWP_SHOWWINDOW);

Expand All @@ -480,17 +486,17 @@ INT_PTR CALLBACK ExplorerDialog::run_dlgProc(UINT Message, WPARAM wParam, LPARAM
/* set position of static text */
hWnd = ::GetDlgItem(_hSelf, IDC_STATIC_FILTER);
::GetWindowRect(hWnd, &rcWnd);
rc.top = rcBuff.bottom - 18;
rc.bottom = 12;
rc.top = rcBuff.bottom - filterHeight + 6;
rc.bottom = filterHeight;
rc.left += 2;
rc.right = rcWnd.right - rcWnd.left;
::SetWindowPos(hWnd, NULL, rc.left, rc.top, rc.right, rc.bottom, SWP_NOZORDER | SWP_SHOWWINDOW);

rcBuff.left = rc.right + 4;

/* set position of combo */
rc.top = rcBuff.bottom - 21;
rc.bottom = 20;
rc.top = rcBuff.bottom - filterHeight + 6;
rc.bottom = filterHeight;
rc.left = rcBuff.left;
rc.right = splitterPos - rcBuff.left;
::SetWindowPos(_hFilter, NULL, rc.left, rc.top, rc.right, rc.bottom, SWP_NOZORDER | SWP_SHOWWINDOW);
Expand Down
12 changes: 7 additions & 5 deletions src/Explorer/FavesDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,14 +328,16 @@ INT_PTR CALLBACK FavesDialog::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lP
case WM_SIZE:
case WM_MOVE: {
RECT rc = {};
/* set position of toolbar */
getClientRect(rc);
_ToolBar.reSizeTo(rc);
_Rebar.reSizeTo(rc);

/* set position of toolbar */
getClientRect(rc);
_Rebar.reSizeTo(rc);
auto toolBarHeight = _ToolBar.getHeight();

/* set position of tree control */
rc.top += 26;
rc.bottom -= 26;
rc.top += toolBarHeight;
rc.bottom -= toolBarHeight;
::SetWindowPos(_hTreeCtrl, nullptr, rc.left, rc.top, rc.right, rc.bottom, SWP_NOZORDER | SWP_SHOWWINDOW);

break;
Expand Down
11 changes: 5 additions & 6 deletions src/Explorer/ToolBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ bool ToolBar::init( HINSTANCE hInst, HWND hPere, toolBarStatusType type,
{
Window::init(hInst, hPere);
_state = type;
int iconSize = (_state == TB_LARGE?32:16);
int iconSize = GetSystemMetrics(SM_CYSMICON);

_toolBarIcons.init(buttonUnitArray, arraySize);
_toolBarIcons.create(_hInst, iconSize);
Expand Down Expand Up @@ -80,7 +80,7 @@ void ToolBar::destroy()
::DestroyWindow(_hSelf);
_hSelf = NULL;
_toolBarIcons.destroy();
};
}

int ToolBar::getWidth() const
{
Expand Down Expand Up @@ -172,11 +172,10 @@ void ToolBar::reset(bool create)
if (create) { //if the toolbar has been recreated, readd the buttons
SIZE_T nrBtnToAdd = _nrButtons;
_nrCurrentButtons = nrBtnToAdd;
WORD btnSize = (_state == TB_LARGE?32:16);
::SendMessage(_hSelf, TB_SETBUTTONSIZE , (WPARAM)0, (LPARAM)MAKELONG (btnSize, btnSize));
WORD btnSize = GetSystemMetrics(SM_CYSMICON);
::SendMessage(_hSelf, TB_ADDBUTTONS, (WPARAM)nrBtnToAdd, (LPARAM)_pTBB);
}
::SendMessage(_hSelf, TB_AUTOSIZE, 0, 0);
::SendMessage(_hSelf, TB_SETBUTTONSIZE, (WPARAM)0, (LPARAM)MAKELONG(btnSize, btnSize));
}

if (_pRebar) {
_rbBand.hwndChild = getHSelf();
Expand Down

0 comments on commit f9cf0f1

Please sign in to comment.