Show preview of post thumbnail(closes #9)

This commit is contained in:
Bnyro 2023-07-16 19:53:01 +02:00
parent 8298bac336
commit 3ce4fc0c3f
1 changed files with 91 additions and 65 deletions

View File

@ -13,6 +13,7 @@ pub struct PostRow {
post: PostView,
author_image: Controller<WebImage>,
community_image: Controller<WebImage>,
thumbnail: Controller<WebImage>,
voting_row: Controller<VotingRowModel>,
}
@ -38,16 +39,34 @@ impl FactoryComponent for PostRow {
view! {
root = gtk::Box {
set_orientation: gtk::Orientation::Vertical,
set_spacing: 10,
set_margin_end: 10,
set_margin_start: 10,
gtk::Box {
set_orientation: gtk::Orientation::Horizontal,
set_spacing: 10,
#[local_ref]
thumbnail -> gtk::Box {
set_visible: self.post.post.thumbnail_url.is_some(),
set_size_request: (180, 180),
set_margin_start: 10,
set_margin_end: 10,
set_hexpand: false,
set_valign: gtk::Align::Center,
},
gtk::Box {
set_orientation: gtk::Orientation::Vertical,
set_valign: gtk::Align::Center,
set_spacing: 10,
set_hexpand: true,
gtk::Box {
set_orientation: gtk::Orientation::Horizontal,
set_margin_top: 10,
set_spacing: 10,
set_vexpand: false,
set_hexpand: true,
#[local_ref]
community_image -> gtk::Box {
@ -116,6 +135,8 @@ impl FactoryComponent for PostRow {
set_visible: self.post.creator.id.0 == settings::get_current_account().id,
}
},
}
},
gtk::Separator {
set_margin_top: 10,
@ -128,6 +149,9 @@ impl FactoryComponent for PostRow {
}
fn init_model(value: Self::Init, _index: &DynamicIndex, _sender: FactorySender<Self>) -> Self {
let thumbnail = WebImage::builder()
.launch(get_web_image_url(value.post.thumbnail_url.clone()))
.detach();
let author_image = WebImage::builder()
.launch(get_web_image_url(value.creator.avatar.clone()))
.detach();
@ -143,6 +167,7 @@ impl FactoryComponent for PostRow {
author_image,
community_image,
voting_row,
thumbnail,
}
}
@ -153,6 +178,7 @@ impl FactoryComponent for PostRow {
_returned_widget: &<Self::ParentWidget as relm4::factory::FactoryView>::ReturnedWidget,
sender: FactorySender<Self>,
) -> Self::Widgets {
let thumbnail = self.thumbnail.widget();
let author_image = self.author_image.widget();
let community_image = self.community_image.widget();
let voting_row = self.voting_row.widget();