From a72014f4d37b94a112384216922780acb516867f Mon Sep 17 00:00:00 2001 From: Reupen Shah Date: Wed, 2 Nov 2022 19:50:30 +0000 Subject: [PATCH] Fix rendering of tabs containing ampersands in dark mode This resolves a problem in the Playlist tabs and Tab stack panels where tab names containing ampersands (& characters) didn't render correctly when dark mode is active. --- CHANGELOG.md | 8 ++++++++ foo_ui_columns/dark_mode_tabs.cpp | 11 ++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3aa882dbf..788d79635 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Change log +## Development version + +### Bug fixes + +- A bug where ampersands didn’t render correctly in tab names in the Playlist + tabs and Tab stack panels when dark mode is active was fixed. + [[#622](https://github.com/reupen/columns_ui/pull/622)] + ## 2.0.0-alpha.5 ### Features diff --git a/foo_ui_columns/dark_mode_tabs.cpp b/foo_ui_columns/dark_mode_tabs.cpp index a49cf6c27..3bb083ef6 100644 --- a/foo_ui_columns/dark_mode_tabs.cpp +++ b/foo_ui_columns/dark_mode_tabs.cpp @@ -118,15 +118,12 @@ void handle_tab_control_paint(HWND wnd) LineTo(buffered_dc.get(), item_rect.left, item_rect.bottom); } - SIZE sz{}; - GetTextExtentPoint32(buffered_dc.get(), item.text.data(), gsl::narrow(item.text.length()), &sz); - // Position using original rect, but shift up 1px if it's the active tab - const auto x = item.rc.left + (RECT_CX(item.rc) - sz.cx) / 2; - const auto y = item.rc.top + (RECT_CY(item.rc) - sz.cy) / 2 - (item.is_active ? 1_spx : 0); + RECT text_rect = {item.rc.left, item.rc.top - (item.is_active ? 1_spx : 0), item.rc.right, + item.rc.bottom - (item.is_active ? 1_spx : 0)}; - ExtTextOut(buffered_dc.get(), x, y, ETO_CLIPPED, &item_rect, item.text.data(), - gsl::narrow(item.text.length()), nullptr); + DrawTextEx(buffered_dc.get(), const_cast(item.text.data()), gsl::narrow(item.text.length()), + &text_rect, DT_CENTER | DT_HIDEPREFIX | DT_SINGLELINE | DT_VCENTER, nullptr); } }