Implements attachments display in transcript
This commit is contained in:
@@ -7,8 +7,6 @@ private class ImageBubbleLayout : BubbleLayout
|
||||
|
||||
private Graphene.Size image_size;
|
||||
private Gdk.Texture? cached_texture = null;
|
||||
private const float max_image_width = 300.0f;
|
||||
private const float max_image_height = 400.0f;
|
||||
|
||||
public ImageBubbleLayout(string image_path, bool from_me, Widget parent, float max_width, Graphene.Size? image_size = null) {
|
||||
base(parent, max_width);
|
||||
@@ -29,18 +27,13 @@ private class ImageBubbleLayout : BubbleLayout
|
||||
|
||||
// Try to load the image to get its dimensions
|
||||
try {
|
||||
warning("No image size provided, loading image to get dimensions");
|
||||
|
||||
var texture = Gdk.Texture.from_filename(image_path);
|
||||
var original_width = (float)texture.get_width();
|
||||
var original_height = (float)texture.get_height();
|
||||
|
||||
// Calculate scaled dimensions while maintaining aspect ratio
|
||||
var scale_factor = float.min(
|
||||
max_image_width / original_width,
|
||||
max_image_height / original_height
|
||||
);
|
||||
scale_factor = float.min(scale_factor, 1.0f); // Don't scale up
|
||||
|
||||
this.image_size = Graphene.Size() { width = original_width * scale_factor, height = original_height * scale_factor };
|
||||
this.image_size = Graphene.Size() { width = original_width, height = original_height };
|
||||
} catch (Error e) {
|
||||
// Fallback dimensions if image can't be loaded
|
||||
warning("Failed to load image %s: %s", image_path, e.message);
|
||||
@@ -65,12 +58,8 @@ private class ImageBubbleLayout : BubbleLayout
|
||||
}
|
||||
|
||||
public override float get_height() {
|
||||
float aspect_ratio = image_size.width / image_size.height;
|
||||
if (image_size.width > max_width) {
|
||||
return max_width / aspect_ratio;
|
||||
}
|
||||
|
||||
return image_size.height;
|
||||
var scale_factor = float.min(max_width / image_size.width, 1.0f);
|
||||
return image_size.height * scale_factor;
|
||||
}
|
||||
|
||||
public override float get_width() {
|
||||
|
||||
Reference in New Issue
Block a user