Commit d7f2eb82 authored by Mohammed Sadiq's avatar Mohammed Sadiq
Browse files

chat-view: Add a button to scroll to bottom

Fixes #468
parent a2f6272e
Pipeline #64308 passed with stages
in 10 minutes and 42 seconds
......@@ -44,6 +44,7 @@ struct _ChattyChatView
GtkWidget *empty_label0;
GtkWidget *empty_label1;
GtkWidget *empty_label2;
GtkWidget *scroll_down_button;
GtkTextBuffer *message_input_buffer;
GtkAdjustment *vadjustment;
......@@ -328,6 +329,15 @@ chatty_update_typing_status (ChattyChatView *self)
chatty_chat_set_typing (self->chat, !empty);
}
static void
chat_view_scroll_down_clicked_cb (ChattyChatView *self)
{
g_assert (CHATTY_IS_CHAT_VIEW (self));
gtk_adjustment_set_value (self->vadjustment,
gtk_adjustment_get_upper (self->vadjustment));
}
static void
chat_view_edge_overshot_cb (ChattyChatView *self,
GtkPositionType pos)
......@@ -736,6 +746,7 @@ chat_view_message_input_changed_cb (ChattyChatView *self)
chatty_check_for_emoticon (self);
}
static void chat_view_adjustment_value_changed_cb (ChattyChatView *self);
static void
list_page_size_changed_cb (ChattyChatView *self)
{
......@@ -755,6 +766,20 @@ list_page_size_changed_cb (ChattyChatView *self)
gtk_adjustment_set_value (self->vadjustment, upper);
self->first_scroll_to_bottom = TRUE;
chat_view_adjustment_value_changed_cb (self);
}
static void
chat_view_adjustment_value_changed_cb (ChattyChatView *self)
{
gdouble value, upper, page_size;
upper = gtk_adjustment_get_upper (self->vadjustment);
value = gtk_adjustment_get_value (self->vadjustment);
page_size = gtk_adjustment_get_page_size (self->vadjustment);
gtk_widget_set_visible (self->scroll_down_button,
(upper - value) > page_size + 1.0);
}
static void
......@@ -785,6 +810,8 @@ chat_view_adjustment_changed_cb (GtkAdjustment *adjustment,
gtk_widget_set_visible (vscroll, FALSE);
gtk_widget_show (self->encrypt_icon);
}
chat_view_adjustment_value_changed_cb (self);
}
static void
......@@ -874,6 +901,7 @@ chatty_chat_view_class_init (ChattyChatViewClass *klass)
"/sm/puri/Chatty/"
"ui/chatty-chat-view.ui");
gtk_widget_class_bind_template_child (widget_class, ChattyChatView, scroll_down_button);
gtk_widget_class_bind_template_child (widget_class, ChattyChatView, message_list);
gtk_widget_class_bind_template_child (widget_class, ChattyChatView, loading_spinner);
gtk_widget_class_bind_template_child (widget_class, ChattyChatView, typing_revealer);
......@@ -891,6 +919,7 @@ chatty_chat_view_class_init (ChattyChatViewClass *klass)
gtk_widget_class_bind_template_child (widget_class, ChattyChatView, message_input_buffer);
gtk_widget_class_bind_template_child (widget_class, ChattyChatView, vadjustment);
gtk_widget_class_bind_template_callback (widget_class, chat_view_scroll_down_clicked_cb);
gtk_widget_class_bind_template_callback (widget_class, chat_view_edge_overshot_cb);
gtk_widget_class_bind_template_callback (widget_class, chat_view_typing_indicator_draw_cb);
gtk_widget_class_bind_template_callback (widget_class, chat_view_input_focus_in_cb);
......@@ -900,6 +929,7 @@ chatty_chat_view_class_init (ChattyChatViewClass *klass)
gtk_widget_class_bind_template_callback (widget_class, chat_view_input_key_pressed_cb);
gtk_widget_class_bind_template_callback (widget_class, chat_view_message_input_changed_cb);
gtk_widget_class_bind_template_callback (widget_class, list_page_size_changed_cb);
gtk_widget_class_bind_template_callback (widget_class, chat_view_adjustment_value_changed_cb);
}
static void
......@@ -984,6 +1014,7 @@ chatty_chat_view_set_chat (ChattyChatView *self,
chat_encrypt_changed_cb (self);
chat_buddy_typing_changed_cb (self);
chatty_chat_view_update (self);
chat_view_adjustment_value_changed_cb (self);
}
ChattyChat *
......
......@@ -6,54 +6,89 @@
<property name="orientation">vertical</property>
<child>
<object class="GtkScrolledWindow" id="scroll">
<object class="GtkOverlay">
<property name="visible">True</property>
<property name="hscrollbar-policy">never</property>
<property name="vadjustment">vadjustment</property>
<signal name="edge-overshot" handler="chat_view_edge_overshot_cb" swapped="yes"/>
<style>
<class name="view"/>
</style>
<child>
<object class="HdyClamp">
<child type="overlay">
<object class="GtkRevealer">
<property name="visible">True</property>
<property name="margin-start">12</property>
<property name="margin-end">12</property>
<property name="reveal-child">True</property>
<property name="halign">end</property>
<property name="valign">end</property>
<child>
<object class="GtkBox" id="property">
<property name="visible">True</property>
<property name="orientation">vertical</property>
<!-- Loading spinner -->
<object class="GtkButton" id="scroll_down_button">
<property name="visible">False</property>
<property name="margin-bottom">18</property>
<property name="margin-end">18</property>
<signal name="clicked" handler="chat_view_scroll_down_clicked_cb" swapped="yes"/>
<style>
<class name="osd"/>
<class name="circular"/>
<class name="suggested-action"/>
</style>
<child>
<object class="GtkSpinner" id="loading_spinner">
<object class="GtkImage">
<property name="visible">True</property>
<property name="margin-top">6</property>
<property name="margin-bottom">6</property>
<property name="icon-name">go-bottom-symbolic</property>
<property name="width-request">32</property>
<property name="height-request">32</property>
</object>
</child>
</object>
</child>
</object>
</child>
<!-- Chat message list -->
<child>
<object class="GtkScrolledWindow" id="scroll">
<property name="visible">True</property>
<property name="hscrollbar-policy">never</property>
<property name="vadjustment">vadjustment</property>
<signal name="edge-overshot" handler="chat_view_edge_overshot_cb" swapped="yes"/>
<style>
<class name="view"/>
</style>
<child>
<object class="HdyClamp">
<property name="visible">True</property>
<property name="margin-start">12</property>
<property name="margin-end">12</property>
<child>
<object class="GtkListBox" id="message_list">
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="vexpand">True</property>
<property name="valign">end</property>
<property name="selection-mode">none</property>
</object>
</child>
<property name="orientation">vertical</property>
<!-- Typing indicator -->
<child>
<object class="GtkRevealer" id="typing_revealer">
<property name="visible">True</property>
<!-- Loading spinner -->
<child>
<object class="GtkSpinner" id="loading_spinner">
<property name="visible">True</property>
<property name="margin-top">6</property>
<property name="margin-bottom">6</property>
</object>
</child>
<!-- Chat message list -->
<child>
<object class="GtkListBox" id="message_list">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="vexpand">True</property>
<property name="valign">end</property>
<property name="selection-mode">none</property>
</object>
</child>
<!-- Typing indicator -->
<child>
<object class="GtkDrawingArea" id="typing_indicator">
<object class="GtkRevealer" id="typing_revealer">
<property name="visible">True</property>
<property name="width-request">60</property>
<property name="height-request">40</property>
<signal name="draw" handler="chat_view_typing_indicator_draw_cb" swapped="yes"/>
<child>
<object class="GtkDrawingArea" id="typing_indicator">
<property name="visible">True</property>
<property name="width-request">60</property>
<property name="height-request">40</property>
<signal name="draw" handler="chat_view_typing_indicator_draw_cb" swapped="yes"/>
</object>
</child>
</object>
</child>
</object>
......@@ -184,6 +219,7 @@
<object class="GtkAdjustment" id="vadjustment">
<signal name="notify::page-size" handler="list_page_size_changed_cb" swapped="yes"/>
<signal name="value-changed" handler="chat_view_adjustment_value_changed_cb" swapped="yes"/>
</object>
<!-- Disclaimer label -->
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment