Skip to content

Commit

Permalink
Add dark mode support to import and export configuration dialogue boxes
Browse files Browse the repository at this point in the history
This adds dark mode support to the import and export configuration dialogue boxes.

Some small improvements were made to the dialogue boxes at the same time.
  • Loading branch information
reupen committed Mar 21, 2023
1 parent 13db351 commit 8ef440a
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 22 deletions.
4 changes: 4 additions & 0 deletions foo_ui_columns/dark_mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,10 @@ COLORREF get_dark_colour(ColourID colour_id)
return get_base_dark_colour(DarkColourID::DARK_750);
case ColourID::TrackbarDisabledThumb:
return get_base_dark_colour(DarkColourID::DARK_400);
case ColourID::TreeViewBackground:
return get_base_dark_colour(DarkColourID::DARK_000);
case ColourID::TreeViewText:
return get_base_dark_colour(DarkColourID::DARK_999);
case ColourID::VolumeChannelTopEdge:
return get_base_dark_colour(DarkColourID::DARK_500);
case ColourID::VolumeChannelBottomAndRightEdge:
Expand Down
2 changes: 2 additions & 0 deletions foo_ui_columns/dark_mode.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ enum class ColourID {
TrackbarThumb,
TrackbarHotThumb,
TrackbarDisabledThumb,
TreeViewBackground,
TreeViewText,
VolumeChannelTopEdge,
VolumeChannelBottomAndRightEdge,
VolumePopupBackground,
Expand Down
15 changes: 15 additions & 0 deletions foo_ui_columns/dark_mode_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class DialogDarkModeHelper {
[[nodiscard]] std::optional<INT_PTR> handle_wm_notify(HWND wnd, LPNMHDR lpnm);
void on_dark_mode_change();
void apply_dark_mode_attributes();
void set_tree_view_theme(bool is_dark);
void set_window_theme(auto&& ids, const wchar_t* dark_class, bool is_dark);

HWND m_wnd{};
Expand All @@ -26,6 +27,19 @@ class DialogDarkModeHelper {
std::unique_ptr<EventToken> m_dark_mode_status_callback;
};

void DialogDarkModeHelper::set_tree_view_theme(bool is_dark)
{
if (!m_wnd)
return;

for (const auto id : m_config.tree_view_ids) {
const auto tree_view_wnd = GetDlgItem(m_wnd, id);
SetWindowTheme(tree_view_wnd, is_dark ? L"DarkMode_Explorer" : L"Explorer", nullptr);
TreeView_SetBkColor(tree_view_wnd, is_dark ? get_dark_colour(ColourID::TreeViewBackground) : -1);
TreeView_SetTextColor(tree_view_wnd, is_dark ? get_dark_colour(ColourID::TreeViewText) : -1);
}
}

void DialogDarkModeHelper::set_window_theme(auto&& ids, const wchar_t* dark_class, bool is_dark)
{
if (!m_wnd)
Expand All @@ -43,6 +57,7 @@ void DialogDarkModeHelper::apply_dark_mode_attributes()
set_window_theme(m_config.checkbox_ids, L"DarkMode_Explorer", is_dark);
set_window_theme(m_config.combo_box_ids, L"DarkMode_CFD", is_dark);
set_window_theme(m_config.edit_ids, L"DarkMode_CFD", is_dark);
set_tree_view_theme(is_dark);
}

std::optional<INT_PTR> DialogDarkModeHelper::handle_message(HWND wnd, UINT msg, WPARAM wp, LPARAM lp)
Expand Down
1 change: 1 addition & 0 deletions foo_ui_columns/dark_mode_dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ struct DialogDarkModeConfig {
std::unordered_set<int> checkbox_ids;
std::unordered_set<int> combo_box_ids;
std::unordered_set<int> edit_ids;
std::unordered_set<int> tree_view_ids;
};

INT_PTR modal_dialog_box(UINT resource_id, DialogDarkModeConfig dark_mode_config, HWND parent_window,
Expand Down
25 changes: 17 additions & 8 deletions foo_ui_columns/fcl.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "pch.h"
#include "fcl.h"

#include "dark_mode_dialog.h"
#include "main_window.h"

// {EBD87879-65A7-4242-821B-812AF9F68E8F}
Expand Down Expand Up @@ -65,11 +67,11 @@ class FCLDialog {
case WM_INITDIALOG: {
if (m_import)
SetWindowText(wnd, _T("Select settings to import"));
HWND wnd_tree = GetDlgItem(wnd, IDC_TREE);
HWND wnd_combo = m_import ? nullptr : GetDlgItem(wnd, IDC_DEST);
SetWindowLongPtr(wnd_tree, GWL_STYLE, GetWindowLongPtr(wnd_tree, GWL_STYLE) | TVS_CHECKBOXES);

uih::tree_view_set_explorer_theme(wnd_tree);
const HWND wnd_tree = GetDlgItem(wnd, IDC_TREE);
TreeView_SetExtendedStyle(wnd_tree, TVS_EX_DOUBLEBUFFER, TVS_EX_DOUBLEBUFFER);

const HWND wnd_combo = m_import ? nullptr : GetDlgItem(wnd, IDC_DEST);

if (wnd_combo) {
ComboBox_AddString(wnd_combo, L"Any foobar2000 installation");
Expand Down Expand Up @@ -351,9 +353,13 @@ void g_import_layout(HWND wnd, const char* path, bool quiet)

FCLDialog pFCLDialog(true, std::move(datasetsguids));
if (!quiet) {
const auto dialog_result = uih::modal_dialog_box(IDD_FCL_IMPORT, wnd, [&pFCLDialog](auto&&... args) {
return pFCLDialog.FCLDialogProc(std::forward<decltype(args)>(args)...);
});
const cui::dark::DialogDarkModeConfig dark_mode_config{
.button_ids = {IDOK, IDCANCEL}, .tree_view_ids = {IDC_TREE}};

const auto dialog_result
= modal_dialog_box(IDD_FCL_IMPORT, dark_mode_config, wnd, [&pFCLDialog](auto&&... args) {
return pFCLDialog.FCLDialogProc(std::forward<decltype(args)>(args)...);
});

if (dialog_result <= 0)
throw exception_aborted();
Expand Down Expand Up @@ -427,7 +433,10 @@ void g_export_layout(HWND wnd, pfc::string8 path, bool is_quiet)
{
FCLDialog pFCLDialog;
if (!is_quiet) {
const auto dialog_result = uih::modal_dialog_box(IDD_FCL_EXPORT, wnd,
const cui::dark::DialogDarkModeConfig dark_mode_config{
.button_ids = {IDOK, IDCANCEL}, .combo_box_ids = {IDC_DEST}, .tree_view_ids = {IDC_TREE}};

const auto dialog_result = modal_dialog_box(IDD_FCL_EXPORT, dark_mode_config, wnd,
[&pFCLDialog](auto&&... args) { return pFCLDialog.FCLDialogProc(std::forward<decltype(args)>(args)...); });

if (dialog_result <= 0)
Expand Down
30 changes: 16 additions & 14 deletions foo_ui_columns/foo_ui_columns.rc
Original file line number Diff line number Diff line change
Expand Up @@ -325,14 +325,15 @@ BEGIN
PUSHBUTTON "Cancel",IDCANCEL,204,207,50,14
END

IDD_FCL_IMPORT DIALOGEX 0, 0, 242, 115
IDD_FCL_IMPORT DIALOGEX 0, 0, 242, 172
STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
CAPTION "Select settings to export"
CAPTION "Import settings"
FONT 8, "Segoe UI", 400, 0, 0x0
BEGIN
PUSHBUTTON "OK",IDOK,133,94,50,14
CONTROL "",IDC_TREE,"SysTreeView32",TVS_HASBUTTONS | TVS_FULLROWSELECT | WS_BORDER | WS_HSCROLL | WS_TABSTOP,7,7,228,84
PUSHBUTTON "Cancel",IDCANCEL,185,94,50,14
LTEXT "Which settings should be imported?",IDC_STATIC,7,7,115,8
CONTROL "",IDC_TREE,"SysTreeView32",TVS_HASBUTTONS | TVS_CHECKBOXES | TVS_FULLROWSELECT | WS_BORDER | WS_HSCROLL | WS_TABSTOP,7,19,228,116
PUSHBUTTON "OK",IDOK,131,151,50,14
PUSHBUTTON "Cancel",IDCANCEL,185,151,50,14
END

IDD_RESULTS DIALOGEX 0, 0, 457, 239
Expand All @@ -345,16 +346,17 @@ BEGIN
LTEXT "Static",IDC_CAPTION,6,8,445,10
END

IDD_FCL_EXPORT DIALOGEX 0, 0, 242, 133
IDD_FCL_EXPORT DIALOGEX 0, 0, 242, 200
STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
CAPTION "Select settings to export"
CAPTION "Export settings"
FONT 8, "Segoe UI", 400, 0, 0x0
BEGIN
PUSHBUTTON "OK",IDOK,133,112,50,14
CONTROL "",IDC_TREE,"SysTreeView32",TVS_HASBUTTONS | TVS_FULLROWSELECT | WS_BORDER | WS_HSCROLL | WS_TABSTOP,7,7,228,84
PUSHBUTTON "Cancel",IDCANCEL,185,112,50,14
LTEXT "Target:",IDC_STATIC,7,98,25,8
COMBOBOX IDC_DEST,42,95,193,12,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
LTEXT "Which settings should be exported?",IDC_STATIC,7,7,115,8
CONTROL "",IDC_TREE,"SysTreeView32",TVS_HASBUTTONS | TVS_CHECKBOXES | TVS_FULLROWSELECT | WS_BORDER | WS_HSCROLL | WS_TABSTOP,7,19,228,116
LTEXT "Target",IDC_STATIC,7,142,25,8
COMBOBOX IDC_DEST,7,153,228,12,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
PUSHBUTTON "OK",IDOK,131,179,50,14
PUSHBUTTON "Cancel",IDCANCEL,185,179,50,14
END

IDD_EDIT_GROUP DIALOGEX 0, 0, 320, 154
Expand Down Expand Up @@ -831,7 +833,7 @@ BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 235
TOPMARGIN, 7
BOTTOMMARGIN, 108
BOTTOMMARGIN, 165
END

IDD_RESULTS, DIALOG
Expand All @@ -847,7 +849,7 @@ BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 235
TOPMARGIN, 7
BOTTOMMARGIN, 126
BOTTOMMARGIN, 193
END

IDD_EDIT_GROUP, DIALOG
Expand Down

0 comments on commit 8ef440a

Please sign in to comment.