Improve docking tab visual

1. Improve high DPI look.
2. Make dark mode color consistent.
3. Allow icons transparency.
This commit is contained in:
ozone10 2021-07-21 22:13:43 +02:00 committed by Don Ho
parent 0f15c207d5
commit 3e69de4879
2 changed files with 35 additions and 27 deletions

View File

@ -697,8 +697,8 @@ LRESULT DockingCont::runProcTab(HWND hwnd, UINT Message, WPARAM wParam, LPARAM l
} }
PAINTSTRUCT ps; PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps); HDC hdc = ::BeginPaint(hwnd, &ps);
FillRect(hdc, &ps.rcPaint, NppDarkMode::getBackgroundBrush()); ::FillRect(hdc, &ps.rcPaint, NppDarkMode::getDarkerBackgroundBrush());
UINT id = ::GetDlgCtrlID(hwnd); UINT id = ::GetDlgCtrlID(hwnd);
@ -733,23 +733,25 @@ LRESULT DockingCont::runProcTab(HWND hwnd, UINT Message, WPARAM wParam, LPARAM l
RECT rcIntersect = { 0 }; RECT rcIntersect = { 0 };
if (IntersectRect(&rcIntersect, &ps.rcPaint, &dis.rcItem)) if (IntersectRect(&rcIntersect, &ps.rcPaint, &dis.rcItem))
{ {
dis.rcItem.top += NppParameters::getInstance()._dpiManager.scaleY(1);
dis.rcItem.right -= 1;
dis.rcItem.bottom += 2;
if (i == 0) if (i == 0)
{ {
POINT edges[] = { POINT edges[] = {
{dis.rcItem.left - 1, dis.rcItem.top}, {dis.rcItem.left - 1, dis.rcItem.top},
{dis.rcItem.left - 1, dis.rcItem.bottom + 2} {dis.rcItem.left - 1, dis.rcItem.bottom}
}; };
Polyline(hdc, edges, _countof(edges)); Polyline(hdc, edges, _countof(edges));
} }
{ {
POINT edges[] = { POINT edges[] = {
{dis.rcItem.right - 1, dis.rcItem.top}, {dis.rcItem.right, dis.rcItem.top},
{dis.rcItem.right - 1, dis.rcItem.bottom + 2} {dis.rcItem.right, dis.rcItem.bottom}
}; };
Polyline(hdc, edges, _countof(edges)); Polyline(hdc, edges, _countof(edges));
dis.rcItem.right -= 1;
dis.rcItem.bottom += 2;
} }
HRGN hClip = CreateRectRgnIndirect(&dis.rcItem); HRGN hClip = CreateRectRgnIndirect(&dis.rcItem);
@ -984,16 +986,20 @@ void DockingCont::drawTabItem(DRAWITEMSTRUCT *pDrawItemStruct)
rc.top += ::GetSystemMetrics(SM_CYEDGE); rc.top += ::GetSystemMetrics(SM_CYEDGE);
::SetBkMode(hDc, TRANSPARENT); ::SetBkMode(hDc, TRANSPARENT);
HBRUSH hBrush;
if (NppDarkMode::isEnabled() && isSelected) if (NppDarkMode::isEnabled())
{ {
RECT selectedRect = rc; RECT selectedRect = rc;
selectedRect.top -= NppParameters::getInstance()._dpiManager.scaleY(2); selectedRect.top -= 2;
selectedRect.bottom += NppParameters::getInstance()._dpiManager.scaleX(4); selectedRect.bottom += 2;
hBrush = ::CreateSolidBrush(NppDarkMode::getSofterBackgroundColor()); if (isSelected)
::FillRect(hDc, &selectedRect, hBrush); {
::DeleteObject((HGDIOBJ)hBrush); ::FillRect(hDc, &selectedRect, NppDarkMode::getSofterBackgroundBrush());
}
else
{
::FillRect(hDc, &selectedRect, NppDarkMode::getBackgroundBrush());
}
} }
// draw orange bar // draw orange bar
@ -1002,9 +1008,9 @@ void DockingCont::drawTabItem(DRAWITEMSTRUCT *pDrawItemStruct)
RECT barRect = rc; RECT barRect = rc;
barRect.top += rc.bottom - 4; barRect.top += rc.bottom - 4;
hBrush = ::CreateSolidBrush(RGB(250, 170, 60)); HBRUSH hBrush = ::CreateSolidBrush(RGB(250, 170, 60));
::FillRect(hDc, &barRect, hBrush); ::FillRect(hDc, &barRect, hBrush);
::DeleteObject((HGDIOBJ)hBrush); ::DeleteObject(hBrush);
} }
// draw icon if enabled // draw icon if enabled
@ -1021,8 +1027,14 @@ void DockingCont::drawTabItem(DRAWITEMSTRUCT *pDrawItemStruct)
ImageList_GetImageInfo(hImageList, iPosImage, &info); ImageList_GetImageInfo(hImageList, iPosImage, &info);
int iconDpiDynamicalY = NppParameters::getInstance()._dpiManager.scaleY(7); int darkPaddingX = NppDarkMode::isEnabled() ? 1 : 0;
ImageList_Draw(hImageList, iPosImage, hDc, rc.left + 3, iconDpiDynamicalY, ILD_NORMAL); int darkPaddingY = NppDarkMode::isEnabled() ? 2 : (isSelected ? 1 : 0);
int iconDpiDynamicalX = isSelected ? rc.left + 3
: rc.left + (rc.right - rc.left - imageRect.right + imageRect.left) / 2 + darkPaddingX;
int iconDpiDynamicalY = NppParameters::getInstance()._dpiManager.scaleY(5) + darkPaddingY;
ImageList_Draw(hImageList, iPosImage, hDc, iconDpiDynamicalX, iconDpiDynamicalY, ILD_NORMAL);
if (isSelected) if (isSelected)
{ {
@ -1076,7 +1088,7 @@ INT_PTR CALLBACK DockingCont::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lP
_hDefaultTabProc = reinterpret_cast<WNDPROC>(::SetWindowLongPtr(_hContTab, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(wndTabProc))); _hDefaultTabProc = reinterpret_cast<WNDPROC>(::SetWindowLongPtr(_hContTab, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(wndTabProc)));
// set min tab width // set min tab width
int tabDpiDynamicalMinWidth = NppParameters::getInstance()._dpiManager.scaleY(24); int tabDpiDynamicalMinWidth = NppParameters::getInstance()._dpiManager.scaleX(24);
::SendMessage(_hContTab, TCM_SETMINTABWIDTH, 0, tabDpiDynamicalMinWidth); ::SendMessage(_hContTab, TCM_SETMINTABWIDTH, 0, tabDpiDynamicalMinWidth);
break; break;
@ -1095,7 +1107,7 @@ INT_PTR CALLBACK DockingCont::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lP
} }
RECT rc = { 0 }; RECT rc = { 0 };
getClientRect(rc); getClientRect(rc);
FillRect((HDC)wParam, &rc, NppDarkMode::getBackgroundBrush()); ::FillRect(reinterpret_cast<HDC>(wParam), &rc, NppDarkMode::getDarkerBackgroundBrush());
return TRUE; return TRUE;
} }
@ -1182,7 +1194,7 @@ void DockingCont::onSize()
if (iItemCnt >= 1) if (iItemCnt >= 1)
{ {
// resize to docked window // resize to docked window
int tabDpiDynamicalHeight = NppParameters::getInstance()._dpiManager.scaleY(24); int tabDpiDynamicalHeight = NppParameters::getInstance()._dpiManager.scaleY(16) + 8;
if (_isFloating == false) if (_isFloating == false)
{ {
// draw caption // draw caption
@ -1640,4 +1652,3 @@ LPARAM DockingCont::NotifyParent(UINT message)
{ {
return ::SendMessage(_hParent, message, 0, reinterpret_cast<LPARAM>(this)); return ::SendMessage(_hParent, message, 0, reinterpret_cast<LPARAM>(this));
} }

View File

@ -15,7 +15,6 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <stdexcept> #include <stdexcept>
#include "DockingManager.h" #include "DockingManager.h"
#include "DockingSplitter.h" #include "DockingSplitter.h"
@ -559,8 +558,8 @@ void DockingManager::createDockableDlg(tTbData data, int iCont, bool isVisible)
// create image list if not exist // create image list if not exist
if (_hImageList == NULL) if (_hImageList == NULL)
{ {
int iconDpiDynamicalSize = NppParameters::getInstance()._dpiManager.scaleY(14); int iconDpiDynamicalSize = NppParameters::getInstance()._dpiManager.scaleY(12) + 2;
_hImageList = ::ImageList_Create(iconDpiDynamicalSize,iconDpiDynamicalSize,ILC_COLOR8, 0, 0); _hImageList = ::ImageList_Create(iconDpiDynamicalSize, iconDpiDynamicalSize, ILC_COLOR32 | ILC_MASK, 0, 0);
} }
// add icon // add icon
@ -971,5 +970,3 @@ int DockingManager::FindEmptyContainer()
// search for empty arrays // search for empty arrays
return iRetCont; return iRetCont;
} }