Skip to content

Commit

Permalink
Merge pull request #112 from reupen/show-groups-button-2
Browse files Browse the repository at this point in the history
Add 'Show groups' state support to the buttons toolbar
  • Loading branch information
reupen authored May 2, 2018
2 parents 17c0f53 + 2822bc8 commit b4e757b
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 43 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

* Right-clicking in empty space in the playlist view now correctly deselects all items and always displays a context menu. [[#75](https://github.com/reupen/columns_ui/issues/75)]

* Added a main menu command to toggle whether playlist groups are shown. [[#100](https://github.com/reupen/columns_ui/issues/100)]
* Added a main menu command to toggle whether playlist groups are shown. (Additionally, if the menu item is added as button, the button will become pressed when the 'Show groups' is turned on.) [[#100](https://github.com/reupen/columns_ui/issues/100), [#112](https://github.com/reupen/columns_ui/issues/112)]

### Filter panel

Expand Down
2 changes: 1 addition & 1 deletion fbh
Submodule fbh updated 1 files
+27 −0 config_var.h
11 changes: 11 additions & 0 deletions foo_ui_columns/button_items.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "stdafx.h"

#include "button_items.h"

namespace cui::button_items {

static uie::button_factory<LiveLayoutEditingButton> live_layout_editing_button_factory;

static uie::button_factory<ShowGroupsButton> show_groups_button_factory;

} // namespace cui::button_items
57 changes: 57 additions & 0 deletions foo_ui_columns/button_items.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#pragma once
#include "menu_items.h"
#include "layout.h"
#include "ng_playlist/ng_playlist.h"

namespace cui::button_items {

template <class ButtonArgs>
class PushButton : public uie::button {
public:
static void s_on_change()
{
for (auto&& button : m_buttons) {
for (auto&& callback : button->m_callbacks) {
callback->on_button_state_change(s_get_button_state());
}
}
}
static unsigned s_get_button_state()
{
return (ButtonArgs::state() ? uie::BUTTON_STATE_PRESSED : 0) | uie::BUTTON_STATE_DEFAULT;
}
PushButton() { m_buttons.emplace_back(this); }
~PushButton() { m_buttons.erase(std::remove(m_buttons.begin(), m_buttons.end(), this), m_buttons.end()); }

private:
const GUID& get_item_guid() const override { return ButtonArgs::id; }
HBITMAP get_item_bitmap(unsigned, COLORREF, uie::t_mask&, COLORREF&, HBITMAP&) const override { return nullptr; }
unsigned get_button_state() const override { return s_get_button_state(); }
void register_callback(uie::button_callback& p_callback) override { m_callbacks.emplace_back(&p_callback); }
void deregister_callback(uie::button_callback& p_callback) override
{
m_callbacks.erase(std::remove(m_callbacks.begin(), m_callbacks.end(), &p_callback), m_callbacks.end());
}

static std::vector<PushButton<ButtonArgs>*> m_buttons;
std::vector<uie::button_callback*> m_callbacks;
};

template <class ButtonArgs>
std::vector<PushButton<ButtonArgs>*> PushButton<ButtonArgs>::m_buttons;

struct LiveLayoutEditingButtonArgs {
static bool state() { return g_layout_window.get_layout_editing_active(); }
static constexpr GUID id = main_menu::commands::toggle_live_editing_id;
};

using LiveLayoutEditingButton = PushButton<LiveLayoutEditingButtonArgs>;

struct ShowGroupsButtonArgs {
static bool state() { return pvt::cfg_grouping; }
static constexpr GUID id = main_menu::commands::show_groups_id;
};

using ShowGroupsButton = PushButton<ShowGroupsButtonArgs>;

} // namespace cui::button_items
2 changes: 2 additions & 0 deletions foo_ui_columns/foo_ui_columns.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@
<ClCompile Include=".\playlist_view_tfhook.cpp" />
<ClCompile Include=".\prefs_utils.cpp" />
<ClCompile Include=".\setup_dialog.cpp" />
<ClCompile Include="button_items.cpp" />
<ClCompile Include="file_info_reader.cpp" />
<ClCompile Include="legacy_config.cpp" />
<ClCompile Include="ng_playlist\ng_playlist.cpp">
Expand Down Expand Up @@ -454,6 +455,7 @@
<ClInclude Include=".\item_properties.h" />
<ClInclude Include=".\menu_helpers.h" />
<ClInclude Include=".\mw_drop_target.h" />
<ClInclude Include="button_items.h" />
<ClInclude Include="playlist_view_tfhooks.h" />
<ClInclude Include=".\setup_dialog.h" />
<ClInclude Include="file_info_reader.h" />
Expand Down
6 changes: 6 additions & 0 deletions foo_ui_columns/foo_ui_columns.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,9 @@
<ClCompile Include="replaygain_mode.cpp">
<Filter>Toolbars</Filter>
</ClCompile>
<ClCompile Include="button_items.cpp">
<Filter>Misc</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="ng_playlist\ng_playlist.h">
Expand Down Expand Up @@ -617,6 +620,9 @@
<Filter>Panels\Playlist view</Filter>
</ClInclude>
<ClInclude Include="drop_down_list_toolbar.h" />
<ClInclude Include="button_items.h">
<Filter>Misc</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include=".\buttons2.bmp">
Expand Down
41 changes: 2 additions & 39 deletions foo_ui_columns/menu_items.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "layout.h"
#include "ng_playlist/ng_playlist.h"
#include "main_window.h"
#include "button_items.h"

namespace cui::main_menu {

Expand Down Expand Up @@ -40,44 +41,6 @@ static mainmenu_group_factory g_mainmenu_group_view_layout_presets_part(

namespace commands {

class LiveLayoutEditingButton : public uie::button {
public:
static void s_on_layout_editing_enabled_change()
{
for (auto&& button : m_buttons) {
for (auto&& callback : button->m_callbacks) {
callback->on_button_state_change(s_get_button_state());
}
}
}
static unsigned s_get_button_state()
{
return (g_layout_window.get_layout_editing_active() ? uie::BUTTON_STATE_PRESSED : 0)
| uie::BUTTON_STATE_DEFAULT;
}
LiveLayoutEditingButton() { m_buttons.emplace_back(this); }
~LiveLayoutEditingButton()
{
m_buttons.erase(std::remove(m_buttons.begin(), m_buttons.end(), this), m_buttons.end());
}

private:
const GUID& get_item_guid() const override { return toggle_live_editing_id; }
HBITMAP get_item_bitmap(unsigned, COLORREF, uie::t_mask&, COLORREF&, HBITMAP&) const override { return nullptr; }
unsigned get_button_state() const override { return s_get_button_state(); }
void register_callback(uie::button_callback& p_callback) override { m_callbacks.emplace_back(&p_callback); };
void deregister_callback(uie::button_callback& p_callback) override
{
m_callbacks.erase(std::remove(m_callbacks.begin(), m_callbacks.end(), &p_callback), m_callbacks.end());
};

static std::vector<LiveLayoutEditingButton*> m_buttons;
std::vector<uie::button_callback*> m_callbacks;
};

std::vector<LiveLayoutEditingButton*> LiveLayoutEditingButton::m_buttons;
static uie::button_factory<LiveLayoutEditingButton> live_layout_editing_button_factory;

static const MainMenuCommand activate_now_playing{activate_now_playing_id, "Activate now playing",
"Activates the currently playing item.", [] { playlist_manager::get()->highlight_playing_item(); }};

Expand Down Expand Up @@ -128,7 +91,7 @@ static const MainMenuCommand live_editing{toggle_live_editing_id, "Live editing"
[] {
bool val = !g_layout_window.get_layout_editing_active();
g_layout_window.set_layout_editing_active(val);
LiveLayoutEditingButton::s_on_layout_editing_enabled_change();
button_items::LiveLayoutEditingButton::s_on_change();
},
[] { return g_layout_window.get_layout_editing_active(); }};

Expand Down
6 changes: 5 additions & 1 deletion foo_ui_columns/ng_playlist/ng_playlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "../config_columns_v2.h"
#include "../playlist_item_helpers.h"
#include "../playlist_view_tfhooks.h"
#include "../button_items.h"

namespace artwork_panel {
// extern cfg_string cfg_front;
Expand Down Expand Up @@ -41,7 +42,9 @@ ng_playlist_view_t::ng_global_mesage_window ng_playlist_view_t::g_global_mesage_
cfg_groups_t g_groups(g_groups_guid);

cfg_bool cfg_show_artwork(g_show_artwork_guid, false), cfg_artwork_reflection(g_artwork_reflection, true),
cfg_artwork_lowpriority(g_artwork_lowpriority, true), cfg_grouping(g_guid_grouping, true);
cfg_artwork_lowpriority(g_artwork_lowpriority, true);

fbh::ConfigBool cfg_grouping(g_guid_grouping, true, [](auto&&) { cui::button_items::ShowGroupsButton::s_on_change(); });
fbh::ConfigUint32DpiAware cfg_artwork_width(g_artwork_width_guid, 100);

void cfg_groups_t::swap(t_size index1, t_size index2)
Expand Down Expand Up @@ -216,6 +219,7 @@ void ng_playlist_view_t::refresh_columns()
}
set_columns(columns);
}

void ng_playlist_view_t::g_on_groups_change()
{
for (auto& window : g_windows)
Expand Down
3 changes: 2 additions & 1 deletion foo_ui_columns/ng_playlist/ng_playlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
namespace pvt {
extern const GUID g_guid_items_font, g_guid_header_font, g_guid_group_header_font;

extern cfg_bool cfg_show_artwork, cfg_artwork_reflection, cfg_artwork_lowpriority, cfg_grouping;
extern cfg_bool cfg_show_artwork, cfg_artwork_reflection, cfg_artwork_lowpriority;
extern fbh::ConfigUint32DpiAware cfg_artwork_width;
extern fbh::ConfigBool cfg_grouping;

HBITMAP g_create_hbitmap_from_image(Gdiplus::Bitmap& bm, t_size& cx, t_size& cy, COLORREF cr_back, bool b_reflection);
HBITMAP g_create_hbitmap_from_data(
Expand Down

0 comments on commit b4e757b

Please sign in to comment.