diff --git a/src/components/post_page.rs b/src/components/post_page.rs index 5d8cb71..f04caf4 100644 --- a/src/components/post_page.rs +++ b/src/components/post_page.rs @@ -27,6 +27,7 @@ pub struct PostPage { #[allow(dead_code)] create_comment_dialog: Controller, voting_row: Controller, + thumbnail_height: i32, } #[derive(Debug)] @@ -65,7 +66,8 @@ impl SimpleComponent for PostPage { #[local_ref] image -> gtk::Box { - set_height_request: 400, + #[watch] + set_height_request: model.thumbnail_height, set_margin_bottom: 20, set_margin_top: 20, #[watch] @@ -218,6 +220,7 @@ impl SimpleComponent for PostPage { let voting_row = VotingRowModel::builder() .launch(VotingStats::default()) .detach(); + let model = PostPage { info: init, image, @@ -226,6 +229,7 @@ impl SimpleComponent for PostPage { community_avatar, create_comment_dialog: dialog, voting_row, + thumbnail_height: 400, }; let image = model.image.widget(); @@ -241,6 +245,13 @@ impl SimpleComponent for PostPage { fn update(&mut self, message: Self::Input, sender: ComponentSender) { match message { PostPageInput::UpdatePost(post) => { + match relm4::main_application().active_window() { + Some(window) => { + self.thumbnail_height = window.allocated_width() / 2; + } + None => unreachable!(), + } + self.info = post.clone(); self.image diff --git a/src/components/post_row.rs b/src/components/post_row.rs index a431384..1ca360f 100644 --- a/src/components/post_row.rs +++ b/src/components/post_row.rs @@ -15,6 +15,7 @@ pub struct PostRow { community_image: Controller, thumbnail: Controller, voting_row: Controller, + image_size: i32, } #[derive(Debug)] @@ -49,7 +50,7 @@ impl FactoryComponent for PostRow { #[local_ref] thumbnail -> gtk::Box { set_visible: self.post.post.thumbnail_url.is_some(), - set_size_request: (180, 180), + set_size_request: (self.image_size, self.image_size), set_margin_start: 10, set_margin_end: 10, set_hexpand: false, @@ -168,6 +169,7 @@ impl FactoryComponent for PostRow { community_image, voting_row, thumbnail, + image_size: 1500, } } @@ -178,6 +180,13 @@ impl FactoryComponent for PostRow { _returned_widget: &::ReturnedWidget, sender: FactorySender, ) -> Self::Widgets { + match root.widget_ref().toplevel_window() { + Some(window) => { + self.image_size = window.allocated_width() / 8; + } + None => unreachable!(), + } + println!("size {}", self.image_size); let thumbnail = self.thumbnail.widget(); let author_image = self.author_image.widget(); let community_image = self.community_image.widget();