Skip to content

Commit

Permalink
Make playlist view group level indentation configuration
Browse files Browse the repository at this point in the history
This makes indentation of grouping levels in the playlist view configurable. Indentation can now be enabled or disabled, and the amount of indentation overridden.

The default configuration matches the behaviour of Columns UI 2.0.0.
  • Loading branch information
reupen committed Jul 23, 2023
1 parent 947e5bc commit b9bf225
Show file tree
Hide file tree
Showing 10 changed files with 174 additions and 29 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Change log

## 2.1.0-beta.2

### Features

- Indentation of grouping levels in the playlist view was made configurable.
[[#773](https://github.com/reupen/columns_ui/pull/773)]

The default configuration matches the behaviour of Columns UI 2.0.0.

## 2.1.0-beta.1

### Features
Expand Down
30 changes: 19 additions & 11 deletions foo_ui_columns/config_host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,29 @@ INT_PTR PreferencesTabHelper::on_message(HWND wnd, UINT msg, WPARAM wp, LPARAM l
void PreferencesTabHelper::on_initdialog(HWND wnd)
{
m_wnd = wnd;
m_title_font = create_default_title_font();

const auto children = helpers::get_child_windows(wnd, [this, wnd](HWND wnd_child) {
return GetAncestor(wnd_child, GA_PARENT) == wnd
&& m_title_ctrl_ids.find(GetDlgCtrlID(wnd_child)) != m_title_ctrl_ids.end();
});
for (auto&& child : children) {
SetWindowFont(child, m_title_font, FALSE);
}
m_h1_font.reset(create_default_title_font());

if (!m_h2_ctrl_ids.empty())
m_h2_font.reset(create_default_ui_font(10));

const auto set_font = [wnd](auto&& font, auto&& ctrl_ids) {
const auto windows = helpers::get_child_windows(wnd, [wnd, &ctrl_ids](HWND wnd_child) {
return GetAncestor(wnd_child, GA_PARENT) == wnd && ctrl_ids.contains(GetDlgCtrlID(wnd_child));
});

for (auto&& child : windows) {
SetWindowFont(child, font.get(), FALSE);
}
};

set_font(m_h1_font, m_h1_ctrl_ids);
set_font(m_h2_font, m_h2_ctrl_ids);
}

void PreferencesTabHelper::on_ncdestroy()
{
DeleteFont(m_title_font);
m_title_font = nullptr;
m_h1_font.reset();
m_h2_font.reset();
m_wnd = nullptr;
}

Expand Down
13 changes: 10 additions & 3 deletions foo_ui_columns/config_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ namespace cui::prefs {

class PreferencesTabHelper {
public:
explicit PreferencesTabHelper(std::initializer_list<unsigned> title_ctrl_ids) : m_title_ctrl_ids(title_ctrl_ids) {}
explicit PreferencesTabHelper(
std::initializer_list<unsigned> h1_ctrl_ids, std::initializer_list<unsigned> h2_ctrl_ids = {})
: m_h1_ctrl_ids(h1_ctrl_ids)
, m_h2_ctrl_ids(h2_ctrl_ids)
{
}

HWND create(
HWND wnd, UINT id, std::function<INT_PTR(HWND wnd, UINT msg, WPARAM wp, LPARAM lp)> on_message_callback);
Expand All @@ -24,8 +29,10 @@ class PreferencesTabHelper {
void on_ncdestroy();

HWND m_wnd{};
HFONT m_title_font{};
std::set<unsigned> m_title_ctrl_ids;
wil::unique_hfont m_h1_font{};
wil::unique_hfont m_h2_font{};
std::set<unsigned> m_h1_ctrl_ids;
std::set<unsigned> m_h2_ctrl_ids;
std::function<INT_PTR(HWND wnd, UINT msg, WPARAM wp, LPARAM lp)> m_on_message_callback;
};

Expand Down
19 changes: 19 additions & 0 deletions foo_ui_columns/fcl_playlist_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "config.h"
#include "config_appearance.h"
#include "tab_dark_mode.h"
#include "ng_playlist/ng_playlist.h"

namespace cui {

Expand All @@ -25,6 +26,9 @@ class PlaylistViewAppearanceDataSet : public fcl::dataset {
/** Non-legacy */
identifier_vertical_item_padding,
identifier_vertical_item_padding_dpi,
identifier_indent_groups,
identifier_use_custom_group_indentation_amount,
identifier_custom_group_indentation_amount,
};
void get_name(pfc::string_base& p_out) const override { p_out = "Colours"; }
const GUID& get_group() const override { return fcl::groups::colours_and_fonts; }
Expand All @@ -40,6 +44,11 @@ class PlaylistViewAppearanceDataSet : public fcl::dataset {
fbh::fcl::Writer out(p_writer, p_abort);
out.write_item(identifier_vertical_item_padding, settings::playlist_view_item_padding.get_raw_value().value);
out.write_item(identifier_vertical_item_padding_dpi, settings::playlist_view_item_padding.get_raw_value().dpi);
out.write_item(identifier_indent_groups, panels::playlist_view::cfg_indent_groups);
out.write_item(
identifier_custom_group_indentation_amount, panels::playlist_view::cfg_custom_group_indentation_amount);
out.write_item(identifier_use_custom_group_indentation_amount,
panels::playlist_view::cfg_use_custom_group_indentation_amount);
}
void set_data(stream_reader* p_reader, size_t stream_size, uint32_t type, fcl::t_import_feedback& feedback,
abort_callback& p_abort) override
Expand Down Expand Up @@ -69,6 +78,15 @@ class PlaylistViewAppearanceDataSet : public fcl::dataset {
reader.read_item(item_padding.dpi);
item_padding_read = true;
break;
case identifier_indent_groups:
reader.read_item(panels::playlist_view::cfg_indent_groups);
break;
case identifier_use_custom_group_indentation_amount:
reader.read_item(panels::playlist_view::cfg_use_custom_group_indentation_amount);
break;
case identifier_custom_group_indentation_amount:
reader.read_item(panels::playlist_view::cfg_custom_group_indentation_amount);
break;
case colours_pview_scheme: {
int use_custom_colours{};
reader.read_item(use_custom_colours);
Expand Down Expand Up @@ -144,6 +162,7 @@ class PlaylistViewAppearanceDataSet : public fcl::dataset {

if (item_padding_read)
settings::playlist_view_item_padding = item_padding;

// refresh_all_playlist_views();
// pvt::ng_playlist_view_t::g_update_all_items();
}
Expand Down
9 changes: 8 additions & 1 deletion foo_ui_columns/foo_ui_columns.rc
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,14 @@ BEGIN
PUSHBUTTON "Move down",IDC_GROUP_DOWN,60,251,50,14
PUSHBUTTON "New...",IDC_GROUP_NEW,217,251,50,14
PUSHBUTTON "Delete",IDC_GROUP_DELETE,270,251,50,14
LTEXT "Groups",IDC_TITLE1,7,4,307,16
LTEXT "Grouping",IDC_TITLE1,7,4,307,16
CONTROL "Indent each level of grouping",IDC_INDENT_GROUPS,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,48,121,10
EDITTEXT IDC_INDENTATION_AMOUNT,142,64,40,14,ES_AUTOHSCROLL
CONTROL "",IDC_INDENTATION_AMOUNT_SPIN,"msctls_updown32",UDS_SETBUDDYINT | UDS_ALIGNRIGHT | UDS_AUTOBUDDY | UDS_ARROWKEYS | UDS_NOTHOUSANDS,194,65,12,10
LTEXT "px",-1,184,67,9,8
LTEXT "Groups",IDC_H2_TITLE,7,89,313,13
CONTROL "Use a custom indentation amount:",IDC_USE_CUSTOM_INDENTATION,
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,66,134,10
END

IDD_PREFS_FILTER_FIELDS DIALOGEX 0, 0, 327, 271
Expand Down
58 changes: 52 additions & 6 deletions foo_ui_columns/ng_playlist/ng_playlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ ConfigGroups g_groups(g_groups_guid);
cfg_bool cfg_artwork_reflection(g_artwork_reflection, false);

fbh::ConfigBool cfg_grouping(g_guid_grouping, true, [](auto&&) { button_items::ShowGroupsButton::s_on_change(); });
fbh::ConfigBool cfg_indent_groups({0x2e3d28c7, 0x7e99, 0x410f, {0xa5, 0x50, 0xd1, 0x5c, 0xc0, 0x6e, 0xa5, 0x51}}, true,
[](auto&&) { PlaylistView::s_on_indent_groups_change(); });
fbh::ConfigBool cfg_use_custom_group_indentation_amount(
{0x53cad633, 0xa735, 0x4880, {0x91, 0x45, 0xd9, 0x11, 0x98, 0x5e, 0x51, 0xe6}}, false,
[](auto&&) { PlaylistView::s_on_group_indentation_amount_change(); });
fbh::ConfigInt32DpiAware cfg_custom_group_indentation_amount(
{0x3d1b3bce, 0x25d2, 0x4dde, {0x8e, 0x99, 0x20, 0xfb, 0xc9, 0x6c, 0xbf, 0xec}}, 10);
fbh::ConfigBool cfg_show_artwork(
g_show_artwork_guid, false, [](auto&&) { button_items::ShowArtworkButton::s_on_change(); });
fbh::ConfigUint32DpiAware cfg_artwork_width(g_artwork_width_guid, 100);
Expand Down Expand Up @@ -261,11 +268,41 @@ void PlaylistView::refresh_columns()
set_columns(columns);
}

void PlaylistView::set_group_info_area_size()
{
ListView::set_group_info_area_size(cfg_artwork_width + get_artwork_left_right_padding() * 2,
cfg_artwork_width + (cfg_artwork_reflection ? (cfg_artwork_width * 3) / 11 : 0));
}

void PlaylistView::g_on_groups_change()
{
for (auto& window : g_windows)
window->on_groups_change();
}

void PlaylistView::s_on_indent_groups_change()
{
if (!cfg_grouping)
return;

for (const auto& window : g_windows) {
window->on_artwork_width_change();
window->set_group_level_indentation_enabled(cfg_indent_groups);
}
}

void PlaylistView::s_on_group_indentation_amount_change()
{
if (!cfg_grouping)
return;

for (const auto& window : g_windows) {
window->set_group_level_indentation_amount(cfg_use_custom_group_indentation_amount
? std::make_optional<int>(cfg_custom_group_indentation_amount)
: std::nullopt);
}
}

void PlaylistView::on_groups_change()
{
if (get_wnd()) {
Expand Down Expand Up @@ -319,16 +356,22 @@ void PlaylistView::g_on_alternate_selection_change()
for (auto& window : g_windows)
window->set_alternate_selection_model(cfg_alternative_sel != 0);
}

void PlaylistView::g_on_artwork_width_change(const PlaylistView* p_skip)
{
for (auto& window : g_windows) {
if (window != p_skip) {
window->flush_artwork_images();
window->set_group_info_area_size(
cfg_artwork_width, cfg_artwork_width + (cfg_artwork_reflection ? (cfg_artwork_width * 3) / 11 : 0));
window->on_artwork_width_change();
}
}
}

void PlaylistView::on_artwork_width_change()
{
flush_artwork_images();
set_group_info_area_size();
}

void PlaylistView::g_flush_artwork(bool b_redraw, const PlaylistView* p_skip)
{
for (auto& window : g_windows) {
Expand Down Expand Up @@ -694,9 +737,12 @@ void PlaylistView::sort_by_column_fb2k_v2(size_t column_index, bool b_descending
void PlaylistView::notify_on_initialisation()
{
set_use_dark_mode(colours::is_dark_mode_active());
set_group_level_indentation_enabled(false);
set_group_info_area_size(
cfg_artwork_width, cfg_artwork_width + (cfg_artwork_reflection ? (cfg_artwork_width * 3) / 11 : 0));
set_group_level_indentation_enabled(cfg_indent_groups);

if (cfg_use_custom_group_indentation_amount)
set_group_level_indentation_amount(cfg_custom_group_indentation_amount);

set_group_info_area_size();
set_show_group_info_area(cfg_show_artwork);
set_show_header(cfg_header != 0);
set_autosize(cfg_nohscroll != 0);
Expand Down
13 changes: 11 additions & 2 deletions foo_ui_columns/ng_playlist/ng_playlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ extern const GUID g_guid_items_font, g_guid_header_font, g_guid_group_header_fon
extern cfg_bool cfg_artwork_reflection;
extern fbh::ConfigUint32DpiAware cfg_artwork_width;
extern fbh::ConfigBool cfg_grouping;
extern fbh::ConfigBool cfg_indent_groups;
extern fbh::ConfigBool cfg_use_custom_group_indentation_amount;
extern fbh::ConfigInt32DpiAware cfg_custom_group_indentation_amount;
extern fbh::ConfigBool cfg_show_artwork;

wil::unique_hbitmap g_create_hbitmap_from_image(
Expand Down Expand Up @@ -323,6 +326,8 @@ class PlaylistView
inline static std::unique_ptr<uie::container_window_v3> s_message_window;

static void g_on_groups_change();
static void s_on_indent_groups_change();
static void s_on_group_indentation_amount_change();
static void g_on_columns_change();
static void g_on_column_widths_change(const PlaylistView* p_skip = nullptr);
static void g_update_all_items();
Expand Down Expand Up @@ -415,7 +420,7 @@ class PlaylistView

static void s_create_message_window();
static void s_destroy_message_window();
static auto get_artwork_left_right_padding() { return 5_spx; }
static auto get_artwork_left_right_padding() { return cfg_indent_groups ? 0 : 5_spx; }

virtual void flush_artwork_images()
{
Expand Down Expand Up @@ -540,7 +545,9 @@ class PlaylistView
const std::optional<uih::lv::SavedScrollPosition>& scroll_position = std::nullopt);
void refresh_groups(bool b_update_columns = false);
void refresh_columns();
void set_group_info_area_size();
void on_groups_change();
void on_artwork_width_change();
void on_columns_change();
void on_column_widths_change();
size_t column_index_display_to_actual(size_t display_index);
Expand Down Expand Up @@ -755,12 +762,14 @@ class GroupsPreferencesTab : public PreferencesTab {

private:
BOOL ConfigProc(HWND wnd, UINT msg, WPARAM wp, LPARAM lp);
void refresh_enabled_options() const;

void on_group_default_action(size_t index);

HWND m_wnd{};
bool m_initialised{};
GroupsListView m_groups_list_view{this};
prefs::PreferencesTabHelper m_helper{IDC_TITLE1};
prefs::PreferencesTabHelper m_helper{{{IDC_TITLE1}}, {{IDC_H2_TITLE}}};
};
} // namespace cui::panels::playlist_view

Expand Down
42 changes: 39 additions & 3 deletions foo_ui_columns/ng_playlist/ng_playlist_prefs_groups.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ BOOL GroupsPreferencesTab::ConfigProc(HWND wnd, UINT msg, WPARAM wp, LPARAM lp)
switch (msg) {
case WM_INITDIALOG: {
m_wnd = wnd;
m_groups_list_view.create(wnd, {7, 51, 313, 195}, true);
m_groups_list_view.create(wnd, {7, 105, 313, 140}, true);

LOGFONT font{};
GetObject(GetWindowFont(wnd), sizeof(font), &font);
Expand All @@ -89,15 +89,41 @@ BOOL GroupsPreferencesTab::ConfigProc(HWND wnd, UINT msg, WPARAM wp, LPARAM lp)
ShowWindow(m_groups_list_view.get_wnd(), SW_SHOWNORMAL);

Button_SetCheck(GetDlgItem(wnd, IDC_GROUPING), cfg_grouping ? BST_CHECKED : BST_UNCHECKED);
Button_SetCheck(GetDlgItem(wnd, IDC_INDENT_GROUPS), cfg_indent_groups ? BST_CHECKED : BST_UNCHECKED);
Button_SetCheck(GetDlgItem(wnd, IDC_USE_CUSTOM_INDENTATION),
cfg_use_custom_group_indentation_amount ? BST_CHECKED : BST_UNCHECKED);

SendDlgItemMessage(wnd, IDC_INDENTATION_AMOUNT_SPIN, UDM_SETRANGE32, 0, 256);
SendDlgItemMessage(wnd, IDC_INDENTATION_AMOUNT_SPIN, UDM_SETPOS32, NULL, cfg_custom_group_indentation_amount);

refresh_enabled_options();

m_initialised = true;
break;
}
case WM_COMMAND:
switch (wp) {
case IDC_GROUPING: {
cfg_grouping = Button_GetCheck(HWND(lp)) == BST_CHECKED;
cfg_grouping = Button_GetCheck(reinterpret_cast<HWND>(lp)) == BST_CHECKED;
refresh_enabled_options();
PlaylistView::g_on_groups_change();
} break;
break;
}
case IDC_INDENT_SUBGROUPS:

Check failure on line 112 in foo_ui_columns/ng_playlist/ng_playlist_prefs_groups.cpp

View workflow job for this annotation

GitHub Actions / build (win32, v143, release)

[C2065] 'IDC_INDENT_SUBGROUPS': undeclared identifier

'IDC_INDENT_SUBGROUPS': undeclared identifier case IDC_INDENT_SUBGROUPS: ^

Check failure on line 112 in foo_ui_columns/ng_playlist/ng_playlist_prefs_groups.cpp

View workflow job for this annotation

GitHub Actions / build (win32, v143, release)

[C2131] expression did not evaluate to a constant

expression did not evaluate to a constant

Check failure on line 112 in foo_ui_columns/ng_playlist/ng_playlist_prefs_groups.cpp

View workflow job for this annotation

GitHub Actions / build (win32, v143, release)

[C2051] case expression not constant

case expression not constant case IDC_INDENT_SUBGROUPS: ^

Check failure on line 112 in foo_ui_columns/ng_playlist/ng_playlist_prefs_groups.cpp

View workflow job for this annotation

GitHub Actions / build (x64, v143, release)

[C2065] 'IDC_INDENT_SUBGROUPS': undeclared identifier

'IDC_INDENT_SUBGROUPS': undeclared identifier case IDC_INDENT_SUBGROUPS: ^

Check failure on line 112 in foo_ui_columns/ng_playlist/ng_playlist_prefs_groups.cpp

View workflow job for this annotation

GitHub Actions / build (x64, v143, release)

[C2131] expression did not evaluate to a constant

expression did not evaluate to a constant

Check failure on line 112 in foo_ui_columns/ng_playlist/ng_playlist_prefs_groups.cpp

View workflow job for this annotation

GitHub Actions / build (x64, v143, release)

[C2051] case expression not constant

case expression not constant case IDC_INDENT_SUBGROUPS: ^
cfg_indent_groups = Button_GetCheck(reinterpret_cast<HWND>(lp)) == BST_CHECKED;
refresh_enabled_options();
break;
case IDC_USE_CUSTOM_INDENTATION:
cfg_use_custom_group_indentation_amount = Button_GetCheck(reinterpret_cast<HWND>(lp)) == BST_CHECKED;
refresh_enabled_options();
break;
case (EN_CHANGE << 16) | IDC_INDENTATION_AMOUNT:
if (m_initialised) {
cfg_custom_group_indentation_amount
= mmh::strtoul_n(uGetWindowText(reinterpret_cast<HWND>(lp)).get_ptr(), pfc_infinite);
PlaylistView::s_on_group_indentation_amount_change();
}
break;
case IDC_GROUP_UP: {
const auto index = m_groups_list_view.get_selected_item_single();
auto& groups = g_groups.get_groups();
Expand Down Expand Up @@ -168,6 +194,16 @@ BOOL GroupsPreferencesTab::ConfigProc(HWND wnd, UINT msg, WPARAM wp, LPARAM lp)
return 0;
}

void GroupsPreferencesTab::refresh_enabled_options() const
{
EnableWindow(GetDlgItem(m_wnd, IDC_INDENT_GROUPS), cfg_grouping);
EnableWindow(GetDlgItem(m_wnd, IDC_USE_CUSTOM_INDENTATION), cfg_grouping && cfg_indent_groups);
EnableWindow(GetDlgItem(m_wnd, IDC_INDENTATION_AMOUNT),
cfg_grouping && cfg_indent_groups && cfg_use_custom_group_indentation_amount);
EnableWindow(GetDlgItem(m_wnd, IDC_INDENTATION_AMOUNT_SPIN),
cfg_grouping && cfg_indent_groups && cfg_use_custom_group_indentation_amount);
}

void GroupsPreferencesTab::on_group_default_action(size_t index)
{
edit_view_param p;
Expand Down
Loading

0 comments on commit b9bf225

Please sign in to comment.