Skip to content

Commit

Permalink
remove TextSizeInHwnd() (replaced with HwndMeasureText()
Browse files Browse the repository at this point in the history
  • Loading branch information
kjk committed Nov 2, 2023
1 parent e826220 commit e978027
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 36 deletions.
4 changes: 2 additions & 2 deletions src/Installer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ static void CreateInstallerWindowControls(InstallerWnd* wnd) {
gButtonDy = btnSize.dy;
gBottomPartDy = gButtonDy + (margin * 2);

Size size = TextSizeInHwnd(hwnd, "Foo");
Size size = HwndMeasureText(hwnd, "Foo");
int staticDy = size.dy + DpiScale(hwnd, 6);

y = r.dy - gBottomPartDy;
Expand Down Expand Up @@ -710,7 +710,7 @@ static void CreateInstallerWindowControls(InstallerWnd* wnd) {
y -= (DpiScale(hwnd, 4) + margin);

const char* s = "&...";
Size btnSize2 = TextSizeInHwnd(hwnd, s);
Size btnSize2 = HwndMeasureText(hwnd, s);
btnSize2.dx += DpiScale(hwnd, 4);
wnd->btnBrowseDir = CreateDefaultButton(hwnd, s);
wnd->btnBrowseDir->onClicked = OnButtonBrowse;
Expand Down
28 changes: 0 additions & 28 deletions src/utils/WinUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2846,34 +2846,6 @@ void DrawCenteredText(HDC hdc, const RECT& r, const WCHAR* txt, bool isRTL) {
DrawCenteredText(hdc, rc, txt, isRTL);
}

// Return size of a text <txt> in a given <hwnd>, taking into account its font
Size TextSizeInHwnd(HWND hwnd, const WCHAR* txt, HFONT font) {
if (!txt || !*txt) {
return Size{};
}
size_t txtLen = str::Len(txt);
AutoReleaseDC dc(hwnd);
/* GetWindowDC() returns dc with default state, so we have to first set
window's current font into dc */
if (font == nullptr) {
font = (HFONT)SendMessageW(hwnd, WM_GETFONT, 0, 0);
}
HGDIOBJ prev = SelectObject(dc, font);
SIZE sz{};
GetTextExtentPoint32W(dc, txt, (int)txtLen, &sz);
SelectObject(dc, prev);
return Size(sz.cx, sz.cy);
}

// Return size of a text <txt> in a given <hwnd>, taking into account its font
Size TextSizeInHwnd(HWND hwnd, const char* txt, HFONT font) {
if (!txt || !*txt) {
return Size{};
}
TempWStr ws = ToWStrTemp(txt);
return TextSizeInHwnd(hwnd, ws, font);
}

/* Return size of a text <txt> in a given <hwnd>, taking into account its font */
Size HwndMeasureText(HWND hwnd, const WCHAR* txt, HFONT font) {
if (!txt || !*txt) {
Expand Down
2 changes: 0 additions & 2 deletions src/utils/WinUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,6 @@ void DrawLine(HDC, const Rect&);
void DrawCenteredText(HDC hdc, Rect r, const WCHAR* txt, bool isRTL = false);
void DrawCenteredText(HDC hdc, Rect r, const char* txt, bool isRTL = false);
void DrawCenteredText(HDC, const RECT& r, const WCHAR* txt, bool isRTL = false);
Size TextSizeInHwnd(HWND, const WCHAR*, HFONT = nullptr);
Size TextSizeInHwnd(HWND, const char*, HFONT = nullptr);
Size HwndMeasureText(HWND hwnd, const char* txt, HFONT font = nullptr);

int HdcDrawText(HDC hdc, const char* s, RECT* r, uint format, HFONT font = nullptr);
Expand Down
2 changes: 1 addition & 1 deletion src/wingui/FrameRateWnd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ static void PositionWindow(FrameRateWnd* w, SIZE s) {

static SIZE GetIdealSize(FrameRateWnd* w) {
TempStr txt = str::FormatTemp("%d", w->frameRate);
Size s = TextSizeInHwnd(w->hwnd, txt);
Size s = HwndMeasureText(w->hwnd, txt);

// add padding
s.dy += 4;
Expand Down
5 changes: 2 additions & 3 deletions src/wingui/WinGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2144,13 +2144,12 @@ void DropDown::SetItemsSeqStrings(const char* items) {

Size DropDown::GetIdealSize() {
HFONT hfont = GetWindowFont(hwnd);
Size s1 = TextSizeInHwnd(hwnd, L"Minimal", hfont);
Size s1 = HwndMeasureText(hwnd, "Minimal", hfont);

int n = items.Size();
for (int i = 0; i < n; i++) {
char* s = items[i];
WCHAR* ws = ToWStrTemp(s);
Size s2 = TextSizeInHwnd(hwnd, ws, hfont);
Size s2 = HwndMeasureText(hwnd, s, hfont);
s1.dx = std::max(s1.dx, s2.dx);
s1.dy = std::max(s1.dy, s2.dy);
}
Expand Down

0 comments on commit e978027

Please sign in to comment.