Skip to content

Commit

Permalink
Make playlist view group level indentation configurable
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 a8aacd5
Show file tree
Hide file tree
Showing 27 changed files with 192 additions and 48 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
2 changes: 1 addition & 1 deletion foo_ui_columns/config_artwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ static class TabArtwork : public PreferencesTab {

private:
bool m_initialising{false};
cui::prefs::PreferencesTabHelper m_helper{IDC_TITLE1, IDC_TITLE2};
cui::prefs::PreferencesTabHelper m_helper{{IDC_TITLE1, IDC_TITLE2}};
} g_tab_artwork;

PreferencesTab* g_get_tab_artwork()
Expand Down
2 changes: 1 addition & 1 deletion foo_ui_columns/config_columns_v2.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class TabColumns : public PreferencesTab {
HWND m_wnd_child{nullptr};
HWND m_wnd{nullptr};
std::unique_ptr<ColumnTab> m_child;
cui::prefs::PreferencesTabHelper m_helper{IDC_TITLE1};
cui::prefs::PreferencesTabHelper m_helper{{IDC_TITLE1}};
ColumnList m_columns;
ColumnsListView m_columns_list_view{this};
bool initialising{false};
Expand Down
6 changes: 3 additions & 3 deletions foo_ui_columns/config_filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ static class TabFilterFields : public PreferencesTab {
}

private:
cui::prefs::PreferencesTabHelper m_helper{IDC_TITLE1};
cui::prefs::PreferencesTabHelper m_helper{{IDC_TITLE1}};
bool m_initialising{false};
} g_tab_filter_fields;

Expand Down Expand Up @@ -297,7 +297,7 @@ static class TabFilterAppearance : public PreferencesTab {
}

private:
cui::prefs::PreferencesTabHelper m_helper{IDC_TITLE1};
cui::prefs::PreferencesTabHelper m_helper{{IDC_TITLE1}};
bool m_initialising{false};
} g_tab_filter_appearance;

Expand Down Expand Up @@ -407,7 +407,7 @@ static class TabFilterBehaviour : public PreferencesTab {
}

private:
cui::prefs::PreferencesTabHelper m_helper{IDC_TITLE1};
cui::prefs::PreferencesTabHelper m_helper{{IDC_TITLE1}};
bool m_initialising{false};
} g_tab_filter_behaviour;

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
12 changes: 9 additions & 3 deletions foo_ui_columns/config_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ namespace cui::prefs {

class PreferencesTabHelper {
public:
explicit PreferencesTabHelper(std::initializer_list<unsigned> title_ctrl_ids) : m_title_ctrl_ids(title_ctrl_ids) {}
PreferencesTabHelper(std::set<unsigned> h1_ctrl_ids, std::set<unsigned> h2_ctrl_ids = {})
: m_h1_ctrl_ids(std::move(h1_ctrl_ids))
, m_h2_ctrl_ids(std::move(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 +28,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
Loading

0 comments on commit a8aacd5

Please sign in to comment.