diff options
author | ouwou <26526779+ouwou@users.noreply.github.com> | 2021-07-20 17:55:03 -0400 |
---|---|---|
committer | ouwou <26526779+ouwou@users.noreply.github.com> | 2021-07-20 17:55:03 -0400 |
commit | a4d0cd9612dfa8b60fed63f1088b59b1762d217a (patch) | |
tree | d385506037a43855c4d62bfe8129a4d86f0a1872 /components | |
parent | d20a822fdbd52c316e3b33a8dbf8c72e564a7986 (diff) | |
download | abaddon-portaudio-a4d0cd9612dfa8b60fed63f1088b59b1762d217a.tar.gz abaddon-portaudio-a4d0cd9612dfa8b60fed63f1088b59b1762d217a.zip |
color nsfw channels
Diffstat (limited to 'components')
-rw-r--r-- | components/channels.cpp | 22 | ||||
-rw-r--r-- | components/channels.hpp | 13 |
2 files changed, 25 insertions, 10 deletions
diff --git a/components/channels.cpp b/components/channels.cpp index 37e7625..547232c 100644 --- a/components/channels.cpp +++ b/components/channels.cpp @@ -66,6 +66,7 @@ ChannelList::ChannelList() column->add_attribute(renderer->property_icon(), m_columns.m_icon); column->add_attribute(renderer->property_name(), m_columns.m_name); column->add_attribute(renderer->property_expanded(), m_columns.m_expanded); + column->add_attribute(renderer->property_nsfw(), m_columns.m_nsfw); m_view.append_column(*column); m_menu_guild_copy_id.signal_activate().connect([this] { @@ -191,15 +192,13 @@ void ChannelList::UpdateChannel(Snowflake id) { channel_row[m_columns.m_type] = RenderType::TextChannel; channel_row[m_columns.m_id] = channel->ID; channel_row[m_columns.m_name] = Glib::Markup::escape_text(*channel->Name); + channel_row[m_columns.m_nsfw] = channel->NSFW(); if (is_orphan) channel_row[m_columns.m_sort] = *channel->Position + OrphanChannelSortOffset; else channel_row[m_columns.m_sort] = *channel->Position; } -void ChannelList::UpdateCreateDMChannel(Snowflake id) { -} - void ChannelList::UpdateCreateChannel(Snowflake id) { const auto channel = Abaddon::Get().GetDiscordClient().GetChannel(id); if (!channel.has_value()) return; @@ -221,6 +220,7 @@ void ChannelList::UpdateCreateChannel(Snowflake id) { channel_row[m_columns.m_type] = RenderType::TextChannel; channel_row[m_columns.m_id] = channel->ID; channel_row[m_columns.m_name] = "#" + Glib::Markup::escape_text(*channel->Name); + channel_row[m_columns.m_nsfw] = channel->NSFW(); if (orphan) channel_row[m_columns.m_sort] = *channel->Position + OrphanChannelSortOffset; else @@ -293,6 +293,7 @@ Gtk::TreeModel::iterator ChannelList::AddGuild(const GuildData &guild) { channel_row[m_columns.m_id] = channel.ID; channel_row[m_columns.m_name] = "#" + Glib::Markup::escape_text(*channel.Name); channel_row[m_columns.m_sort] = *channel.Position + OrphanChannelSortOffset; + channel_row[m_columns.m_nsfw] = channel.NSFW(); } for (const auto &[category_id, channels] : categories) { @@ -312,6 +313,7 @@ Gtk::TreeModel::iterator ChannelList::AddGuild(const GuildData &guild) { channel_row[m_columns.m_id] = channel.ID; channel_row[m_columns.m_name] = "#" + Glib::Markup::escape_text(*channel.Name); channel_row[m_columns.m_sort] = *channel.Position; + channel_row[m_columns.m_nsfw] = channel.NSFW(); } } @@ -527,6 +529,7 @@ ChannelList::ModelColumns::ModelColumns() { add(m_name); add(m_icon); add(m_sort); + add(m_nsfw); add(m_expanded); } @@ -536,7 +539,8 @@ CellRendererChannels::CellRendererChannels() , m_property_type(*this, "render-type") , m_property_name(*this, "name") , m_property_pixbuf(*this, "pixbuf") - , m_property_expanded(*this, "expanded") { + , m_property_expanded(*this, "expanded") + , m_property_nsfw(*this, "nsfw") { property_mode() = Gtk::CELL_RENDERER_MODE_ACTIVATABLE; property_xpad() = 2; property_ypad() = 2; @@ -564,6 +568,10 @@ Glib::PropertyProxy<bool> CellRendererChannels::property_expanded() { return m_property_expanded.get_proxy(); } +Glib::PropertyProxy<bool> CellRendererChannels::property_nsfw() { + return m_property_nsfw.get_proxy(); +} + void CellRendererChannels::get_preferred_width_vfunc(Gtk::Widget &widget, int &minimum_width, int &natural_width) const { switch (m_property_type.get_value()) { case RenderType::Guild: @@ -794,7 +802,13 @@ void CellRendererChannels::render_vfunc_channel(const Cairo::RefPtr<Cairo::Conte Gdk::Rectangle text_cell_area(text_x, text_y, text_w, text_h); + const static auto nsfw_color = Gdk::RGBA(Abaddon::Get().GetSettings().GetNSFWChannelColor()); + if (m_property_nsfw.get_value()) + m_renderer_text.property_foreground_rgba() = nsfw_color; m_renderer_text.render(cr, widget, background_area, text_cell_area, flags); + // setting property_foreground_rgba() sets this to true which makes non-nsfw cells use the property too which is bad + // so unset it + m_renderer_text.property_foreground_set() = false; } // dm header diff --git a/components/channels.hpp b/components/channels.hpp index d3df2d5..2246b3b 100644 --- a/components/channels.hpp +++ b/components/channels.hpp @@ -12,7 +12,7 @@ constexpr static int GuildIconSize = 24; constexpr static int DMIconSize = 20; constexpr static int OrphanChannelSortOffset = -100; // forces orphan channels to the top of the list -enum class RenderType { +enum class RenderType : uint8_t { Guild, Category, TextChannel, @@ -30,6 +30,7 @@ public: Glib::PropertyProxy<Glib::ustring> property_name(); Glib::PropertyProxy<Glib::RefPtr<Gdk::Pixbuf>> property_icon(); Glib::PropertyProxy<bool> property_expanded(); + Glib::PropertyProxy<bool> property_nsfw(); protected: void get_preferred_width_vfunc(Gtk::Widget &widget, int &minimum_width, int &natural_width) const override; @@ -100,11 +101,11 @@ protected: private: Gtk::CellRendererText m_renderer_text; - Glib::Property<RenderType> m_property_type; - - Glib::Property<Glib::ustring> m_property_name; // guild - Glib::Property<Glib::RefPtr<Gdk::Pixbuf>> m_property_pixbuf; // guild + Glib::Property<RenderType> m_property_type; // all + Glib::Property<Glib::ustring> m_property_name; // all + Glib::Property<Glib::RefPtr<Gdk::Pixbuf>> m_property_pixbuf; // guild, dm Glib::Property<bool> m_property_expanded; // category + Glib::Property<bool> m_property_nsfw; // channel }; class ChannelList : public Gtk::ScrolledWindow { @@ -115,7 +116,6 @@ public: void UpdateRemoveGuild(Snowflake id); void UpdateRemoveChannel(Snowflake id); void UpdateChannel(Snowflake id); - void UpdateCreateDMChannel(Snowflake id); void UpdateCreateChannel(Snowflake id); void UpdateGuild(Snowflake id); @@ -133,6 +133,7 @@ protected: Gtk::TreeModelColumn<Glib::ustring> m_name; Gtk::TreeModelColumn<Glib::RefPtr<Gdk::Pixbuf>> m_icon; Gtk::TreeModelColumn<int64_t> m_sort; + Gtk::TreeModelColumn<bool> m_nsfw; // 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 |