diff options
author | ouwou <26526779+ouwou@users.noreply.github.com> | 2024-01-08 20:53:40 -0500 |
---|---|---|
committer | ouwou <26526779+ouwou@users.noreply.github.com> | 2024-01-08 20:53:40 -0500 |
commit | 9131158cbbf5800dd103d5b5fbfff96384352c77 (patch) | |
tree | 631e9120b5e0108b7169300760b8d21cb3bcee9c | |
parent | b700aa85d82b0af391e9fef84202488a779bc304 (diff) | |
download | abaddon-portaudio-9131158cbbf5800dd103d5b5fbfff96384352c77.tar.gz abaddon-portaudio-9131158cbbf5800dd103d5b5fbfff96384352c77.zip |
add stack with icon and grid for classic listing folder icon
-rw-r--r-- | src/components/channellist/classic/guildlistfolderitem.cpp | 71 | ||||
-rw-r--r-- | src/components/channellist/classic/guildlistfolderitem.hpp | 13 | ||||
-rw-r--r-- | src/settings.cpp | 1 | ||||
-rw-r--r-- | src/settings.hpp | 1 |
4 files changed, 56 insertions, 30 deletions
diff --git a/src/components/channellist/classic/guildlistfolderitem.cpp b/src/components/channellist/classic/guildlistfolderitem.cpp index b6e49f1..e60bd5f 100644 --- a/src/components/channellist/classic/guildlistfolderitem.cpp +++ b/src/components/channellist/classic/guildlistfolderitem.cpp @@ -6,37 +6,31 @@ const int FolderGridButtonSize = 48; const int FolderGridImageSize = 24; -class GuildListFolderButton : public Gtk::Grid { -public: - GuildListFolderButton() { - set_size_request(FolderGridButtonSize, FolderGridButtonSize); - } +GuildListFolderButton::GuildListFolderButton() { + set_size_request(FolderGridButtonSize, FolderGridButtonSize); +} + +void GuildListFolderButton::SetGuilds(const std::vector<Snowflake> &guild_ids) { + for (int y = 0; y < 2; y++) { + for (int x = 0; x < 2; x++) { + const size_t i = y * 2 + x; + auto &widget = m_images[x][y]; + widget.property_pixbuf() = Abaddon::Get().GetImageManager().GetPlaceholder(FolderGridImageSize); + attach(widget, x, y, 1, 1); - void SetGuilds(const std::vector<Snowflake> &guild_ids) { - for (int y = 0; y < 2; y++) { - for (int x = 0; x < 2; x++) { - const size_t i = y * 2 + x; - auto &widget = m_images[x][y]; - widget.property_pixbuf() = Abaddon::Get().GetImageManager().GetPlaceholder(FolderGridImageSize); - attach(widget, x, y, 1, 1); - - if (i < guild_ids.size()) { - widget.show(); - - if (const auto guild = Abaddon::Get().GetDiscordClient().GetGuild(guild_ids[i]); guild.has_value()) { - const auto cb = [&widget](const Glib::RefPtr<Gdk::Pixbuf> &pb) { - widget.property_pixbuf() = pb->scale_simple(FolderGridImageSize, FolderGridImageSize, Gdk::INTERP_BILINEAR); - }; - Abaddon::Get().GetImageManager().LoadFromURL(guild->GetIconURL("png", "32"), sigc::track_obj(cb, *this)); - } + if (i < guild_ids.size()) { + widget.show(); + + if (const auto guild = Abaddon::Get().GetDiscordClient().GetGuild(guild_ids[i]); guild.has_value()) { + const auto cb = [&widget](const Glib::RefPtr<Gdk::Pixbuf> &pb) { + widget.property_pixbuf() = pb->scale_simple(FolderGridImageSize, FolderGridImageSize, Gdk::INTERP_BILINEAR); + }; + Abaddon::Get().GetImageManager().LoadFromURL(guild->GetIconURL("png", "32"), sigc::track_obj(cb, *this)); } } } } - -private: - Gtk::Image m_images[2][2]; -}; +} GuildListFolderItem::GuildListFolderItem(const UserSettingsGuildFoldersEntry &folder) { get_style_context()->add_class("classic-guild-folder"); @@ -49,17 +43,34 @@ GuildListFolderItem::GuildListFolderItem(const UserSettingsGuildFoldersEntry &fo m_ev.signal_button_press_event().connect([this](GdkEventButton *event) -> bool { if (event->type == GDK_BUTTON_PRESS && event->button == GDK_BUTTON_PRIMARY) { m_revealer.set_reveal_child(!m_revealer.get_reveal_child()); + if (!Abaddon::Get().GetSettings().FolderIconOnly) { + if (m_revealer.get_reveal_child()) { + m_stack.set_visible_child("icon", Gtk::STACK_TRANSITION_TYPE_SLIDE_DOWN); + } else { + m_stack.set_visible_child("grid", Gtk::STACK_TRANSITION_TYPE_SLIDE_UP); + } + } } + return false; }); - auto *btn = Gtk::make_managed<GuildListFolderButton>(); - btn->SetGuilds(folder.GuildIDs); - m_ev.add(*btn); + m_grid.SetGuilds(folder.GuildIDs); + m_grid.show(); + + m_icon.property_icon_name() = "folder-symbolic"; + m_icon.property_icon_size() = Gtk::ICON_SIZE_DND; + m_icon.show(); + + m_stack.add(m_grid, "grid"); + m_stack.add(m_icon, "icon"); + m_stack.set_visible_child(Abaddon::Get().GetSettings().FolderIconOnly ? "icon" : "grid"); + m_stack.show(); + + m_ev.add(m_stack); add(m_ev); add(m_revealer); - btn->show(); m_ev.show(); m_revealer.show(); m_box.show(); diff --git a/src/components/channellist/classic/guildlistfolderitem.hpp b/src/components/channellist/classic/guildlistfolderitem.hpp index 460fd07..6a9fb50 100644 --- a/src/components/channellist/classic/guildlistfolderitem.hpp +++ b/src/components/channellist/classic/guildlistfolderitem.hpp @@ -9,6 +9,15 @@ class GuildListGuildItem; +class GuildListFolderButton : public Gtk::Grid { +public: + GuildListFolderButton(); + void SetGuilds(const std::vector<Snowflake> &guild_ids); + +private: + Gtk::Image m_images[2][2]; +}; + class GuildListFolderItem : public Gtk::VBox { public: GuildListFolderItem(const UserSettingsGuildFoldersEntry &folder); @@ -16,6 +25,10 @@ public: void AddGuildWidget(GuildListGuildItem *widget); private: + Gtk::Stack m_stack; + GuildListFolderButton m_grid; + Gtk::Image m_icon; + Gtk::EventBox m_ev; Gtk::Image m_image; Gtk::Revealer m_revealer; diff --git a/src/settings.cpp b/src/settings.cpp index 23b2b89..6b051e7 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -96,6 +96,7 @@ void SettingsManager::DefineSettings() { AddSetting("gui", "hide_to_try", false, &Settings::HideToTray); AddSetting("gui", "show_deleted_indicator", true, &Settings::ShowDeletedIndicator); AddSetting("gui", "font_scale", -1.0, &Settings::FontScale); + AddSetting("gui", "folder_icon_only", false, &Settings::FolderIconOnly); AddSetting("http", "concurrent", 20, &Settings::CacheHTTPConcurrency); AddSetting("http", "user_agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36"s, &Settings::UserAgent); diff --git a/src/settings.hpp b/src/settings.hpp index be9660e..e508270 100644 --- a/src/settings.hpp +++ b/src/settings.hpp @@ -28,6 +28,7 @@ public: bool HideToTray; bool ShowDeletedIndicator; double FontScale; + bool FolderIconOnly; // [http] int CacheHTTPConcurrency; |