Try to scale avatars for HiDPI screens (#35)

This commit is contained in:
bleakgrey 2018-06-02 12:27:19 +03:00
parent ef878d7330
commit a5518a1c4a
6 changed files with 33 additions and 16 deletions

View File

@ -128,15 +128,15 @@ public class Tootle.ImageCache : GLib.Object {
}
}
public void load_avatar (string uri, Granite.Widgets.Avatar avatar, int size = 32) {
get_image.begin(uri, size, (pixbuf) => avatar.pixbuf = pixbuf);
public void load_avatar (string uri, Granite.Widgets.Avatar avatar, int size) {
get_image.begin(uri, size, (pixbuf) => avatar.pixbuf = pixbuf.scale_simple (size, size, Gdk.InterpType.BILINEAR));
}
public void load_image (string uri, Gtk.Image image) {
load_scaled_image(uri, image, -1);
}
public void load_scaled_image (string uri, Gtk.Image image, int size = 64) {
public void load_scaled_image (string uri, Gtk.Image image, int size) {
get_image.begin(uri, size, image.set_from_pixbuf);
}

View File

@ -105,7 +105,7 @@ public class Tootle.NetManager : GLib.Object {
return parser.get_root ().get_array ();
}
public void load_avatar (string url, Granite.Widgets.Avatar avatar, int size = 32){
public void load_avatar (string url, Granite.Widgets.Avatar avatar, int size){
if (settings.cache) {
image_cache.load_avatar (url, avatar, size);
return;
@ -116,7 +116,7 @@ public class Tootle.NetManager : GLib.Object {
var data = msg.response_body.data;
var stream = new MemoryInputStream.from_data (data);
var pixbuf = new Gdk.Pixbuf.from_stream_at_scale (stream, size, size, true);
avatar.pixbuf = pixbuf;
avatar.pixbuf = pixbuf.scale_simple (size, size, Gdk.InterpType.BILINEAR);
});
Tootle.network.queue (msg);
}
@ -137,7 +137,7 @@ public class Tootle.NetManager : GLib.Object {
Tootle.network.queue (msg);
}
public void load_scaled_image (string url, Gtk.Image image, int size = 64) {
public void load_scaled_image (string url, Gtk.Image image, int size) {
if (settings.cache) {
image_cache.load_scaled_image (url, image, size);
return;

View File

@ -3,6 +3,7 @@ using Granite;
public class Tootle.AccountView : TimelineView {
const int AVATAR_SIZE = 128;
Account account;
Gtk.Grid header;
@ -43,7 +44,7 @@ public class Tootle.AccountView : TimelineView {
relationship.margin = 12;
header.attach (relationship, 0, 0, 1, 1);
avatar = new Granite.Widgets.Avatar.with_default_icon (128);
avatar = new Granite.Widgets.Avatar.with_default_icon (AVATAR_SIZE);
avatar.hexpand = true;
avatar.margin_bottom = 6;
header_info.pack_start(avatar, false, false, 0);
@ -137,6 +138,8 @@ public class Tootle.AccountView : TimelineView {
request ();
}
public void rebind (){
display_name.label = "<b>%s</b>".printf (Utils.escape_entities(account.display_name));
username.label = "@" + account.acct;

View File

@ -2,6 +2,7 @@ using Gtk;
public class Tootle.AccountsButton : Gtk.MenuButton{
const int AVATAR_SIZE = 24;
Granite.Widgets.Avatar avatar;
Gtk.Grid grid;
Gtk.Popover menu;
@ -50,7 +51,7 @@ public class Tootle.AccountsButton : Gtk.MenuButton{
}
construct{
avatar = new Granite.Widgets.Avatar.with_default_icon (24);
avatar = new Granite.Widgets.Avatar.with_default_icon (AVATAR_SIZE);
avatar.button_press_event.connect(event => {
return false;
});
@ -133,9 +134,9 @@ public class Tootle.AccountsButton : Gtk.MenuButton{
private void account_switched (Account? account) {
if (account == null)
avatar.show_default (24);
avatar.show_default (AVATAR_SIZE);
else
network.load_avatar (account.avatar, avatar, 24);
network.load_avatar (account.avatar, avatar, get_avatar_size ());
}
private void update_selection () {
@ -145,6 +146,10 @@ public class Tootle.AccountsButton : Gtk.MenuButton{
list.select_row (row);
}
public int get_avatar_size () {
return AVATAR_SIZE * get_style_context ().get_scale ();
}
public AccountsButton() {
account_switched (accounts.current);
}

View File

@ -8,13 +8,14 @@ public class Tootle.AttachmentWidget : Gtk.EventBox {
Attachment? attachment;
private bool editable = false;
private const int SMALL_SIZE = 64;
public Gtk.Label label;
Gtk.Grid grid;
Gtk.Image? image;
construct {
set_size_request (64, 64);
set_size_request (SMALL_SIZE, SMALL_SIZE);
grid = new Gtk.Grid ();
get_style_context ().add_class ("attachment");
@ -38,6 +39,10 @@ public class Tootle.AttachmentWidget : Gtk.EventBox {
attachment = att;
rebind ();
}
public int get_small_size () {
return SMALL_SIZE * get_style_context ().get_scale ();
}
public void rebind () {
var type = attachment.type;
@ -49,7 +54,7 @@ public class Tootle.AttachmentWidget : Gtk.EventBox {
image.valign = Gtk.Align.CENTER;
image.show ();
if (editable)
Tootle.network.load_scaled_image (attachment.preview_url, image);
Tootle.network.load_scaled_image (attachment.preview_url, image, get_small_size ());
else
Tootle.network.load_image (attachment.preview_url, image);
grid.attach (image, 0, 0);

View File

@ -6,11 +6,11 @@ public class Tootle.StatusWidget : Gtk.EventBox {
public Status status;
public bool is_notification = false;
public const int AVATAR_SIZE = 32;
public Gtk.Separator? separator;
public Gtk.Grid grid;
public Granite.Widgets.Avatar avatar;
private const int avatar_size = 32;
public Gtk.Label title_user;
public Gtk.Label title_date;
public Gtk.Label title_acct;
@ -30,7 +30,7 @@ public class Tootle.StatusWidget : Gtk.EventBox {
construct {
grid = new Gtk.Grid ();
avatar = new Granite.Widgets.Avatar.with_default_icon (32);
avatar = new Granite.Widgets.Avatar.with_default_icon (AVATAR_SIZE);
avatar.valign = Gtk.Align.START;
avatar.margin_top = 6;
avatar.margin_start = 6;
@ -175,7 +175,7 @@ public class Tootle.StatusWidget : Gtk.EventBox {
attachments.destroy ();
destroy.connect (() => {
avatar.show_default (avatar_size);
avatar.show_default (AVATAR_SIZE);
if(separator != null)
separator.destroy ();
});
@ -193,6 +193,10 @@ public class Tootle.StatusWidget : Gtk.EventBox {
grid.margin_bottom = 6;
}
public int get_avatar_size () {
return AVATAR_SIZE * get_style_context ().get_scale ();
}
public void rebind () {
var formal = status.get_formal ();
@ -220,7 +224,7 @@ public class Tootle.StatusWidget : Gtk.EventBox {
reblog.tooltip_text = _("This post can't be boosted");
}
Tootle.network.load_avatar (formal.account.avatar, avatar, avatar_size);
Tootle.network.load_avatar (formal.account.avatar, avatar, get_avatar_size ());
}
public bool is_spoiler () {