Separate imagelist for tab bar close button icons for dark/light modes

Ref: https://github.com/notepad-plus-plus/notepad-plus-plus/pull/15321

Close #15326
pull/15336/head
ozone10 5 months ago committed by Don Ho
parent 6b441b738a
commit 25686c22e4

@ -462,21 +462,31 @@ void TabBarPlus::currentTabToEnd()
void TabBarPlus::setCloseBtnImageList()
{
int iconSize = 0;
std::vector<int> ids;
if (NppDarkMode::isEnabled())
{
iconSize = g_TabCloseBtnSize_DM;
ids = { IDR_CLOSETAB_DM, IDR_CLOSETAB_INACT_DM, IDR_CLOSETAB_HOVER_DM, IDR_CLOSETAB_PUSH_DM };
}
else
{
iconSize = g_TabCloseBtnSize;
ids = { IDR_CLOSETAB, IDR_CLOSETAB_INACT, IDR_CLOSETAB_HOVER, IDR_CLOSETAB_PUSH };
}
if (_hCloseBtnImgLst != nullptr)
{
::ImageList_Destroy(_hCloseBtnImgLst);
_hCloseBtnImgLst = nullptr;
}
const int btnSize = _dpiManager.scale(g_TabCloseBtnSize);
const int btnSize = _dpiManager.scale(iconSize);
const auto idsCloseIcons = {
IDR_CLOSETAB, IDR_CLOSETAB_INACT, IDR_CLOSETAB_HOVER, IDR_CLOSETAB_PUSH,
IDR_CLOSETAB_DM, IDR_CLOSETAB_INACT_DM, IDR_CLOSETAB_HOVER_DM, IDR_CLOSETAB_PUSH_DM };
_hCloseBtnImgLst = ::ImageList_Create(btnSize, btnSize, ILC_COLOR32 | ILC_MASK, static_cast<int>(ids.size()), 0);
_hCloseBtnImgLst = ::ImageList_Create(btnSize, btnSize, ILC_COLOR32 | ILC_MASK, static_cast<int>(idsCloseIcons.size()), 0);
for (const auto& id : idsCloseIcons)
for (const auto& id : ids)
{
HICON hIcon = nullptr;
DPIManagerV2::loadIcon(_hInst, MAKEINTRESOURCE(id), btnSize, btnSize, &hIcon);
@ -552,6 +562,7 @@ LRESULT TabBarPlus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPara
case NPPM_INTERNAL_REFRESHDARKMODE:
{
NppDarkMode::setDarkTooltips(hwnd, NppDarkMode::ToolTipsType::tabbar);
setCloseBtnImageList();
return TRUE;
}
@ -1304,7 +1315,7 @@ void TabBarPlus::drawItem(DRAWITEMSTRUCT *pDrawItemStruct, bool isDarkMode)
{
// 3 status for each inactive tab and selected tab close item :
// normal / hover / pushed
int idxCloseImg = isDarkMode ? 4 : 0; // selected
int idxCloseImg = 0; // selected
if (_isCloseHover && (_currentHoverTabItem == nTab))
{
@ -1557,16 +1568,6 @@ void TabBarPlus::exchangeItemData(POINT point)
}
CloseButtonZone::CloseButtonZone()
{
// TODO: get width/height of close button dynamically
if (_parent)
{
_width = DPIManagerV2::scale(g_TabCloseBtnSize, _parent);
}
_height = _width;
}
bool CloseButtonZone::isHit(int x, int y, const RECT & tabRect, bool isVertical) const
{
RECT buttonRect = getButtonRectFrom(tabRect, isVertical);

@ -54,6 +54,7 @@ constexpr int g_TabHeightLarge = 25;
constexpr int g_TabWidth = 45;
constexpr int g_TabWidthCloseBtn = 60;
constexpr int g_TabCloseBtnSize = 11;
constexpr int g_TabCloseBtnSize_DM = 16;
struct TBHDR
{
@ -138,7 +139,6 @@ protected:
struct CloseButtonZone
{
CloseButtonZone();
bool isHit(int x, int y, const RECT & tabRect, bool isVertical) const;
RECT getButtonRectFrom(const RECT & tabRect, bool isVertical) const;
void setParent(HWND parent) { _parent = parent; }

Loading…
Cancel
Save