diff options
author | Lucas Fryzek <lucas.fryzek@fryzekconcepts.com> | 2024-10-06 11:04:12 +0100 |
---|---|---|
committer | Lucas Fryzek <lucas.fryzek@fryzekconcepts.com> | 2024-10-06 11:04:12 +0100 |
commit | cb2ff26daacde20e9d347bc0e720ed27ea2bea52 (patch) | |
tree | 3e0b23db908c1e3d2a4fecd0741f086d379389d6 | |
parent | c21a3405a455f65f13beb5a72af87cc717a13aea (diff) |
chat: Add autoscroll to bottom button
-rw-r--r-- | src/chat.py | 17 | ||||
-rw-r--r-- | src/gtk/chat.ui | 32 |
2 files changed, 46 insertions, 3 deletions
diff --git a/src/chat.py b/src/chat.py index bb498c3..3c61b00 100644 --- a/src/chat.py +++ b/src/chat.py @@ -43,6 +43,7 @@ class WeegtkChat(Adw.Bin): window = Gtk.Template.Child() messages = Gtk.Template.Child() text_entry = Gtk.Template.Child() + scroll_button_revealer = Gtk.Template.Child() def __init__(self, data=None, **kwargs): super().__init__(**kwargs) @@ -62,30 +63,40 @@ class WeegtkChat(Adw.Bin): self.color = Color(config.color_options(), False) self.auto_scroll = True - self.sticky = True + self.set_sticky(True) adj = self.window.get_vadjustment() adj.connect("value-changed", self.scroll_changes) adj.connect("notify::upper", self.upper_notify) + # TODO figure out why style is not being taken from ui file + self.add_css_class("view") + def is_at_bottom(self): adj = self.window.get_vadjustment() return (adj.get_value() + adj.get_page_size()) == adj.get_upper() + def set_sticky(self, is_sticky): + if not is_sticky: + self.scroll_button_revealer.set_visible(True) + self.scroll_button_revealer.set_reveal_child(not is_sticky) + self.sticky = is_sticky + def scroll_changes(self, *args): is_at_bottom = self.is_at_bottom() if self.auto_scroll: if is_at_bottom: self.auto_scroll = False - self.sticky = True + self.set_sticky(True) else: self.scroll_bottom() else: - self.sticky = is_at_bottom + self.set_sticky(is_at_bottom) def upper_notify(self, *args): if self.sticky: self.scroll_bottom() + @Gtk.Template.Callback() def scroll_bottom(self, *args): n_items = self.model.get_n_items() self.auto_scroll = True diff --git a/src/gtk/chat.ui b/src/gtk/chat.ui index a768f5c..65765e5 100644 --- a/src/gtk/chat.ui +++ b/src/gtk/chat.ui @@ -48,6 +48,38 @@ <property name="maximum-size">750</property> <property name="tightening-threshold">500</property> <property name="child"> + <object class="GtkOverlay" id="content"> + <child type="overlay"> + <object class="GtkRevealer" id="scroll_button_revealer"> + <property name="visible">False</property> + <property name="transition_type">crossfade</property> + <property name="valign">end</property> + <property name="halign">end</property> + <property name="margin-end">5</property> + <property name="margin-bottom">5</property> + <child> + <object class="GtkButton" id="scroll_button"> + <property name="icon-name">go-bottom-symbolic</property> + <property name="tooltip-text" translatable="yes">Scroll to Bottom</property> + <signal name="clicked" handler="scroll_bottom"/> + <style> + <class name="osd"/> + <class name="circular"/> + <class name="overlaid"/> + </style> + </object> + </child> + </object> + </child> + </object> + </property> + </object> + </child> + <child> + <object class="AdwClamp"> + <property name="maximum-size">750</property> + <property name="tightening-threshold">500</property> + <property name="child"> <object class="GtkBox"> <property name="margin-top">5</property> <property name="margin-bottom">5</property> |