reorg: message-list -> transcript
This commit is contained in:
96
src/transcript/layouts/text-bubble-layout.vala
Normal file
96
src/transcript/layouts/text-bubble-layout.vala
Normal file
@@ -0,0 +1,96 @@
|
||||
using Gtk;
|
||||
|
||||
private class TextBubbleLayout : BubbleLayout
|
||||
{
|
||||
public Message message;
|
||||
private Pango.Layout layout;
|
||||
|
||||
public TextBubbleLayout(Message message, Widget parent, float max_width) {
|
||||
base(parent, max_width);
|
||||
|
||||
this.from_me = message.from_me;
|
||||
this.message = message;
|
||||
|
||||
layout = parent.create_pango_layout(message.text);
|
||||
|
||||
// Get the system font settings
|
||||
var settings = Gtk.Settings.get_default();
|
||||
var font_name = settings.gtk_font_name;
|
||||
|
||||
// Create font description from system font
|
||||
var font_desc = Pango.FontDescription.from_string(font_name);
|
||||
|
||||
var size = font_desc.get_size();
|
||||
font_desc.set_size((int)(size));
|
||||
layout.set_font_description(font_desc);
|
||||
|
||||
// Set max width
|
||||
layout.set_width((int)text_available_width * Pango.SCALE);
|
||||
}
|
||||
|
||||
private float text_available_width {
|
||||
get {
|
||||
return max_width - text_x_offset - constants.text_padding;
|
||||
}
|
||||
}
|
||||
|
||||
private float text_x_offset {
|
||||
get {
|
||||
return from_me ? constants.text_padding : constants.tail_width + constants.text_padding;
|
||||
}
|
||||
}
|
||||
|
||||
private float text_x_padding {
|
||||
get {
|
||||
// Opposite of text_x_offset
|
||||
return from_me ? constants.tail_width + constants.text_padding : constants.text_padding;
|
||||
}
|
||||
}
|
||||
|
||||
private Gdk.RGBA background_color {
|
||||
get {
|
||||
return from_me ? parent.get_color() : Gdk.RGBA() {
|
||||
red = 1.0f,
|
||||
green = 1.0f,
|
||||
blue = 1.0f,
|
||||
alpha = 0.08f
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public override float get_height() {
|
||||
Pango.Rectangle ink_rect, logical_rect;
|
||||
layout.get_pixel_extents(out ink_rect, out logical_rect);
|
||||
|
||||
return logical_rect.height + constants.corner_radius + constants.tail_bottom_padding;
|
||||
}
|
||||
|
||||
public override float get_width() {
|
||||
Pango.Rectangle ink_rect, logical_rect;
|
||||
layout.get_pixel_extents(out ink_rect, out logical_rect);
|
||||
|
||||
return logical_rect.width + text_x_offset + text_x_padding;
|
||||
}
|
||||
|
||||
public override void draw_content(Snapshot snapshot) {
|
||||
snapshot.save();
|
||||
|
||||
Pango.Rectangle ink_rect, logical_rect;
|
||||
layout.get_pixel_extents(out ink_rect, out logical_rect);
|
||||
snapshot.translate(Graphene.Point() {
|
||||
x = text_x_offset,
|
||||
y = ((get_height() - constants.tail_bottom_padding) - logical_rect.height) / 2
|
||||
});
|
||||
|
||||
snapshot.append_layout(layout, Gdk.RGBA() {
|
||||
red = 1.0f,
|
||||
green = 1.0f,
|
||||
blue = 1.0f,
|
||||
alpha = 1.0f
|
||||
});
|
||||
|
||||
snapshot.restore();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user