From a83e9c01a6bc652e26d9c9e5b20668a94727975f Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Thu, 31 Mar 2022 03:21:07 -0400 Subject: improve scrolling up behavior when loading new messages --- src/components/chatlist.hpp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'src/components/chatlist.hpp') diff --git a/src/components/chatlist.hpp b/src/components/chatlist.hpp index e5afb80..783474a 100644 --- a/src/components/chatlist.hpp +++ b/src/components/chatlist.hpp @@ -2,6 +2,7 @@ #include #include #include +#include "discord/message.hpp" #include "discord/snowflake.hpp" class ChatList : public Gtk::ScrolledWindow { @@ -25,7 +26,7 @@ public: void ActuallyRemoveMessage(Snowflake id); // perhaps not the best method name private: - void OnScrollEdgeOvershot(Gtk::PositionType pos); + void OnUpperAdjustmentChanged(); void ScrollToBottom(); void RemoveMessageAndHeader(Gtk::Widget *widget); @@ -52,6 +53,10 @@ private: bool m_separate_all = false; + Glib::Timer m_history_timer; + bool m_needs_upper_adjustment = false; + double m_old_upper = -1.0; + public: // these are all forwarded by the parent using type_signal_action_message_edit = sigc::signal; @@ -88,6 +93,7 @@ private: template inline void ChatList::SetMessages(Iter begin, Iter end) { + m_needs_upper_adjustment = false; Clear(); m_num_rows = 0; m_num_messages = 0; @@ -101,15 +107,7 @@ inline void ChatList::SetMessages(Iter begin, Iter end) { template inline void ChatList::PrependMessages(Iter begin, Iter end) { - const auto old_upper = get_vadjustment()->get_upper(); - const auto old_value = get_vadjustment()->get_value(); + m_needs_upper_adjustment = true; for (Iter it = begin; it != end; it++) ProcessNewMessage(*it, true); - // force everything to process before getting new values - while (Gtk::Main::events_pending()) - Gtk::Main::iteration(); - const auto new_upper = get_vadjustment()->get_upper(); - if (old_value == 0.0 && (new_upper - old_upper) > 0.0) - get_vadjustment()->set_value(new_upper - old_upper); - // this isn't ideal } -- cgit v1.2.3