mirror of
https://github.com/uowuo/abaddon.git
synced 2025-03-04 03:03:16 -05:00
add stack with icon and grid for classic listing folder icon
This commit is contained in:
parent
b700aa85d8
commit
9131158cbb
@ -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 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 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);
|
||||
|
||||
if (i < guild_ids.size()) {
|
||||
widget.show();
|
||||
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 (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();
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -28,6 +28,7 @@ public:
|
||||
bool HideToTray;
|
||||
bool ShowDeletedIndicator;
|
||||
double FontScale;
|
||||
bool FolderIconOnly;
|
||||
|
||||
// [http]
|
||||
int CacheHTTPConcurrency;
|
||||
|
Loading…
Reference in New Issue
Block a user