Skip to content

Commit e739bfb

Browse files
committed
fix(win32): non-transparent LinkLabel bk color
1 parent ce3a340 commit e739bfb

2 files changed

Lines changed: 33 additions & 13 deletions

File tree

winio-ui-win32/src/runtime.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@ use windows_sys::{
2121
Foundation::{HWND, LPARAM, LRESULT, RECT, SetLastError, WPARAM},
2222
Graphics::{
2323
Dwm::DwmExtendFrameIntoClientArea,
24-
Gdi::{
25-
BLACK_BRUSH, GetStockObject, HDC, InvalidateRect, NULL_BRUSH, SetBkMode,
26-
SetTextColor, TRANSPARENT, WHITE_BRUSH,
27-
},
24+
Gdi::{BLACK_BRUSH, GetStockObject, HDC, InvalidateRect, WHITE_BRUSH},
2825
},
2926
UI::{
3027
Controls::{MARGINS, NMHDR},
@@ -41,8 +38,8 @@ use windows_sys::{
4138
core::BOOL,
4239
};
4340
use winio_ui_windows_common::{
44-
Backdrop, children_refresh_dark_mode, control_color_edit, control_color_static, init_dark,
45-
is_dark_mode_allowed_for_app, window_use_dark_mode,
41+
Backdrop, children_refresh_dark_mode, control_color_edit, control_color_link_label,
42+
control_color_static, init_dark, is_dark_mode_allowed_for_app, window_use_dark_mode,
4643
};
4744

4845
use super::RUNTIME;
@@ -289,13 +286,7 @@ pub(crate) unsafe extern "system" fn window_proc(
289286
let mut data = 0;
290287
if GetWindowSubclass(hwnd, Some(link_label_wnd_proc), 0, &mut data) != 0 {
291288
// This is a LinkLabel
292-
SetBkMode(hdc, TRANSPARENT as _);
293-
if is_dark_mode_allowed_for_app() {
294-
SetTextColor(hdc, 0xFFFC96);
295-
} else {
296-
SetTextColor(hdc, 0xCC6600);
297-
}
298-
return GetStockObject(NULL_BRUSH) as _;
289+
return control_color_link_label(hwnd, hdc);
299290
} else {
300291
return control_color_static(hwnd, hdc);
301292
}

winio-ui-windows-common/src/darkmode/mod.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,35 @@ pub unsafe fn control_color_static(hwnd: HWND, hdc: HDC) -> LRESULT {
116116
}
117117
}
118118

119+
/// # Safety
120+
/// It should only be called inside an wndproc, and `hwnd` & `hdc` should be
121+
/// valid.
122+
pub unsafe fn control_color_link_label(hwnd: HWND, hdc: HDC) -> LRESULT {
123+
unsafe {
124+
let dark = is_dark_mode_allowed_for_app();
125+
126+
let is_transparent = (GetWindowLongPtrW(hwnd, GWL_EXSTYLE) as u32 & WS_EX_TRANSPARENT) != 0;
127+
128+
SetBkMode(hdc, TRANSPARENT as _);
129+
if dark {
130+
SetTextColor(hdc, 0xFFFC96);
131+
if !is_transparent {
132+
SetBkColor(hdc, BLACK);
133+
}
134+
} else {
135+
SetTextColor(hdc, 0xCC6600);
136+
}
137+
let res = if is_transparent {
138+
GetStockObject(NULL_BRUSH)
139+
} else if dark {
140+
GetStockObject(BLACK_BRUSH)
141+
} else {
142+
GetStockObject(WHITE_BRUSH)
143+
};
144+
res as _
145+
}
146+
}
147+
119148
/// # Safety
120149
/// It should only be called inside an wndproc, and `hparent` & `hwnd` & `hdc`
121150
/// should be valid.

0 commit comments

Comments
 (0)