Now About Social Code
aboutsummaryrefslogtreecommitdiff
path: root/src/chat.py
diff options
context:
space:
mode:
authorLucas Fryzek <lucas.fryzek@fryzekconcepts.com>2024-10-06 11:04:12 +0100
committerLucas Fryzek <lucas.fryzek@fryzekconcepts.com>2024-10-06 11:04:12 +0100
commitcb2ff26daacde20e9d347bc0e720ed27ea2bea52 (patch)
tree3e0b23db908c1e3d2a4fecd0741f086d379389d6 /src/chat.py
parentc21a3405a455f65f13beb5a72af87cc717a13aea (diff)
chat: Add autoscroll to bottom button
Diffstat (limited to 'src/chat.py')
-rw-r--r--src/chat.py17
1 files changed, 14 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