initial working better channel list

This commit is contained in:
ouwou 2021-07-03 19:06:49 -04:00
parent cbc65bf766
commit 66e2311bf0
2 changed files with 423 additions and 826 deletions

File diff suppressed because it is too large Load Diff

View File

@ -10,110 +10,74 @@
static const constexpr int ChannelEmojiSize = 16; static const constexpr int ChannelEmojiSize = 16;
class ChannelListRow : public Gtk::ListBoxRow { enum class RenderType {
public: Guild,
bool IsUserCollapsed; Category,
Snowflake ID; TextChannel,
std::vector<ChannelListRow *> Children;
ChannelListRow *Parent = nullptr;
virtual void Collapse();
virtual void Expand();
static void MakeReadOnly(Gtk::TextView *tv);
}; };
class ChannelListRowDMHeader : public ChannelListRow { class CellRendererChannels : public Gtk::CellRenderer {
public: public:
ChannelListRowDMHeader(); CellRendererChannels();
virtual ~CellRendererChannels();
Glib::PropertyProxy<RenderType> property_type();
Glib::PropertyProxy<Glib::ustring> property_name();
Glib::PropertyProxy<Glib::RefPtr<Gdk::Pixbuf>> property_icon();
Glib::PropertyProxy<bool> property_expanded();
protected: protected:
Gtk::EventBox *m_ev; void get_preferred_width_vfunc(Gtk::Widget &widget, int &minimum_width, int &natural_width) const override;
Gtk::Box *m_box; void get_preferred_width_for_height_vfunc(Gtk::Widget &widget, int height, int &minimum_width, int &natural_width) const override;
Gtk::Label *m_lbl; void get_preferred_height_vfunc(Gtk::Widget &widget, int &minimum_height, int &natural_height) const override;
}; void get_preferred_height_for_width_vfunc(Gtk::Widget &widget, int width, int &minimum_height, int &natural_height) const override;
void render_vfunc(const Cairo::RefPtr<Cairo::Context> &cr,
Gtk::Widget &widget,
const Gdk::Rectangle &background_area,
const Gdk::Rectangle &cell_area,
Gtk::CellRendererState flags) override;
class StatusIndicator; // guild functions
class ChannelListRowDMChannel : public ChannelListRow { void get_preferred_width_vfunc_guild(Gtk::Widget &widget, int &minimum_width, int &natural_width) const;
public: void get_preferred_width_for_height_vfunc_guild(Gtk::Widget &widget, int height, int &minimum_width, int &natural_width) const;
ChannelListRowDMChannel(const ChannelData *data); void get_preferred_height_vfunc_guild(Gtk::Widget &widget, int &minimum_height, int &natural_height) const;
void get_preferred_height_for_width_vfunc_guild(Gtk::Widget &widget, int width, int &minimum_height, int &natural_height) const;
void render_vfunc_guild(const Cairo::RefPtr<Cairo::Context> &cr,
Gtk::Widget &widget,
const Gdk::Rectangle &background_area,
const Gdk::Rectangle &cell_area,
Gtk::CellRendererState flags);
protected: // category
Gtk::EventBox *m_ev; void get_preferred_width_vfunc_category(Gtk::Widget &widget, int &minimum_width, int &natural_width) const;
Gtk::Box *m_box; void get_preferred_width_for_height_vfunc_category(Gtk::Widget &widget, int height, int &minimum_width, int &natural_width) const;
StatusIndicator *m_status = nullptr; void get_preferred_height_vfunc_category(Gtk::Widget &widget, int &minimum_height, int &natural_height) const;
Gtk::TextView *m_lbl; void get_preferred_height_for_width_vfunc_category(Gtk::Widget &widget, int width, int &minimum_height, int &natural_height) const;
Gtk::Image *m_icon = nullptr; void render_vfunc_category(const Cairo::RefPtr<Cairo::Context> &cr,
Gtk::Widget &widget,
const Gdk::Rectangle &background_area,
const Gdk::Rectangle &cell_area,
Gtk::CellRendererState flags);
Gtk::Menu m_menu; // text channel
Gtk::MenuItem *m_menu_close; // leave if group void get_preferred_width_vfunc_channel(Gtk::Widget &widget, int &minimum_width, int &natural_width) const;
Gtk::MenuItem *m_menu_copy_id; void get_preferred_width_for_height_vfunc_channel(Gtk::Widget &widget, int height, int &minimum_width, int &natural_width) const;
}; void get_preferred_height_vfunc_channel(Gtk::Widget &widget, int &minimum_height, int &natural_height) const;
void get_preferred_height_for_width_vfunc_channel(Gtk::Widget &widget, int width, int &minimum_height, int &natural_height) const;
class ChannelListRowGuild : public ChannelListRow { void render_vfunc_channel(const Cairo::RefPtr<Cairo::Context> &cr,
public: Gtk::Widget &widget,
ChannelListRowGuild(const GuildData *data); const Gdk::Rectangle &background_area,
const Gdk::Rectangle &cell_area,
int GuildIndex; Gtk::CellRendererState flags);
protected:
Gtk::EventBox *m_ev;
Gtk::Box *m_box;
Gtk::TextView *m_lbl;
Gtk::Image *m_icon;
Gtk::Menu m_menu;
Gtk::MenuItem *m_menu_copyid;
Gtk::MenuItem *m_menu_leave;
Gtk::MenuItem *m_menu_settings;
private: private:
typedef sigc::signal<void> type_signal_copy_id; Gtk::CellRendererText m_renderer_text;
typedef sigc::signal<void> type_signal_leave;
typedef sigc::signal<void> type_signal_settings;
type_signal_copy_id m_signal_copy_id; Glib::Property<RenderType> m_property_type;
type_signal_leave m_signal_leave;
type_signal_settings m_signal_settings;
public: Glib::Property<Glib::ustring> m_property_name; // guild
type_signal_copy_id signal_copy_id(); Glib::Property<Glib::RefPtr<Gdk::Pixbuf>> m_property_pixbuf; // guild
type_signal_leave signal_leave(); Glib::Property<bool> m_property_expanded; // category
type_signal_settings signal_settings();
};
class ChannelListRowCategory : public ChannelListRow {
public:
ChannelListRowCategory(const ChannelData *data);
virtual void Collapse();
virtual void Expand();
protected:
Gtk::EventBox *m_ev;
Gtk::Box *m_box;
Gtk::TextView *m_lbl;
Gtk::Arrow *m_arrow;
Gtk::Menu m_menu;
Gtk::MenuItem *m_menu_copyid;
private:
typedef sigc::signal<void> type_signal_copy_id;
type_signal_copy_id m_signal_copy_id;
public:
type_signal_copy_id signal_copy_id();
};
class ChannelListRowChannel : public ChannelListRow {
public:
ChannelListRowChannel(const ChannelData *data);
private:
static Gtk::Menu *m_menu;
static bool m_menu_init;
}; };
class ChannelList { class ChannelList {
@ -132,36 +96,28 @@ public:
void SetActiveChannel(Snowflake id); void SetActiveChannel(Snowflake id);
protected: protected:
Gtk::ListBox *m_list;
Gtk::ScrolledWindow *m_main; Gtk::ScrolledWindow *m_main;
Gtk::TreeView m_view;
ChannelListRowDMHeader *m_dm_header_row = nullptr; class ModelColumns : public Gtk::TreeModel::ColumnRecord {
public:
ModelColumns();
void CollapseRow(ChannelListRow *row); Gtk::TreeModelColumn<RenderType> m_type;
void ExpandRow(ChannelListRow *row); Gtk::TreeModelColumn<uint64_t> m_id;
void DeleteRow(ChannelListRow *row); Gtk::TreeModelColumn<Glib::ustring> m_name;
Gtk::TreeModelColumn<Glib::RefPtr<Gdk::Pixbuf>> m_icon;
Gtk::TreeModelColumn<int> m_sort;
// Gtk::CellRenderer's property_is_expanded only works how i want it to if it has children
// because otherwise it doesnt count as an "expander" (property_is_expander)
// so this solution will have to do which i hate but the alternative is adding invisible children
// to all categories without children and having a filter model but that sounds worse
// of course its a lot better than the absolute travesty i had before
Gtk::TreeModelColumn<bool> m_expanded;
};
void UpdateChannelCategory(Snowflake id); ModelColumns m_columns;
Glib::RefPtr<Gtk::TreeStore> m_model;
void on_row_activated(Gtk::ListBoxRow *row);
int m_guild_count;
void OnMenuCopyID(Snowflake id);
void OnGuildMenuLeave(Snowflake id);
void OnGuildMenuSettings(Snowflake id);
Gtk::Menu m_channel_menu;
Gtk::MenuItem *m_channel_menu_copyid;
// i would use one map but in really old guilds there can be a channel w/ same id as the guild so this hacky shit has to do
std::unordered_map<Snowflake, ChannelListRow *> m_guild_id_to_row;
std::unordered_map<Snowflake, ChannelListRow *> m_id_to_row;
void InsertGuildAt(Snowflake id, int pos);
void AddPrivateChannels();
void CheckBumpDM(Snowflake channel_id);
public: public:
typedef sigc::signal<void, Snowflake> type_signal_action_channel_item_select; typedef sigc::signal<void, Snowflake> type_signal_action_channel_item_select;