mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Merge branch 'drunkonhotcoco/issue_1204_chat_scroll_fix' into 'master'
Added fix for Issue #1204 - Incorrect scrolling when switching between filtered tabs See merge request veloren/veloren!2514
This commit is contained in:
commit
f6782e21b8
@ -163,6 +163,8 @@ pub struct State {
|
|||||||
tabs_last_hover_pulse: Option<f32>,
|
tabs_last_hover_pulse: Option<f32>,
|
||||||
// last chat_tab (used to see if chat tab has been changed)
|
// last chat_tab (used to see if chat tab has been changed)
|
||||||
prev_chat_tab: Option<ChatTab>,
|
prev_chat_tab: Option<ChatTab>,
|
||||||
|
//whether or not a scroll action is queued
|
||||||
|
scroll_next: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum Event {
|
pub enum Event {
|
||||||
@ -194,6 +196,7 @@ impl<'a> Widget for Chat<'a> {
|
|||||||
ids: Ids::new(id_gen),
|
ids: Ids::new(id_gen),
|
||||||
tabs_last_hover_pulse: None,
|
tabs_last_hover_pulse: None,
|
||||||
prev_chat_tab: None,
|
prev_chat_tab: None,
|
||||||
|
scroll_next: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -213,15 +216,23 @@ impl<'a> Widget for Chat<'a> {
|
|||||||
|
|
||||||
let chat_tabs = &chat_settings.chat_tabs;
|
let chat_tabs = &chat_settings.chat_tabs;
|
||||||
let current_chat_tab = chat_settings.chat_tab_index.and_then(|i| chat_tabs.get(i));
|
let current_chat_tab = chat_settings.chat_tab_index.and_then(|i| chat_tabs.get(i));
|
||||||
|
// Maintain scrolling //
|
||||||
// Maintain scrolling.
|
|
||||||
if !self.new_messages.is_empty() {
|
if !self.new_messages.is_empty() {
|
||||||
|
//new messages - update chat w/ them & scroll down
|
||||||
state.update(|s| s.messages.extend(self.new_messages.drain(..)));
|
state.update(|s| s.messages.extend(self.new_messages.drain(..)));
|
||||||
ui.scroll_widget(state.ids.message_box, [0.0, std::f64::MAX]);
|
ui.scroll_widget(state.ids.message_box, [0.0, std::f64::MAX]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Trigger scroll event queued from previous frame
|
||||||
|
if state.scroll_next {
|
||||||
|
ui.scroll_widget(state.ids.message_box, [0.0, std::f64::MAX]);
|
||||||
|
state.update(|s| s.scroll_next = false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Queue scroll event if switching from a different tab
|
||||||
if current_chat_tab != state.prev_chat_tab.as_ref() {
|
if current_chat_tab != state.prev_chat_tab.as_ref() {
|
||||||
state.update(|s| s.prev_chat_tab = current_chat_tab.cloned());
|
state.update(|s| s.prev_chat_tab = current_chat_tab.cloned());
|
||||||
ui.scroll_widget(state.ids.message_box, [0.0, std::f64::MAX]);
|
state.update(|s| s.scroll_next = true); //make scroll happen only once any filters to the messages have already been applied
|
||||||
}
|
}
|
||||||
|
|
||||||
// Empty old messages
|
// Empty old messages
|
||||||
|
Loading…
Reference in New Issue
Block a user