Private
Public Access
1
0

reorg: message layout becomes interface for other types of chat items (like date)

This commit is contained in:
2025-05-03 22:12:26 -07:00
parent 518608a04e
commit 21c926456d
5 changed files with 142 additions and 103 deletions

View File

@@ -4,7 +4,7 @@ using Gee;
private class MessageDrawingArea : Widget
{
private SortedSet<Message> _messages = new TreeSet<Message>();
private ArrayList<MessageLayout> _message_layouts = new ArrayList<MessageLayout>();
private ArrayList<ChatItemLayout> _chat_items = new ArrayList<ChatItemLayout>();
private const float bubble_padding = 10.0f;
private const float bubble_margin = 18.0f;
@@ -31,8 +31,8 @@ private class MessageDrawingArea : Widget
} else {
// compute total message layout height
float total_height = 0.0f;
_message_layouts.foreach((message_layout) => {
total_height += message_layout.get_height() + bubble_padding;
_chat_items.foreach((chat_item) => {
total_height += chat_item.get_height() + bubble_padding;
return true;
});
@@ -52,9 +52,9 @@ private class MessageDrawingArea : Widget
public override void snapshot(Snapshot snapshot) {
var container_width = get_width();
float y_offset = 0;
_message_layouts.foreach((message_layout) => {
var message_width = message_layout.get_width();
var message_height = message_layout.get_height();
_chat_items.foreach((chat_item) => {
var message_width = chat_item.get_width();
var message_height = chat_item.get_height();
snapshot.save();
@@ -63,14 +63,14 @@ private class MessageDrawingArea : Widget
// Translate to the correct position
snapshot.translate(Graphene.Point() {
x = (message_layout.from_me ? (container_width - message_width - bubble_margin) : bubble_margin),
x = (chat_item.from_me ? (container_width - message_width - bubble_margin) : bubble_margin),
y = y_offset
});
// Undo the y-axis flip, origin is top left
snapshot.translate(Graphene.Point() { x = 0, y = -message_height });
message_layout.draw(snapshot);
chat_item.draw(snapshot);
snapshot.restore();
y_offset -= message_height + bubble_padding;
@@ -83,14 +83,17 @@ private class MessageDrawingArea : Widget
var container_width = get_width();
float max_width = container_width * 0.90f;
_message_layouts.clear();
_messages
.order_by((a, b) => (int)b.date - (int)a.date) // reverse order
.foreach((message) => {
_message_layouts.add(new MessageLayout(message, this, max_width));
return true;
});
_chat_items.clear();
var sorted_messages = _messages
.order_by((a, b) => (int)b.date - (int)a.date); // reverse order
sorted_messages.foreach((message) => {
_chat_items.add(new TextBubbleLayout(message, this, max_width));
return true;
});
queue_draw();
queue_resize();
}