forked from OpenGamers/abaddon
preserve scroll position when loading history
it still jumps around a bit sometimes but its acceptable. hopefully there is a better solution
This commit is contained in:
parent
cf33d53809
commit
ad523f37c5
@ -1,7 +1,7 @@
|
|||||||
#include "chatmessage.hpp"
|
#include "chatmessage.hpp"
|
||||||
#include "chatlist.hpp"
|
#include "chatlist.hpp"
|
||||||
#include "../abaddon.hpp"
|
#include "abaddon.hpp"
|
||||||
#include "../constants.hpp"
|
#include "constants.hpp"
|
||||||
|
|
||||||
ChatList::ChatList() {
|
ChatList::ChatList() {
|
||||||
m_list.get_style_context()->add_class("messages");
|
m_list.get_style_context()->add_class("messages");
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#include <gtkmm.h>
|
#include <gtkmm.h>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "../discord/snowflake.hpp"
|
#include "discord/snowflake.hpp"
|
||||||
|
|
||||||
class ChatList : public Gtk::ScrolledWindow {
|
class ChatList : public Gtk::ScrolledWindow {
|
||||||
public:
|
public:
|
||||||
@ -101,6 +101,15 @@ inline void ChatList::SetMessages(Iter begin, Iter end) {
|
|||||||
|
|
||||||
template<typename Iter>
|
template<typename Iter>
|
||||||
inline void ChatList::PrependMessages(Iter begin, Iter end) {
|
inline void ChatList::PrependMessages(Iter begin, Iter end) {
|
||||||
|
const auto old_upper = get_vadjustment()->get_upper();
|
||||||
|
const auto old_value = get_vadjustment()->get_value();
|
||||||
for (Iter it = begin; it != end; it++)
|
for (Iter it = begin; it != end; it++)
|
||||||
ProcessNewMessage(*it, true);
|
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
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user