Switch from Entry to TextView for multiline, paste support for attachments
This commit is contained in:
@@ -1,5 +1,27 @@
|
||||
using Gee;
|
||||
using Gtk;
|
||||
|
||||
private class SizeCache
|
||||
{
|
||||
private static SizeCache instance = null;
|
||||
private HashMap<string, Graphene.Size?> size_cache = new HashMap<string, Graphene.Size?>();
|
||||
|
||||
public static SizeCache get_instance() {
|
||||
if (instance == null) {
|
||||
instance = new SizeCache();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public Graphene.Size? get_size(string image_path) {
|
||||
return size_cache.get(image_path);
|
||||
}
|
||||
|
||||
public void set_size(string image_path, Graphene.Size size) {
|
||||
size_cache.set(image_path, size);
|
||||
}
|
||||
}
|
||||
|
||||
private class ImageBubbleLayout : BubbleLayout
|
||||
{
|
||||
public string image_path;
|
||||
@@ -25,6 +47,12 @@ private class ImageBubbleLayout : BubbleLayout
|
||||
return;
|
||||
}
|
||||
|
||||
var cached_size = SizeCache.get_instance().get_size(image_path);
|
||||
if (cached_size != null) {
|
||||
this.image_size = cached_size;
|
||||
return;
|
||||
}
|
||||
|
||||
// Try to load the image to get its dimensions
|
||||
try {
|
||||
warning("No image size provided, loading image to get dimensions");
|
||||
@@ -34,6 +62,7 @@ private class ImageBubbleLayout : BubbleLayout
|
||||
var original_height = (float)texture.get_height();
|
||||
|
||||
this.image_size = Graphene.Size() { width = original_width, height = original_height };
|
||||
SizeCache.get_instance().set_size(image_path, this.image_size);
|
||||
} catch (Error e) {
|
||||
// Fallback dimensions if image can't be loaded
|
||||
warning("Failed to load image %s: %s", image_path, e.message);
|
||||
@@ -57,13 +86,26 @@ private class ImageBubbleLayout : BubbleLayout
|
||||
}
|
||||
}
|
||||
|
||||
private float intrinsic_height {
|
||||
get {
|
||||
var scale_factor = float.min(max_width / image_size.width, 1.0f);
|
||||
return image_size.height * scale_factor;
|
||||
}
|
||||
}
|
||||
|
||||
private float intrinsic_width {
|
||||
get {
|
||||
var scale_factor = float.min(max_width / image_size.width, 1.0f);
|
||||
return image_size.width * scale_factor;
|
||||
}
|
||||
}
|
||||
|
||||
public override float get_height() {
|
||||
var scale_factor = float.min(max_width / image_size.width, 1.0f);
|
||||
return image_size.height * scale_factor;
|
||||
return float.max(intrinsic_height, 100.0f);
|
||||
}
|
||||
|
||||
public override float get_width() {
|
||||
return float.min(image_size.width, max_width);
|
||||
return float.max(intrinsic_width, 200.0f);
|
||||
}
|
||||
|
||||
public override void draw_content(Snapshot snapshot) {
|
||||
@@ -73,9 +115,15 @@ private class ImageBubbleLayout : BubbleLayout
|
||||
|
||||
var image_rect = Graphene.Rect () {
|
||||
origin = Graphene.Point() { x = 0, y = 0 },
|
||||
size = Graphene.Size() { width = get_width(), height = get_height() }
|
||||
size = Graphene.Size() { width = intrinsic_width, height = intrinsic_height }
|
||||
};
|
||||
|
||||
// Center image in the bubble (if it's smaller than the bubble)
|
||||
snapshot.translate(Graphene.Point() {
|
||||
x = (get_width() - intrinsic_width) / 2,
|
||||
y = (get_height() - intrinsic_height) / 2
|
||||
});
|
||||
|
||||
if (cached_texture != null) {
|
||||
snapshot.append_texture(cached_texture, image_rect);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user