Circle image for room avatar

This commit is contained in:
Daniel García Moreno 2017-12-22 21:25:36 +01:00
parent 3c23922708
commit 2fb1cdc108
3 changed files with 22 additions and 11 deletions

View file

@ -36,3 +36,7 @@
border-radius: 20px;
}
**/
.room-avatar-container .avatar {
margin: 3px;
}

View file

@ -1073,12 +1073,15 @@ Join a room to start to chat</property>
<property name="can_focus">False</property>
<property name="spacing">6</property>
<child>
<object class="GtkImage" id="room_image">
<object class="GtkBox" id="room_image">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">6</property>
<property name="pixel_size">40</property>
<property name="icon_name">camera-photo-symbolic</property>
<property name="icon_size">5</property>
<child>
<placeholder/>
</child>
<style>
<class name="room-avatar-container"/>
</style>
</object>
<packing>
<property name="expand">False</property>

View file

@ -674,22 +674,26 @@ impl AppOp {
pub fn set_current_room_avatar(&self, avatar: Option<String>) {
let image = self.gtk_builder
.get_object::<gtk::Image>("room_image")
.get_object::<gtk::Box>("room_image")
.expect("Can't find room_image in ui file.");
for ch in image.get_children() {
image.remove(&ch);
}
let config = self.gtk_builder
.get_object::<gtk::Image>("room_avatar_image")
.expect("Can't find room_avatar_image in ui file.");
if avatar.is_some() && !avatar.clone().unwrap().is_empty() {
if let Ok(pixbuf) = Pixbuf::new_from_file_at_size(&avatar.clone().unwrap(), 40, 40) {
image.set_from_pixbuf(&pixbuf);
}
image.add(&widgets::Avatar::circle_avatar(avatar.clone().unwrap(), Some(40)));
if let Ok(pixbuf) = Pixbuf::new_from_file_at_size(&avatar.clone().unwrap(), 100, 100) {
config.set_from_pixbuf(&pixbuf);
}
} else {
image.set_from_icon_name("image-missing", 5);
config.set_from_icon_name("image-missing", 5);
let w = widgets::Avatar::avatar_new(Some(40));
w.default(String::from("camera-photo-symbolic"), Some(40));
image.add(&w);
config.set_from_icon_name("camera-photo-symbolic", 5);
}
}