Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement custom selection backgrounds with dark mode on #127

Merged
merged 2 commits into from Apr 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 29 additions & 3 deletions foo_uie_albumlist/main_window_proc.cpp
Expand Up @@ -276,24 +276,50 @@ std::optional<LRESULT> album_list_window::on_tree_view_wm_notify(LPNMHDR hdr)
case CDDS_PREPAINT:
if (cui::colours::helper(album_list_items_colours_client_id).get_themed())
return CDRF_DODEFAULT;
return CDRF_NOTIFYITEMDRAW;
return CDRF_NOTIFYITEMDRAW | CDRF_NOTIFYPOSTERASE;
case CDDS_ITEMPREPAINT: {
const auto is_window_focused = GetFocus() == hdr->hwndFrom;
const auto is_selected = (nmtvcd->nmcd.uItemState & CDIS_SELECTED) != 0;
const auto is_drop_highlighted
= (TreeView_GetItemState(hdr->hwndFrom, nmtvcd->nmcd.dwItemSpec, TVIS_DROPHILITED) & TVIS_DROPHILITED)
!= 0;

cui::colours::helper colour_client(album_list_items_colours_client_id);

if (is_selected || is_drop_highlighted) {
cui::colours::helper colour_client(album_list_items_colours_client_id);

nmtvcd->clrText = is_window_focused
? colour_client.get_colour(cui::colours::colour_selection_text)
: colour_client.get_colour(cui::colours::colour_inactive_selection_text);
nmtvcd->clrTextBk = is_window_focused
? colour_client.get_colour(cui::colours::colour_selection_background)
: colour_client.get_colour(cui::colours::colour_inactive_selection_background);

if (cui::colours::is_dark_mode_active())
return CDRF_NOTIFYPOSTPAINT;
}

return CDRF_DODEFAULT;
}
case CDDS_ITEMPOSTPAINT: {
if (!nmtvcd->nmcd.lItemlParam)
return CDRF_DODEFAULT;

const auto draw_node = reinterpret_cast<node*>(nmtvcd->nmcd.lItemlParam)->shared_from_this();

RECT rc{};
TreeView_GetItemRect(
nmtvcd->nmcd.hdr.hwndFrom, reinterpret_cast<HTREEITEM>(nmtvcd->nmcd.dwItemSpec), &rc, TRUE);
InflateRect(&rc, 1, -1);

wil::unique_hbrush brush(CreateSolidBrush(nmtvcd->clrTextBk));
FillRect(nmtvcd->nmcd.hdc, &rc, brush.get());

const pfc::stringcvt::string_wide_from_utf8 text(draw_node->get_val());

SetTextColor(nmtvcd->nmcd.hdc, nmtvcd->clrText);
DrawTextEx(nmtvcd->nmcd.hdc, const_cast<wchar_t*>(text.get_ptr()), gsl::narrow<int>(text.length()), &rc,
DT_CENTER | DT_NOPREFIX | DT_SINGLELINE | DT_VCENTER, nullptr);

return CDRF_DODEFAULT;
}
}
Expand Down
4 changes: 1 addition & 3 deletions foo_uie_albumlist/prefs.cpp
Expand Up @@ -249,9 +249,7 @@ class items_colours_client : public cui::colours::client {
& ~(cui::colours::colour_flag_group_foreground | cui::colours::colour_flag_group_background);

if (cui::colours::is_dark_mode_active()) {
flags &= ~(cui::colours::colour_flag_selection_background
| cui::colours::colour_flag_inactive_selection_background
| cui::colours::colour_flag_active_item_frame);
flags &= ~(cui::colours::colour_flag_active_item_frame);
}

return flags;
Expand Down
10 changes: 5 additions & 5 deletions vcpkg.json
@@ -1,24 +1,24 @@
{
"name": "album-list-panel",
"version-string": "git",
"builtin-baseline": "03ca9b59af1506a86840e3a3a01a092f3333a29b",
"builtin-baseline": "a7b6122f6b6504d16d96117336a0562693579933",
"dependencies": ["fmt", "ms-gsl", "range-v3", "wil"],
"overrides": [
{
"name": "fmt",
"version": "8.1.0"
"version": "9.1.0#1"
},
{
"name": "ms-gsl",
"version-string": "3.1.0#1"
"version": "4.0.0"
},
{
"name": "range-v3",
"version-date": "2021-11-02"
"version": "0.12.0#1"
},
{
"name": "wil",
"version-date": "2021-12-25"
"version": "2023-02-02"
}
]
}