diff options
author | ouwou <26526779+ouwou@users.noreply.github.com> | 2023-11-03 01:00:29 -0400 |
---|---|---|
committer | ouwou <26526779+ouwou@users.noreply.github.com> | 2023-11-03 01:00:29 -0400 |
commit | 8bd628c1776c20dbf41d2fb18f6204c4a398da0e (patch) | |
tree | 1708a94ab49a4463ecf959ccc523b0f3aa798214 /src/components/channellist/classic/guildlistfolderitem.cpp | |
parent | 6fc3624e3bfc1ae2f30a922c3a86533e50e99def (diff) | |
download | abaddon-portaudio-8bd628c1776c20dbf41d2fb18f6204c4a398da0e.tar.gz abaddon-portaudio-8bd628c1776c20dbf41d2fb18f6204c4a398da0e.zip |
show guild icon previews as grid in folder button
Diffstat (limited to 'src/components/channellist/classic/guildlistfolderitem.cpp')
-rw-r--r-- | src/components/channellist/classic/guildlistfolderitem.cpp | 53 |
1 files changed, 50 insertions, 3 deletions
diff --git a/src/components/channellist/classic/guildlistfolderitem.cpp b/src/components/channellist/classic/guildlistfolderitem.cpp index aead848..acf1a2c 100644 --- a/src/components/channellist/classic/guildlistfolderitem.cpp +++ b/src/components/channellist/classic/guildlistfolderitem.cpp @@ -1,7 +1,46 @@ #include "guildlistfolderitem.hpp" #include "guildlistguilditem.hpp" -GuildListFolderItem::GuildListFolderItem() { +// doing my best to copy discord here + +const int FolderGridButtonSize = 48; +const int FolderGridImageSize = 24; + +class GuildListFolderButton : public Gtk::Grid { +public: + GuildListFolderButton() { + set_size_request(FolderGridButtonSize, FolderGridButtonSize); + } + + 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)); + } + } + } + } + } + +private: + Gtk::Image m_images[2][2]; +}; + +GuildListFolderItem::GuildListFolderItem(const UserSettingsGuildFoldersEntry &folder) { + get_style_context()->add_class("classic-guild-folder"); + m_revealer.add(m_box); m_revealer.set_reveal_child(true); @@ -14,10 +53,18 @@ GuildListFolderItem::GuildListFolderItem() { return false; }); - m_ev.add(m_image); + auto *btn = Gtk::make_managed<GuildListFolderButton>(); + btn->SetGuilds(folder.GuildIDs); + m_ev.add(*btn); add(m_ev); add(m_revealer); - show_all_children(); + + btn->show(); + m_ev.show(); + m_revealer.show(); + m_box.show(); + m_image.show(); + show(); } void GuildListFolderItem::AddGuildWidget(GuildListGuildItem *widget) { |